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