Jpp  18.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 "JSystem/JStat.hh"
9 
10 #include "Jeep/JPrint.hh"
11 #include "Jeep/JComment.hh"
12 #include "Jeep/JProperties.hh"
13 
14 #include "JIO/JSerialisable.hh"
15 
16 #include "JLang/JEquals.hh"
17 #include "JLang/JParameter.hh"
18 #include "JLang/JVectorize.hh"
19 #include "JLang/JStringStream.hh"
20 #include "JLang/JObjectStreamIO.hh"
22 
23 
24 /**
25  * \author bjung, mdejong
26  */
27 
28 namespace JOSCPROB {}
29 namespace JPP { using namespace JOSCPROB; }
30 
31 namespace JOSCPROB {
32 
33  using JIO::JReader;
34  using JIO::JWriter;
35  using JIO::JSerialisable;
36 
37  using JEEP::JComment;
38 
39  using JLANG::JEquals;
40  using JLANG::JParameter;
44 
45 
46  /**
47  * Abstract base class for sets of oscillation parameters.
48  */
49  template<class T>
51  public JSerialisable,
52  public JObjectStreamIO<JOscParametersInterface<T> >,
53  public JEquals <JOscParametersInterface<T> >
54  {
58 
59 
60  /**
61  * Default constructor.
62  */
64  dM21sq (),
65  dM31sq (),
66  deltaCP (),
67  sinsqTh12(),
68  sinsqTh13(),
69  sinsqTh23()
70  {}
71 
72 
73  /**
74  * Constructor.
75  *
76  * \param dM21sq Squared mass difference between the first and second neutrino mass eigenstates [eV2]
77  * \param dM31sq Squared mass difference between the first and third neutrino mass eigenstates [eV2]
78  * \param deltaCP PMNS phase angle [pi rad]
79  * \param sinsqTh12 Squared sine of the PMNS mixing angle between the first and second neutrino mass eigenstates [-]
80  * \param sinsqTh13 Squared sine of the PMNS mixing angle between the first and third neutrino mass eigenstates [-]
81  * \param sinsqTh23 Squared sine of the PMNS mixing angle between the second and third neutrino mass eigenstates [-]
82  */
84  const T& dM31sq,
85  const T& deltaCP,
86  const T& sinsqTh12,
87  const T& sinsqTh13,
88  const T& sinsqTh23) :
89  dM21sq (dM21sq),
90  dM31sq (dM31sq),
91  deltaCP (deltaCP),
92  sinsqTh12(sinsqTh12),
93  sinsqTh13(sinsqTh13),
94  sinsqTh23(sinsqTh23)
95  {}
96 
97 
98  /**
99  * Constructor.
100  *
101  * \param name parameter name
102  * \param value parameter value
103  * \param args remaining pairs of parameter names and values
104  */
105  template<class ...Args>
107  const T& value,
108  const Args& ...args)
109  {
110  set(name, value, args...);
111  }
112 
113 
114  /**
115  * Set value for a given oscillation parameter.
116  *
117  * \param name parameter name
118  * \param value parameter value
119  */
120  void set(const std::string& name,
121  const T& value)
122  {
123  JProperties properties = this->getProperties();
124 
125  JProperties::iterator i = properties.find(name);
126 
127  if (i != properties.end()) {
128 
129  i->second.setValue(JParameter_t(value));
130 
131  } else {
132 
134  "template<class T> JOscParametersInterface<T>::set(const std::string&, const T&): " <<
135  "Invalid oscillation parameter name " << name << "; Valid options:\n" << JLANG::get_keys(properties));
136  }
137  }
138 
139 
140  /**
141  * Set value for given list of oscillation parameters.
142  *
143  * \param name parameter name
144  * \param value parameter value
145  * \param args remaining pairs of parameter names and values
146  */
147  template<class ...Args>
148  void set(const std::string& name,
149  const T& value,
150  const Args& ...args)
151  {
152  set(name, value);
153  set(args...);
154  }
155 
156 
157  /**
158  * Join the given oscillation parameters with these oscillation parameters.
159  *
160  * \param parameters oscillation parameters
161  */
163  {
164  if (parameters.dM21sq.isDefined()) { this->dM21sq = parameters.dM21sq; }
165  if (parameters.dM31sq.isDefined()) { this->dM31sq = parameters.dM31sq; }
166  if (parameters.deltaCP.isDefined()) { this->deltaCP = parameters.deltaCP; }
167  if (parameters.sinsqTh12.isDefined()) { this->sinsqTh12 = parameters.sinsqTh12; }
168  if (parameters.sinsqTh13.isDefined()) { this->sinsqTh13 = parameters.sinsqTh13; }
169  if (parameters.sinsqTh23.isDefined()) { this->sinsqTh23 = parameters.sinsqTh23; }
170 
171  return *this;
172  }
173 
174 
175  /**
176  * Get oscillation parameters.
177  *
178  * \return oscillation parameters
179  */
181  {
182  return static_cast<const JOscParameters_t&>(*this);
183  }
184 
185 
186  /**
187  * Set oscillation parameters.
188  *
189  * \param parameters oscillation parameters
190  */
192  {
193  static_cast<JOscParameters_t&>(*this) = parameters;
194  }
195 
196 
197  /**
198  * Check validity of oscillation parameters.
199  *
200  * \return true if valid; else false
201  */
202  virtual bool is_valid() const = 0;
203 
204 
205  /**
206  * Get size of this oscillation parameters set.
207  *
208  * \return size (= number of defined parameters)
209  */
210  virtual unsigned int size() const
211  {
212  return ((unsigned int) this->dM21sq.isDefined() +
213  (unsigned int) this->dM31sq.isDefined() +
214  (unsigned int) this->deltaCP.isDefined() +
215  (unsigned int) this->sinsqTh12.isDefined() +
216  (unsigned int) this->sinsqTh13.isDefined() +
217  (unsigned int) this->sinsqTh23.isDefined());
218  }
219 
220 
221  /**
222  * Check if this oscillations parameter set contains the given oscillation parameters.
223  *
224  * \param parameters oscillation parameters
225  * \return true if all given oscillation parameters\n
226  * are also defined in this oscillation parameters set
227  */
228  virtual bool contains(const JOscParameters_t& parameters) const
229  {
230  if ( (parameters.dM21sq.isDefined() && !this->dM21sq.isDefined()) ||
231  (parameters.dM31sq.isDefined() && !this->dM31sq.isDefined()) ||
232  (parameters.deltaCP.isDefined() && !this->deltaCP.isDefined()) ||
233  (parameters.sinsqTh12.isDefined() && !this->sinsqTh12.isDefined()) ||
234  (parameters.sinsqTh13.isDefined() && !this->sinsqTh13.isDefined()) ||
235  (parameters.sinsqTh23.isDefined() && !this->sinsqTh23.isDefined()) ) {
236  return false;
237  } else {
238  return true;
239  }
240  }
241 
242 
243  bool equals(const JOscParameters_t& parameters) const
244  {
245  return (this->dM21sq == parameters.dM21sq &&
246  this->dM31sq == parameters.dM31sq &&
247  this->deltaCP == parameters.deltaCP &&
248  this->sinsqTh12 == parameters.sinsqTh12 &&
249  this->sinsqTh13 == parameters.sinsqTh13 &&
250  this->sinsqTh23 == parameters.sinsqTh23);
251  }
252 
253 
254  /**
255  * Stream input of oscillation parameters.
256  *
257  * \param in input stream
258  * \param parameters oscillation parameters
259  * \return input stream
260  */
261  friend inline std::istream& operator>>(std::istream& in, JOscParameters_t& parameters)
262  {
263  using namespace std;
264  using namespace JPP;
265 
266  JStringStream is(in);
267 
268  if (getFileStatus(is.str().c_str())) {
269  is.load();
270  }
271 
272  JProperties properties = parameters.getProperties();
273 
274  is >> parameters.comment;
275  is >> properties;
276 
277  parameters.setProperties(properties);
278 
279  return in;
280  }
281 
282 
283  /**
284  * Stream output of oscillation parameters.
285  *
286  * \param out output stream
287  * \param parameters oscillation parameters
288  * \return output stream
289  */
290  friend inline std::ostream& operator<<(std::ostream& out, const JOscParameters_t& parameters)
291  {
292  out << parameters.comment;
293  out << parameters.getProperties();
294 
295  return out;
296  }
297 
298 
299  /**
300  * Binary stream input of oscillation parameters.
301  *
302  * \param in input stream
303  * \return input stream
304  */
305  JReader& read(JReader& in) override
306  {
307  JProperties properties = getProperties();
308 
309  for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
310 
311  bool is_defined;
312  T value;
313 
314  if ((in >> is_defined >> value) && is_defined) {
315 
316  JParameter_t& parameter = i->second.getValue<JParameter_t>();
317 
318  parameter.setValue(value);
319  }
320  }
321 
322  return in;
323  }
324 
325 
326  /**
327  * Binary stream output of oscillation parameters.
328  *
329  * \param out output stream
330  * \return output stream
331  */
332  JWriter& write(JWriter& out) const override
333  {
334  const JProperties properties = getProperties();
335 
336  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
337 
338  const JParameter_t& parameter = i->second.getValue<const JParameter_t>();
339 
340  out << parameter.isDefined() << parameter.getValue();
341  }
342 
343  return out;
344  }
345 
346 
347  /**
348  * Get equation parameters.
349  *
350  * \return equation parameters
351  */
353  {
354  static JEquationParameters equation("=", "\n\r;,", "./", "#");
355 
356  return equation;
357  }
358 
359 
360  /**
361  * Set equation parameters.
362  *
363  * \param equation equation parameters
364  */
365  static inline void setEquationParameters(const JEquationParameters& equation)
366  {
367  getEquationParameters() = equation;
368  }
369 
370 
371  /**
372  * Get properties of this class.
373  *
374  * \param equation equation parameters
375  */
377  {
378  return JOscParametersHelper(*this, equation);
379  }
380 
381 
382  /**
383  * Get properties of this class.
384  *
385  * \param equation equation parameters
386  */
388  {
389  return JOscParametersHelper(*this, equation);
390  }
391 
392 
393  /**
394  * Set properties of this class
395  *
396  * \param properties properties
397  */
398  void setProperties(const JProperties& properties)
399  {
400  this->dM21sq = properties.getValue<JParameter_t>("dM21sq");
401  this->dM31sq = properties.getValue<JParameter_t>("dM31sq");
402  this->deltaCP = properties.getValue<JParameter_t>("deltaCP");
403  this->sinsqTh12 = properties.getValue<JParameter_t>("sinsqTh12");
404  this->sinsqTh13 = properties.getValue<JParameter_t>("sinsqTh13");
405  this->sinsqTh23 = properties.getValue<JParameter_t>("sinsqTh23");
406  }
407 
408 
409  JParameter_t dM21sq; //!< Squared mass difference between the first and second neutrino mass eigenstates [eV2]
410  JParameter_t dM31sq; //!< Squared mass difference between the first and third neutrino mass eigenstates [eV2]
411  JParameter_t deltaCP; //!< PMNS phase angle [pi * rad]
412  JParameter_t sinsqTh12; //!< Squared sine of the PMNS mixing angle between the first and second neutrino mass eigenstates [-]
413  JParameter_t sinsqTh13; //!< Squared sine of the PMNS mixing angle between the first and third neutrino mass eigenstates [-]
414  JParameter_t sinsqTh23; //!< Squared sine of the PMNS mixing angle between the second and third neutrino mass eigenstates [-]
415 
417 
418 
419  private:
420 
421  /**
422  * Auxiliary class for I/O of oscillation parameters.
423  */
425  public JProperties
426  {
427  /**
428  * Constructor.
429  *
430  * \param parameters oscillation parameters
431  * \param equation equation parameters
432  */
433  template<class JOscParameters_t>
435  const JEquationParameters& equation) :
436  JProperties(equation, 1)
437  {
438  this->insert(gmake_property(parameters.dM21sq));
439  this->insert(gmake_property(parameters.dM31sq));
440  this->insert(gmake_property(parameters.deltaCP));
441  this->insert(gmake_property(parameters.sinsqTh12));
442  this->insert(gmake_property(parameters.sinsqTh13));
443  this->insert(gmake_property(parameters.sinsqTh23));
444  }
445  };
446  };
447 }
448 
449 #endif
Interface for binary output.
virtual unsigned int size() const
Get size of this oscillation parameters set.
Parameter class.
Definition: JParameter.hh:34
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
JParameter_t sinsqTh12
Squared sine of the PMNS mixing angle between the first and second neutrino mass eigenstates [-]...
JOscParametersInterface(const T &dM21sq, const T &dM31sq, const T &deltaCP, const T &sinsqTh12, const T &sinsqTh13, const T &sinsqTh23)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
JParameter_t dM21sq
Squared mass difference between the first and second neutrino mass eigenstates [eV2].
Utility class to parse parameter values.
Definition: JProperties.hh:496
JReader & read(JReader &in) override
Binary stream input of oscillation parameters.
*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).
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
void set(const std::string &name, const T &value, const Args &...args)
Set value for given list of oscillation parameters.
JParameter_t sinsqTh13
Squared sine of the PMNS mixing angle between the first and third neutrino mass eigenstates [-]...
is
Definition: JDAQCHSM.chsm:167
const JOscParameters_t & getOscParameters() const
Get oscillation parameters.
Auxiliary class for I/O of oscillation parameters.
Utility class to parse parameter values.
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:136
virtual bool is_valid() const =0
Check validity of oscillation parameters.
Forward declaration of binary output.
JProperties getProperties(const JEquationParameters &equation=JOscParameters_t::getEquationParameters())
Get properties of this class.
const T & getValue(const std::string &key) const
Get value.
Definition: JProperties.hh:974
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
I/O formatting auxiliaries.
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
friend std::istream & operator>>(std::istream &in, JOscParameters_t &parameters)
Stream input of oscillation parameters.
bool equals(const JOscParameters_t &parameters) const
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
void setValue(const argument_type &value)
Set value.
Definition: JParameter.hh:102
then awk string
JOscParametersInterface(const std::string &name, const T &value, const Args &...args)
Constructor.
JParameter_t dM31sq
Squared mass difference between the first and third neutrino mass eigenstates [eV2].
Interface for binary input.
JOscParametersInterface()
Default constructor.
JOscParametersHelper(JOscParameters_t &parameters, const JEquationParameters &equation)
Constructor.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
JClass< T >::argument_type argument_type
Definition: JParameter.hh:39
JOscParameters_t & join(const JOscParameters_t &parameters)
Join the given oscillation parameters with these oscillation parameters.
virtual bool contains(const JOscParameters_t &parameters) const
Check if this oscillations parameter set contains the given oscillation parameters.
void setValue(const std::string &key, const T &value)
Set value.
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
void setOscParameters(const JOscParameters_t &parameters)
Set oscillation parameters.
Auxiliary class for comment.
Definition: JComment.hh:41
static JEquationParameters & getEquationParameters()
Get equation parameters.
void set(const std::string &name, const T &value)
Set value for a given oscillation parameter.
JParameter_t sinsqTh23
Squared sine of the PMNS mixing angle between the second and third neutrino mass eigenstates [-]...
Abstract base class for sets of oscillation parameters.
JProperties getProperties(const JEquationParameters &equation=JOscParameters_t::getEquationParameters()) const
Get properties of this class.
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:80
friend std::ostream & operator<<(std::ostream &out, const JOscParameters_t &parameters)
Stream output of oscillation parameters.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Auxiliary base class for storing and loading a single object to and from an ASCII file...
JParameter_t::argument_type argument_type
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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:46
JParameter_t deltaCP
PMNS phase angle [pi * rad].
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
Definition: JVectorize.hh:139
JOscParametersInterface< T > JOscParameters_t
File status.
void setProperties(const JProperties &properties)
Set properties of this class.