Jpp  17.1.1
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/JPrint.hh"
9 #include "Jeep/JProperties.hh"
10 
11 #include "JIO/JSerialisable.hh"
12 
13 #include "JLang/JParameter.hh"
14 #include "JLang/JVectorize.hh"
16 
17 
18 /**
19  * \author bjung, mdejong
20  */
21 
22 namespace JOSCPROB {}
23 namespace JPP { using namespace JOSCPROB; }
24 
25 namespace JOSCPROB {
26 
27  using JIO::JReader;
28  using JIO::JWriter;
29  using JIO::JSerialisable;
30 
31  using JLANG::JParameter;
34 
35 
36  /**
37  * Abstract base class for sets of oscillation parameters.
38  */
39  template<class T>
41  public JSerialisable
42  {
46 
47 
48  /**
49  * Default constructor.
50  */
52  dM21sq (),
53  dM31sq (),
54  deltaCP (),
55  sinsqTh12(),
56  sinsqTh13(),
57  sinsqTh23()
58  {}
59 
60 
61  /**
62  * Constructor.
63  *
64  * \param dM21sq Squared mass difference between the first and second neutrino mass eigenstates [eV2]
65  * \param dM31sq Squared mass difference between the first and third neutrino mass eigenstates [eV2]
66  * \param deltaCP PMNS phase angle [pi rad]
67  * \param sinsqTh12 Squared sine of the PMNS mixing angle between the first and second neutrino mass eigenstates [-]
68  * \param sinsqTh13 Squared sine of the PMNS mixing angle between the first and third neutrino mass eigenstates [-]
69  * \param sinsqTh23 Squared sine of the PMNS mixing angle between the second and third neutrino mass eigenstates [-]
70  */
72  const T& dM31sq,
73  const T& deltaCP,
74  const T& sinsqTh12,
75  const T& sinsqTh13,
76  const T& sinsqTh23) :
77  dM21sq (dM21sq),
78  dM31sq (dM31sq),
79  deltaCP (deltaCP),
80  sinsqTh12(sinsqTh12),
81  sinsqTh13(sinsqTh13),
82  sinsqTh23(sinsqTh23)
83  {}
84 
85 
86  /**
87  * Constructor.
88  *
89  * \param name parameter name
90  * \param value parameter value
91  * \param args remaining pairs of parameter names and values
92  */
93  template<class ...Args>
94  JOscParametersInterface(const std::string& name,
95  const T& value,
96  const Args& ...args)
97  {
98  set(name, value, args...);
99  }
100 
101 
102  /**
103  * Set value for a given oscillation parameter.
104  *
105  * \param name parameter name
106  * \param value parameter value
107  */
108  void set(const std::string& name,
109  const T& value)
110  {
111  JProperties properties = this->getProperties();
112 
113  JProperties::iterator i = properties.find(name);
114 
115  if (i != properties.end()) {
116 
117  i->second.setValue(JParameter_t(value));
118 
119  } else {
120 
122  "template<class T> JOscParametersInterface<T>::set(const std::string&, const T&): " <<
123  "Invalid oscillation parameter name " << name << "; Valid options:\n" << JLANG::get_keys(properties));
124  }
125  }
126 
127 
128  /**
129  * Set value for given list of oscillation parameters.
130  *
131  * \param name parameter name
132  * \param value parameter value
133  * \param args remaining pairs of parameter names and values
134  */
135  template<class ...Args>
136  void set(const std::string& name,
137  const T& value,
138  const Args& ...args)
139  {
140  set(name, value);
141  set(args...);
142  }
143 
144 
145  /**
146  * Join the given oscillation parameters with these oscillation parameters.
147  *
148  * \param parameters oscillation parameters
149  */
151  {
152  if (parameters.dM21sq.isDefined()) { this->dM21sq = parameters.dM21sq; }
153  if (parameters.dM31sq.isDefined()) { this->dM31sq = parameters.dM31sq; }
154  if (parameters.deltaCP.isDefined()) { this->deltaCP = parameters.deltaCP; }
155  if (parameters.sinsqTh12.isDefined()) { this->sinsqTh12 = parameters.sinsqTh12; }
156  if (parameters.sinsqTh13.isDefined()) { this->sinsqTh13 = parameters.sinsqTh13; }
157  if (parameters.sinsqTh23.isDefined()) { this->sinsqTh23 = parameters.sinsqTh23; }
158 
159  return *this;
160  }
161 
162 
163  /**
164  * Get oscillation parameters.
165  *
166  * \return oscillation parameters
167  */
169  {
170  return static_cast<const JOscParameters_t&>(*this);
171  }
172 
173 
174  /**
175  * Set oscillation parameters.
176  *
177  * \param parameters oscillation parameters
178  */
180  {
181  static_cast<JOscParameters_t&>(*this) = parameters;
182  }
183 
184 
185  /**
186  * Check validity of oscillation parameters.
187  *
188  * \return true if valid; else false
189  */
190  virtual bool is_valid() const = 0;
191 
192 
193  /**
194  * Get size of this oscillation parameters set.
195  *
196  * \return size (= number of defined parameters)
197  */
198  virtual unsigned int size() const
199  {
200  return ((unsigned int) this->dM21sq.isDefined() +
201  (unsigned int) this->dM31sq.isDefined() +
202  (unsigned int) this->deltaCP.isDefined() +
203  (unsigned int) this->sinsqTh12.isDefined() +
204  (unsigned int) this->sinsqTh13.isDefined() +
205  (unsigned int) this->sinsqTh23.isDefined());
206  }
207 
208 
209  /**
210  * Check if this oscillations parameter set contains the given oscillation parameters.
211  *
212  * \param parameters oscillation parameters
213  * \return true if all given oscillation parameters\n
214  * are also defined in this oscillation parameters set
215  */
216  virtual bool contains(const JOscParameters_t& parameters) const
217  {
218  if ( (parameters.dM21sq.isDefined() && !this->dM21sq.isDefined()) ||
219  (parameters.dM31sq.isDefined() && !this->dM31sq.isDefined()) ||
220  (parameters.deltaCP.isDefined() && !this->deltaCP.isDefined()) ||
221  (parameters.sinsqTh12.isDefined() && !this->sinsqTh12.isDefined()) ||
222  (parameters.sinsqTh13.isDefined() && !this->sinsqTh13.isDefined()) ||
223  (parameters.sinsqTh23.isDefined() && !this->sinsqTh23.isDefined()) ) {
224  return false;
225  } else {
226  return true;
227  }
228  }
229 
230 
231  /**
232  * Stream input of oscillation parameters.
233  *
234  * \param in input stream
235  * \param parameters oscillation parameters
236  * \return input stream
237  */
238  friend inline std::istream& operator>>(std::istream& in, JOscParameters_t& parameters)
239  {
240  JProperties properties(parameters.getProperties());
241 
242  in >> properties;
243 
244  parameters.setProperties(properties);
245 
246  return in;
247  }
248 
249 
250  /**
251  * Stream output of oscillation parameters.
252  *
253  * \param out output stream
254  * \param parameters oscillation parameters
255  * \return output stream
256  */
257  friend inline std::ostream& operator<<(std::ostream& out, const JOscParameters_t& parameters)
258  {
259  return out << parameters.getProperties();
260  }
261 
262 
263  /**
264  * Binary stream input of oscillation parameters.
265  *
266  * \param in input stream
267  * \return input stream
268  */
269  JReader& read(JReader& in) override
270  {
271  JProperties properties = getProperties();
272 
273  for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
274 
275  bool is_defined;
276  T value;
277 
278  if ((in >> is_defined >> value) && is_defined) {
279 
280  JParameter_t& parameter = i->second.getValue<JParameter_t>();
281 
282  parameter.setValue(value);
283  }
284  }
285 
286  return in;
287  }
288 
289 
290  /**
291  * Binary stream output of oscillation parameters.
292  *
293  * \param out output stream
294  * \return output stream
295  */
296  JWriter& write(JWriter& out) const override
297  {
298  const JProperties properties = getProperties();
299 
300  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
301 
302  const JParameter_t& parameter = i->second.getValue<JParameter_t>();
303 
304  out << parameter.isDefined() << parameter.getValue();
305  }
306 
307  return out;
308  }
309 
310 
311  /**
312  * Get equation parameters.
313  *
314  * \return equation parameters
315  */
317  {
318  static JEquationParameters equation("=", "\n\r;,", "./", "#");
319 
320  return equation;
321  }
322 
323 
324  /**
325  * Set equation parameters.
326  *
327  * \param equation equation parameters
328  */
329  static inline void setEquationParameters(const JEquationParameters& equation)
330  {
331  getEquationParameters() = equation;
332  }
333 
334 
335  /**
336  * Get properties of this class.
337  *
338  * \param equation equation parameters
339  */
341  {
342  return JOscParametersHelper(*this, equation);
343  }
344 
345 
346  /**
347  * Get properties of this class.
348  *
349  * \param equation equation parameters
350  */
352  {
353  return JOscParametersHelper(*this, equation);
354  }
355 
356 
357  /**
358  * Set properties of this class
359  *
360  * \param properties properties
361  */
362  void setProperties(const JProperties& properties)
363  {
364  this->dM21sq = properties.getValue<JParameter_t>("dM21sq");
365  this->dM31sq = properties.getValue<JParameter_t>("dM31sq");
366  this->deltaCP = properties.getValue<JParameter_t>("deltaCP");
367  this->sinsqTh12 = properties.getValue<JParameter_t>("sinsqTh12");
368  this->sinsqTh13 = properties.getValue<JParameter_t>("sinsqTh13");
369  this->sinsqTh23 = properties.getValue<JParameter_t>("sinsqTh23");
370  }
371 
372 
373  JParameter_t dM21sq; //!< Squared mass difference between the first and second neutrino mass eigenstates [eV2]
374  JParameter_t dM31sq; //!< Squared mass difference between the first and third neutrino mass eigenstates [eV2]
375  JParameter_t deltaCP; //!< PMNS phase angle [pi * rad]
376  JParameter_t sinsqTh12; //!< Squared sine of the PMNS mixing angle between the first and second neutrino mass eigenstates [-]
377  JParameter_t sinsqTh13; //!< Squared sine of the PMNS mixing angle between the first and third neutrino mass eigenstates [-]
378  JParameter_t sinsqTh23; //!< Squared sine of the PMNS mixing angle between the second and third neutrino mass eigenstates [-]
379 
380 
381  private:
382 
383  /**
384  * Auxiliary class for I/O of oscillation parameters.
385  */
387  public JProperties
388  {
389  /**
390  * Constructor.
391  *
392  * \param parameters oscillation parameters
393  * \param equation equation parameters
394  */
395  template<class JOscParameters_t>
397  const JEquationParameters& equation) :
398  JProperties(equation, 1)
399  {
400  this->insert(gmake_property(parameters.dM21sq));
401  this->insert(gmake_property(parameters.dM31sq));
402  this->insert(gmake_property(parameters.deltaCP));
403  this->insert(gmake_property(parameters.sinsqTh12));
404  this->insert(gmake_property(parameters.sinsqTh13));
405  this->insert(gmake_property(parameters.sinsqTh23));
406  }
407  };
408  };
409 }
410 
411 #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)
macro 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).
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 [-]...
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.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void setValue(const argument_type &value)
Set value.
Definition: JParameter.hh:102
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.
void setOscParameters(const JOscParameters_t &parameters)
Set oscillation parameters.
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
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
void setProperties(const JProperties &properties)
Set properties of this class.