Jpp master_rocky-44-g75b7c4f75
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 "JSystem/JStat.hh"
12
13#include "JIO/JSerialisable.hh"
14
15#include "JLang/JClonable.hh"
16#include "JLang/JParameter.hh"
19
20#include "JTools/JGrid.hh"
21
23
24
25/**
26 * \author bjung, mdejong
27 */
28
29namespace JOSCPROB {}
30namespace JPP { using namespace JOSCPROB; }
31
32namespace JOSCPROB {
33
34 using JIO::JReader;
35 using JIO::JWriter;
37
38 using JLANG::JClonable;
40
41
42 /**
43 * Interface class for sets of oscillation parameters.
44 */
45 template<class T>
47 public JClonable<JOscParametersInterface<T> >,
48 public JSerialisable
49 {
50 public:
51
54
56
59
60
61 /**
62 * Default constructor.
63 */
66
67
68 /**
69 * Virtual destructor.
70 */
73
74
75 /**
76 * Get properties of this class.
77 *
78 * \param equation equation parameters
79 * \return properties of this class
80 */
82
83
84 /**
85 * Get properties of this class.
86 *
87 * \param equation equation parameters
88 * \return properties of this class
89 */
91
92
93 /**
94 * Get oscillation parameters.
95 *
96 * \return reference to oscillation parameters
97 */
99 {
100 return static_cast<JOscParametersInterface_t&>(*this);
101 }
102
103
104 /**
105 * Get oscillation parameter.
106 *
107 * \param name parameter name
108 * \return parameter
109 */
110 const JOscParameter_t& get(const std::string& name) const
111 {
112 using namespace std;
113 using namespace JPP;
114
115 JProperties properties = this->getProperties();
116
117 const JOscParameter_t& parameter = properties.getValue<const JOscParameter_t>(name);
118
119 return parameter;
120 }
121
122
123 /**
124 * Get oscillation parameter.
125 *
126 * \param name parameter name
127 * \return parameter
128 */
129 JOscParameter_t& get(const std::string& name)
130 {
131 using namespace std;
132 using namespace JPP;
133
134 JProperties properties = this->getProperties();
135
136 JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
137
138 return parameter;
139 }
140
141
142 /**
143 * Set value for a given oscillation parameter.
144 *
145 * \param name parameter name
146 * \param value parameter value
147 */
148 void set(const std::string& name,
149 const value_type& value)
150 {
151 using namespace std;
152 using namespace JPP;
153
154 JProperties properties = this->getProperties();
155
156 JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
157
158 parameter.setValue(value);
159 }
160
161
162 /**
163 * Set value for given list of oscillation parameters.
164 *
165 * \param name parameter name
166 * \param value parameter value
167 * \param args remaining pairs of parameter names and values
168 */
169 template<class ...Args>
170 void set(const std::string& name,
171 const value_type& value,
172 const Args& ...args)
173 {
174 set(name, value);
175 set(args...);
176 }
177
178
179 /**
180 * Set oscillation parameters.
181 *
182 * \param parameters oscillation parameters
183 */
185 {
186 using namespace std;
187 using namespace JPP;
188
189 JProperties properties = parameters.getProperties();
190
191 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
192
193 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
194
195 this->set(i->first, parameter.getValue());
196 }
197 }
198
199
200 /**
201 * Check validity of oscillation parameters.
202 *
203 * \return true if all oscillation parameters are valid; else false
204 */
205 bool is_valid() const
206 {
207 bool valid = true;
208
209 const JProperties properties = this->getProperties();
210
211 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && valid; ++i) {
212
213 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
214
215 valid = parameter.is_valid();
216 }
217
218 return valid;
219 }
220
221
222 /**
223 * Check whether these oscillation parameters are equal to given oscillation parameters.
224 *
225 * \param oscillation parameters
226 * \return true if equal; else false
227 */
228 bool equals(const JOscParametersInterface<value_type>& parameters) const
229 {
230 using namespace std;
231 using namespace JPP;
232
233 bool equal = true;
234
235 JProperties properties = this->getProperties();
236
237 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && equal; ++i) {
238
239 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
240
241 equal = (parameter == parameters.get(i->first));
242 }
243
244 return equal;
245 }
246
247
248 /**
249 * Equal operator.
250 *
251 * \param parameters set of oscillation parameters
252 * \return true if this set of oscillation parameters is equal to the given set; else false
253 */
255 {
256 return this->equals(parameters);
257 }
258
259
260 /**
261 * Not equal operator.
262 *
263 * \param parameters set of oscillation parameters
264 * \return true if this set of oscillation parameters is equal to the given set; else false
265 */
267 {
268 return !this->equals(parameters);
269 }
270
271
272 /**
273 * Get equation parameters.
274 *
275 * \return equation parameters
276 */
278 {
279 static JEquationParameters equation("=", "\n\r;,", "./", "#");
280
281 return equation;
282 }
283
284
285 /**
286 * Set equation parameters.
287 *
288 * \param equation equation parameters
289 */
290 static inline void setEquationParameters(const JEquationParameters& equation)
291 {
292 getEquationParameters() = equation;
293 }
294
295
296 /**
297 * Binary stream input of oscillation parameters.
298 *
299 * \param in input stream
300 * \return input stream
301 */
302 JReader& read(JReader& in) override
303 {
304 JProperties properties = this->getProperties();
305
306 for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
307
308 bool is_defined;
309 value_type value;
310
311 if ((in >> is_defined >> value) && is_defined) {
312
313 JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
314
315 parameter.setValue(value);
316 }
317 }
318
319 return in;
320 }
321
322
323 /**
324 * Binary stream output of oscillation parameters.
325 *
326 * \param out output stream
327 * \return output stream
328 */
329 JWriter& write(JWriter& out) const override
330 {
331 const JProperties properties = this->getProperties();
332
333 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
334
335 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
336
337 out << parameter.isDefined() << parameter.getValue();
338 }
339
340 return out;
341 }
342
343
344 /**
345 * Stream input of oscillation parameters.
346 *
347 * \param in input stream
348 * \param parameters oscillation parameters
349 * \return input stream
350 */
351 friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters)
352 {
353 using namespace std;
354 using namespace JPP;
355
356 JStringStream is(in);
357
358 if (getFileStatus(is.str().c_str())) {
359 is.load();
360 }
361
362 JProperties properties = parameters.getProperties();
363 is >> properties;
364
365 return in;
366 }
367
368
369 /**
370 * Stream output of oscillation parameters.
371 *
372 * \param out output stream
373 * \param parameters oscillation parameters
374 * \return output stream
375 */
376 friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters)
377 {
378 return out << parameters.getProperties();
379 }
380 };
381
382
383 /**
384 * Get size of given oscillation parameters set.
385 *
386 * \param parameters oscillation parameters set
387 * \return size (= number of defined parameters)
388 */
389 template<class T>
390 inline size_t getSize(const JOscParametersInterface<T>& parameters)
391 {
392 size_t n = 0;
393
394 const JProperties properties = parameters.getProperties();
395
396 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
397 const JOscParameter<T>& parameter = i->second.getValue<const JOscParameter<T> >();
398
399 n += (size_t) parameter.isDefined();
400 }
401
402 return n;
403 }
404
405
406 /**
407 * Get size of given oscillation parameters grid.
408 *
409 * \param parameters oscillation parameters grid
410 * \return size (= number of defined parameters)
411 */
412 inline size_t getSize(const JOscParametersInterface<JGrid<double> >& parameters)
413 {
414 size_t n = 1;
415
416 const JProperties properties = parameters.getProperties();
417
418 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
419 const JOscParameter<JGrid<double> >& parameter = i->second.getValue<const JOscParameter<JGrid<double> > >();
420
421 if (parameter.isDefined()) {
422 n *= getSize(parameter);
423 }
424 }
425
426 return n;
427 }
428}
429
430#endif
Utility class to parse parameter values.
File status.
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.
void load()
Load data from file with name corresponding to current contents.
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.
bool is_valid() const
Check validity of 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.
virtual bool is_valid() const =0
Check validity of oscillation parameter.
Simple data structure for an abstract collection of equidistant abscissa values.
Definition JGrid.hh:40