Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JOscParametersInterface.hh
Go to the documentation of this file.
1#ifndef __JOSCPROB__JOSCPARAMETERSINTERFACE__
2#define __JOSCPROB__JOSCPARAMETERSINTERFACE__
3
4#include <iostream>
5#include <iomanip>
6#include <string>
7
8#include "Jeep/JComment.hh"
9#include "Jeep/JProperties.hh"
10
11#include "JIO/JSerialisable.hh"
12
13#include "JLang/JClonable.hh"
14#include "JLang/JParameter.hh"
17
18#include "JTools/JGrid.hh"
19
21
22
23/**
24 * \author bjung, mdejong
25 */
26
27namespace JOSCPROB {}
28namespace JPP { using namespace JOSCPROB; }
29
30namespace JOSCPROB {
31
32 using JIO::JReader;
33 using JIO::JWriter;
35
36 using JLANG::JClonable;
38
39
40 /**
41 * Interface class for sets of oscillation parameters.
42 */
43 template<class T>
45 public JClonable<JOscParametersInterface<T> >,
46 public JSerialisable
47 {
48 public:
49
52
54
57
58
59 /**
60 * Default constructor.
61 */
64
65
66 /**
67 * Virtual destructor.
68 */
71
72
73 /**
74 * Get properties of this class.
75 *
76 * \param equation equation parameters
77 * \return properties of this class
78 */
80
81
82 /**
83 * Get properties of this class.
84 *
85 * \param equation equation parameters
86 * \return properties of this class
87 */
89
90
91 /**
92 * Get oscillation parameters.
93 *
94 * \return reference to oscillation parameters
95 */
97 {
98 return static_cast<JOscParametersInterface_t&>(*this);
99 }
100
101
102 /**
103 * Get oscillation parameter.
104 *
105 * \param name parameter name
106 * \return parameter
107 */
108 const JOscParameter_t& get(const std::string& name) const
109 {
110 using namespace std;
111 using namespace JPP;
112
113 JProperties properties = this->getProperties();
114
115 const JOscParameter_t& parameter = properties.getValue<const JOscParameter_t>(name);
116
117 return parameter;
118 }
119
120
121 /**
122 * Get oscillation parameter.
123 *
124 * \param name parameter name
125 * \return parameter
126 */
127 JOscParameter_t& get(const std::string& name)
128 {
129 using namespace std;
130 using namespace JPP;
131
132 JProperties properties = this->getProperties();
133
134 JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
135
136 return parameter;
137 }
138
139
140 /**
141 * Set value for a given oscillation parameter.
142 *
143 * \param name parameter name
144 * \param value parameter value
145 */
146 void set(const std::string& name,
147 const value_type& value)
148 {
149 using namespace std;
150 using namespace JPP;
151
152 JProperties properties = this->getProperties();
153
154 JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
155
156 parameter.setValue(value);
157 }
158
159
160 /**
161 * Set value for given list of oscillation parameters.
162 *
163 * \param name parameter name
164 * \param value parameter value
165 * \param args remaining pairs of parameter names and values
166 */
167 template<class ...Args>
168 void set(const std::string& name,
169 const value_type& value,
170 const Args& ...args)
171 {
172 set(name, value);
173 set(args...);
174 }
175
176
177 /**
178 * Set oscillation parameters.
179 *
180 * \param parameters oscillation parameters
181 */
183 {
184 using namespace std;
185 using namespace JPP;
186
187 JProperties properties = parameters.getProperties();
188
189 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
190
191 const JOscParameter<value_type>& parameter = i->second.getValue<const JOscParameter<value_type> >();
192
193 if (parameter.isDefined()) {
194 this->set(i->first, parameter.getValue());
195 }
196 }
197 }
198
199
200 /**
201 * Check whether these oscillation parameters are equal to given oscillation parameters.
202 *
203 * \param parameters oscillation parameters
204 * \return true if equal; else false
205 */
206 bool equals(const JOscParametersInterface<value_type>& parameters) const
207 {
208 using namespace std;
209 using namespace JPP;
210
211 bool equal = true;
212
213 JProperties properties = this->getProperties();
214
215 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && equal; ++i) {
216
217 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
218
219 equal = (parameter == parameters.get(i->first));
220 }
221
222 return equal;
223 }
224
225
226 /**
227 * Equal operator.
228 *
229 * \param parameters set of oscillation parameters
230 * \return true if this set of oscillation parameters is equal to the given set; else false
231 */
233 {
234 return this->equals(parameters);
235 }
236
237
238 /**
239 * Not equal operator.
240 *
241 * \param parameters set of oscillation parameters
242 * \return true if this set of oscillation parameters is equal to the given set; else false
243 */
245 {
246 return !this->equals(parameters);
247 }
248
249
250 /**
251 * Get equation parameters.
252 *
253 * \return equation parameters
254 */
256 {
257 static JEquationParameters equation("=", "\n\r;,", "./", "#");
258
259 return equation;
260 }
261
262
263 /**
264 * Set equation parameters.
265 *
266 * \param equation equation parameters
267 */
268 static inline void setEquationParameters(const JEquationParameters& equation)
269 {
270 getEquationParameters() = equation;
271 }
272
273
274 /**
275 * Binary stream input of oscillation parameters.
276 *
277 * \param in input stream
278 * \return input stream
279 */
280 JReader& read(JReader& in) override
281 {
282 JProperties properties = this->getProperties();
283
284 for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
285
286 bool is_defined;
287 value_type value;
288
289 if ((in >> is_defined >> value) && is_defined) {
290
291 JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
292
293 parameter.setValue(value);
294 }
295 }
296
297 return in;
298 }
299
300
301 /**
302 * Binary stream output of oscillation parameters.
303 *
304 * \param out output stream
305 * \return output stream
306 */
307 JWriter& write(JWriter& out) const override
308 {
309 const JProperties properties = this->getProperties();
310
311 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
312
313 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
314
315 out << parameter.isDefined() << parameter.getValue();
316 }
317
318 return out;
319 }
320
321
322 /**
323 * Stream input of oscillation parameters.
324 *
325 * \param in input stream
326 * \param parameters oscillation parameters
327 * \return input stream
328 */
329 friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters)
330 {
331 using namespace std;
332 using namespace JPP;
333
334 JStringStream is(in);
335
336 JProperties properties = parameters.getProperties();
337 is >> properties;
338
339 return in;
340 }
341
342
343 /**
344 * Stream output of oscillation parameters.
345 *
346 * \param out output stream
347 * \param parameters oscillation parameters
348 * \return output stream
349 */
350 friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters)
351 {
352 return out << parameters.getProperties();
353 }
354 };
355
356
357 /**
358 * Get size of given oscillation parameters set.
359 *
360 * \param parameters oscillation parameters set
361 * \return size (= number of defined parameters)
362 */
363 template<class T>
364 inline size_t getSize(const JOscParametersInterface<T>& parameters)
365 {
366 size_t n = 0;
367
368 const JProperties properties = parameters.getProperties();
369
370 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
371 const JOscParameter<T>& parameter = i->second.getValue<const JOscParameter<T> >();
372
373 n += (size_t) parameter.isDefined();
374 }
375
376 return n;
377 }
378
379
380 /**
381 * Get size of given oscillation parameters grid.
382 *
383 * \param parameters oscillation parameters grid
384 * \return size (= number of defined parameters)
385 */
386 inline size_t getSize(const JOscParametersInterface<JGrid<double> >& parameters)
387 {
388 size_t n = 1;
389
390 const JProperties properties = parameters.getProperties();
391
392 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
393 const JOscParameter<JGrid<double> >& parameter = i->second.getValue<const JOscParameter<JGrid<double> > >();
394
395 if (parameter.isDefined()) {
396 n *= getSize(parameter);
397 }
398 }
399
400 return n;
401 }
402}
403
404#endif
Utility class to parse parameter values.
Utility class to parse parameter values.
const T & getValue(const std::string &key) const
Get value.
Interface for binary input.
Forward declaration of binary output.
Interface for binary output.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Parameter class.
Definition JParameter.hh:36
JClass< T >::argument_type argument_type
Definition JParameter.hh:39
const value_type getValue() const
Get value of parameter.
Definition JParameter.hh:82
const bool isDefined() const
Get status of parameter.
JClass< T >::value_type value_type
Definition JParameter.hh:40
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Interface class for sets of oscillation parameters.
JReader & read(JReader &in) override
Binary stream input of oscillation parameters.
JOscParameter_t::JParameter_t JParameter_t
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
friend std::ostream & operator<<(std::ostream &out, const JOscParametersInterface_t &parameters)
Stream output of oscillation parameters.
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
void set(const std::string &name, const value_type &value, const Args &...args)
Set value for given list of oscillation parameters.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters()) const =0
Get properties of this class.
friend std::istream & operator>>(std::istream &in, JOscParametersInterface_t &parameters)
Stream input of oscillation parameters.
const JOscParameter_t & get(const std::string &name) const
Get oscillation parameter.
JOscParameter_t & get(const std::string &name)
Get oscillation parameter.
bool equals(const JOscParametersInterface< value_type > &parameters) const
Check whether these oscillation parameters are equal to given oscillation parameters.
JOscParametersInterface< T > JOscParametersInterface_t
static JEquationParameters & getEquationParameters()
Get equation parameters.
bool operator!=(const JOscParametersInterface< value_type > &parameters)
Not equal operator.
JOscParametersInterface_t & getParameters()
Get oscillation parameters.
void set(const std::string &name, const value_type &value)
Set value for a given oscillation parameter.
bool operator==(const JOscParametersInterface< value_type > &parameters)
Equal operator.
void set(const JOscParametersInterface< value_type > &parameters)
Set oscillation parameters.
JParameter_t::argument_type argument_type
size_t getSize(const JOscParameter< JGrid< double > > &grid)
Get size of given oscillation parameter grid.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template class for object cloning.
Definition JClonable.hh:59
Abstract base class for oscillation parameter.
void setValue(const value_type &value)
Set parameter.
Simple data structure for an abstract collection of equidistant abscissa values.
Definition JGrid.hh:40