Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JTable1D.hh
Go to the documentation of this file.
1#ifndef __JTOOLS__JTABLE1D__
2#define __JTOOLS__JTABLE1D__
3
4#include "JMath/JMath.hh"
5#include "JMath/JZero.hh"
7
8
9/**
10 * \author mdejong
11 */
12
13namespace JTOOLS {}
14namespace JPP { using namespace JTOOLS; }
15
16namespace JTOOLS {
17
18 using JMATH::JMath;
19 using JIO::JReader;
20 using JIO::JWriter;
21
22
23 /**
24 * 1D table with arithmetic capabilities.
25 */
26 template<unsigned int NX, class JData_t = double>
27 struct JTable1D :
28 public JMath< JTable1D<NX, JData_t> >
29 {
30 typedef JData_t data_type;
31
32 /**
33 * Default constructor.
34 */
36 {
37 for (int i = 0; i != NX; ++i) {
38 data[i] = JMATH::zero;
39 }
40 }
41
42
43 /**
44 * Get number of entries.
45 *
46 * \return number of entries
47 */
48 static int getNX()
49 {
50 return NX;
51 }
52
53
54 /**
55 * Get entry data.
56 *
57 * \param entry entry number
58 * \return entry data
59 */
60 const data_type& operator[](int entry) const
61 {
62 return data[entry];
63 };
64
65
66 /**
67 * Get entry data.
68 *
69 * \param entry entry number
70 * \return entry data
71 */
73 {
74 return data[entry];
75 };
76
77
78 /**
79 * Negate table.
80 *
81 * \return this table
82 */
84 {
85 for (int i = 0; i != NX; ++i) {
86 data[i] = -data[i];
87 }
88
89 return *this;
90 }
91
92
93 /**
94 * Add table.
95 *
96 * \param table table
97 * \return this table
98 */
99 JTable1D& add(const JTable1D& table)
100 {
101 for (int i = 0; i != NX; ++i) {
102 data[i] += table.data[i];
103 }
104
105 return *this;
106 }
107
108
109 /**
110 * Subtract table.
111 *
112 * \param table table
113 * \return this table
114 */
115 JTable1D& sub(const JTable1D& table)
116 {
117 for (int i = 0; i != NX; ++i) {
118 data[i] -= table.data[i];
119 }
120
121 return *this;
122 }
123
124 /**
125 * Scale table.
126 *
127 * \param factor multiplication factor
128 * \return this table
129 */
130 JTable1D& mul(const double factor)
131 {
132 for (int i = 0; i != NX; ++i) {
133 data[i] *= factor;
134 }
135
136 return *this;
137 }
138
139
140 /**
141 * Scale table.
142 *
143 * \param factor division factor
144 * \return this table
145 */
146 JTable1D& div(const double factor)
147 {
148 for (int i = 0; i != NX; ++i) {
149 data[i] /= factor;
150 }
151
152 return *this;
153 }
154
155
156 /**
157 * Read table from input.
158 *
159 * \param in reader
160 * \param table table
161 * \return reader
162 */
163 friend inline JReader& operator>>(JReader& in, JTable1D& table)
164 {
165 for (int i = 0; i != NX; ++i) {
166 in >> table.data[i];
167 }
168
169 return in;
170 }
171
172
173 /**
174 * Write table to output.
175 *
176 * \param out writer
177 * \param table table
178 * \return writer
179 */
180 friend inline JWriter& operator<<(JWriter& out, const JTable1D& table)
181 {
182 for (int i = 0; i != NX; ++i) {
183 out << table.data[i];
184 }
185
186 return out;
187 }
188
189
190 protected:
192 };
193}
194
195#endif
Base class for data structures with artithmetic capabilities.
Definition of zero value for any class.
Interface for binary input.
Interface for binary output.
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Auxiliary base class for aritmetic operations of derived class types.
Definition JMath.hh:347
1D table with arithmetic capabilities.
Definition JTable1D.hh:29
data_type data[NX]
Definition JTable1D.hh:191
JTable1D & div(const double factor)
Scale table.
Definition JTable1D.hh:146
data_type & operator[](int entry)
Get entry data.
Definition JTable1D.hh:72
JTable1D & add(const JTable1D &table)
Add table.
Definition JTable1D.hh:99
static int getNX()
Get number of entries.
Definition JTable1D.hh:48
const data_type & operator[](int entry) const
Get entry data.
Definition JTable1D.hh:60
friend JReader & operator>>(JReader &in, JTable1D &table)
Read table from input.
Definition JTable1D.hh:163
JTable1D & sub(const JTable1D &table)
Subtract table.
Definition JTable1D.hh:115
friend JWriter & operator<<(JWriter &out, const JTable1D &table)
Write table to output.
Definition JTable1D.hh:180
JTable1D()
Default constructor.
Definition JTable1D.hh:35
JData_t data_type
Definition JTable1D.hh:30
JTable1D & negate()
Negate table.
Definition JTable1D.hh:83
JTable1D & mul(const double factor)
Scale table.
Definition JTable1D.hh:130