Jpp test-rotations-old
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<value_type>& parameter = i->second.getValue<const JOscParameter<value_type> >();
194
195 if (parameter.isDefined()) {
196 this->set(i->first, parameter.getValue());
197 }
198 }
199 }
200
201
202 /**
203 * Check whether these oscillation parameters are equal to given oscillation parameters.
204 *
205 * \param parameters oscillation parameters
206 * \return true if equal; else false
207 */
208 bool equals(const JOscParametersInterface<value_type>& parameters) const
209 {
210 using namespace std;
211 using namespace JPP;
212
213 bool equal = true;
214
215 JProperties properties = this->getProperties();
216
217 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && equal; ++i) {
218
219 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
220
221 equal = (parameter == parameters.get(i->first));
222 }
223
224 return equal;
225 }
226
227
228 /**
229 * Equal operator.
230 *
231 * \param parameters set of oscillation parameters
232 * \return true if this set of oscillation parameters is equal to the given set; else false
233 */
235 {
236 return this->equals(parameters);
237 }
238
239
240 /**
241 * Not equal operator.
242 *
243 * \param parameters set of oscillation parameters
244 * \return true if this set of oscillation parameters is equal to the given set; else false
245 */
247 {
248 return !this->equals(parameters);
249 }
250
251
252 /**
253 * Get equation parameters.
254 *
255 * \return equation parameters
256 */
258 {
259 static JEquationParameters equation("=", "\n\r;,", "./", "#");
260
261 return equation;
262 }
263
264
265 /**
266 * Set equation parameters.
267 *
268 * \param equation equation parameters
269 */
270 static inline void setEquationParameters(const JEquationParameters& equation)
271 {
272 getEquationParameters() = equation;
273 }
274
275
276 /**
277 * Binary stream input of oscillation parameters.
278 *
279 * \param in input stream
280 * \return input stream
281 */
282 JReader& read(JReader& in) override
283 {
284 JProperties properties = this->getProperties();
285
286 for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
287
288 bool is_defined;
289 value_type value;
290
291 if ((in >> is_defined >> value) && is_defined) {
292
293 JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
294
295 parameter.setValue(value);
296 }
297 }
298
299 return in;
300 }
301
302
303 /**
304 * Binary stream output of oscillation parameters.
305 *
306 * \param out output stream
307 * \return output stream
308 */
309 JWriter& write(JWriter& out) const override
310 {
311 const JProperties properties = this->getProperties();
312
313 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
314
315 const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
316
317 out << parameter.isDefined() << parameter.getValue();
318 }
319
320 return out;
321 }
322
323
324 /**
325 * Stream input of oscillation parameters.
326 *
327 * \param in input stream
328 * \param parameters oscillation parameters
329 * \return input stream
330 */
331 friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters)
332 {
333 using namespace std;
334 using namespace JPP;
335
336 JStringStream is(in);
337
338 if (getFileStatus(is.str().c_str())) {
339 is.load();
340 }
341
342 JProperties properties = parameters.getProperties();
343 is >> properties;
344
345 return in;
346 }
347
348
349 /**
350 * Stream output of oscillation parameters.
351 *
352 * \param out output stream
353 * \param parameters oscillation parameters
354 * \return output stream
355 */
356 friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters)
357 {
358 return out << parameters.getProperties();
359 }
360 };
361
362
363 /**
364 * Get size of given oscillation parameters set.
365 *
366 * \param parameters oscillation parameters set
367 * \return size (= number of defined parameters)
368 */
369 template<class T>
370 inline size_t getSize(const JOscParametersInterface<T>& parameters)
371 {
372 size_t n = 0;
373
374 const JProperties properties = parameters.getProperties();
375
376 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
377 const JOscParameter<T>& parameter = i->second.getValue<const JOscParameter<T> >();
378
379 n += (size_t) parameter.isDefined();
380 }
381
382 return n;
383 }
384
385
386 /**
387 * Get size of given oscillation parameters grid.
388 *
389 * \param parameters oscillation parameters grid
390 * \return size (= number of defined parameters)
391 */
392 inline size_t getSize(const JOscParametersInterface<JGrid<double> >& parameters)
393 {
394 size_t n = 1;
395
396 const JProperties properties = parameters.getProperties();
397
398 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
399 const JOscParameter<JGrid<double> >& parameter = i->second.getValue<const JOscParameter<JGrid<double> > >();
400
401 if (parameter.isDefined()) {
402 n *= getSize(parameter);
403 }
404 }
405
406 return n;
407 }
408}
409
410#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.
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