Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/JEquals.hh"
16 #include "JLang/JClonable.hh"
17 #include "JLang/JParameter.hh"
18 #include "JLang/JStringStream.hh"
20 
21 #include "JTools/JGrid.hh"
22 
24 
25 
26 /**
27  * \author bjung, mdejong
28  */
29 
30 namespace JOSCPROB {}
31 namespace JPP { using namespace JOSCPROB; }
32 
33 namespace JOSCPROB {
34 
35  using JIO::JReader;
36  using JIO::JWriter;
37  using JIO::JSerialisable;
38 
39  using JLANG::JEquals;
40  using JLANG::JClonable;
42 
43 
44  /**
45  * Interface class for sets of oscillation parameters.
46  */
47  template<class T>
49  public JClonable<JOscParametersInterface<T> >,
50  public JEquals <JOscParametersInterface<T> >,
51  public JSerialisable
52  {
53  public:
54 
57 
59 
62 
63 
64  /**
65  * Default constructor.
66  */
68  {}
69 
70 
71  /**
72  * Virtual destructor.
73  */
75  {}
76 
77 
78  /**
79  * Get properties of this class.
80  *
81  * \param equation equation parameters
82  * \return properties of this class
83  */
85 
86 
87  /**
88  * Get properties of this class.
89  *
90  * \param equation equation parameters
91  * \return properties of this class
92  */
94 
95 
96  /**
97  * Get oscillation parameters.
98  *
99  * \return reference to oscillation parameters
100  */
102  {
103  return static_cast<JOscParametersInterface_t&>(*this);
104  }
105 
106 
107  /**
108  * Get oscillation parameter.
109  *
110  * \param name parameter name
111  * \return parameter
112  */
113  JOscParameter_t& get(const std::string& name) const
114  {
115  using namespace std;
116  using namespace JPP;
117 
118  JProperties properties = this->getProperties();
119 
120  JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
121 
122  return parameter;
123  }
124 
125 
126  /**
127  * Set value for a given oscillation parameter.
128  *
129  * \param name parameter name
130  * \param value parameter value
131  */
132  void set(const std::string& name,
133  const value_type& value)
134  {
135  using namespace std;
136  using namespace JPP;
137 
138  JProperties properties = this->getProperties();
139 
140  JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
141 
142  parameter.setValue(value);
143  }
144 
145 
146  /**
147  * Set value for given list of oscillation parameters.
148  *
149  * \param name parameter name
150  * \param value parameter value
151  * \param args remaining pairs of parameter names and values
152  */
153  template<class ...Args>
154  void set(const std::string& name,
155  const value_type& value,
156  const Args& ...args)
157  {
158  set(name, value);
159  set(args...);
160  }
161 
162 
163  /**
164  * Set oscillation parameters.
165  *
166  * \param parameters oscillation parameters
167  */
169  {
170  using namespace std;
171  using namespace JPP;
172 
173  JProperties properties = parameters.getProperties();
174 
175  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
176 
177  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
178 
179  this->set(i->first, parameter.getValue());
180  }
181  }
182 
183 
184  /**
185  * Check validity of oscillation parameters.
186  *
187  * \return true if all oscillation parameters are valid; else false
188  */
189  bool is_valid() const
190  {
191  bool valid = true;
192 
193  const JProperties properties = this->getProperties();
194 
195  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && valid; ++i) {
196 
197  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
198 
199  valid = parameter.is_valid();
200  }
201 
202  return valid;
203  }
204 
205 
206  /**
207  * Check whether these oscillation parameters are equal to given oscillation parameters.
208  *
209  * \return true if equal; else false
210  */
212  {
213  using namespace std;
214  using namespace JPP;
215 
216  bool equal = true;
217 
218  JProperties properties = parameters.getProperties();
219 
220  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && equal; ++i) {
221 
222  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
223 
224  equal = (parameter == this->get(i->first));
225  }
226 
227  return equal;
228  }
229 
230 
231  /**
232  * Get equation parameters.
233  *
234  * \return equation parameters
235  */
237  {
238  static JEquationParameters equation("=", "\n\r;,", "./", "#");
239 
240  return equation;
241  }
242 
243 
244  /**
245  * Set equation parameters.
246  *
247  * \param equation equation parameters
248  */
249  static inline void setEquationParameters(const JEquationParameters& equation)
250  {
251  getEquationParameters() = equation;
252  }
253 
254 
255  /**
256  * Binary stream input of oscillation parameters.
257  *
258  * \param in input stream
259  * \return input stream
260  */
261  JReader& read(JReader& in) override
262  {
263  JProperties properties = this->getProperties();
264 
265  for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
266 
267  bool is_defined;
268  value_type value;
269 
270  if ((in >> is_defined >> value) && is_defined) {
271 
272  JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
273 
274  parameter.setValue(value);
275  }
276  }
277 
278  return in;
279  }
280 
281 
282  /**
283  * Binary stream output of oscillation parameters.
284  *
285  * \param out output stream
286  * \return output stream
287  */
288  JWriter& write(JWriter& out) const override
289  {
290  const JProperties properties = this->getProperties();
291 
292  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
293 
294  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
295 
296  out << parameter.isDefined() << parameter.getValue();
297  }
298 
299  return out;
300  }
301 
302 
303  /**
304  * Stream input of oscillation parameters.
305  *
306  * \param in input stream
307  * \param parameters oscillation parameters
308  * \return input stream
309  */
310  friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters)
311  {
312  using namespace std;
313  using namespace JPP;
314 
315  JStringStream is(in);
316 
317  if (getFileStatus(is.str().c_str())) {
318  is.load();
319  }
320 
321  JProperties properties = parameters.getProperties();
322  is >> properties;
323 
324  return in;
325  }
326 
327 
328  /**
329  * Stream output of oscillation parameters.
330  *
331  * \param out output stream
332  * \param parameters oscillation parameters
333  * \return output stream
334  */
335  friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters)
336  {
337  return out << parameters.getProperties();
338  }
339  };
340 
341 
342  /**
343  * Get size of given oscillation parameters set.
344  *
345  * \param parameters oscillation parameters set
346  * \return size (= number of defined parameters)
347  */
348  template<class T>
350  {
351  size_t n = 0;
352 
353  const JProperties properties = parameters.getProperties();
354 
355  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
356  const JOscParameter<T>& parameter = i->second.getValue<const JOscParameter<T> >();
357 
358  n += (size_t) parameter.isDefined();
359  }
360 
361  return n;
362  }
363 
364 
365  /**
366  * Get size of given oscillation parameters grid.
367  *
368  * \param parameters oscillation parameters grid
369  * \return size (= number of defined parameters)
370  */
372  {
373  size_t n = 1;
374 
375  const JProperties properties = parameters.getProperties();
376 
377  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
378  const JOscParameter<JGrid<double> >& parameter = i->second.getValue<const JOscParameter<JGrid<double> > >();
379 
380  if (parameter.isDefined()) {
381  n *= getSize(parameter);
382  }
383  }
384 
385  return n;
386  }
387 }
388 
389 #endif
Abstract base class for oscillation parameter.
JReader & read(JReader &in) override
Binary stream input of oscillation parameters.
JOscParametersInterface< T > JOscParametersInterface_t
Interface for binary output.
Parameter class.
Definition: JParameter.hh:34
friend std::ostream & operator<<(std::ostream &out, const JOscParametersInterface_t &parameters)
Stream output of oscillation parameters.
void set(const std::string &name, const value_type &value, const Args &...args)
Set value for given list of oscillation parameters.
friend std::istream & operator>>(std::istream &in, JOscParametersInterface_t &parameters)
Stream input of oscillation parameters.
Utility class to parse parameter values.
Definition: JProperties.hh:497
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Simple data structure to support I/O of equations (see class JLANG::JEquation).
bool is_valid() const
Check validity of oscillation parameters.
is
Definition: JDAQCHSM.chsm:167
size_t getSize(T(&array)[N])
Get size of c-array.
Definition: JLangToolkit.hh:32
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
Utility class to parse parameter values.
bool equals(const JOscParametersInterface< value_type > &parameters) const
Check whether these oscillation parameters are equal to given oscillation parameters.
JParameter_t::argument_type argument_type
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:116
void set(const JOscParametersInterface< value_type > &parameters)
Set oscillation parameters.
void set(const std::string &name, const value_type &value)
Set value for a given oscillation parameter.
Forward declaration of binary output.
const int n
Definition: JPolint.hh:786
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
Template class for object cloning.
Definition: JClonable.hh:20
JOscParameter_t::JParameter_t JParameter_t
Interface for binary input.
virtual bool is_valid() const =0
Check validity of oscillation parameter.
JClass< T >::argument_type argument_type
Definition: JParameter.hh:39
then fatal The output file must have the wildcard in the name
Definition: JCanberra.sh:31
void setValue(const value_type &value)
Set parameter.
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:38
static JEquationParameters & getEquationParameters()
Get equation parameters.
JOscParametersInterface_t & getParameters()
Get oscillation parameters.
JOscParametersInterface()
Default constructor.
JClass< T >::value_type value_type
Definition: JParameter.hh:40
Interface class for sets of oscillation parameters.
const value_type getValue() const
Get value of parameter.
Definition: JParameter.hh:82
File status.