Jpp  18.5.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/JClonable.hh"
16 #include "JLang/JParameter.hh"
17 #include "JLang/JStringStream.hh"
19 
20 #include "JTools/JGrid.hh"
21 
23 
24 
25 /**
26  * \author bjung, mdejong
27  */
28 
29 namespace JOSCPROB {}
30 namespace JPP { using namespace JOSCPROB; }
31 
32 namespace JOSCPROB {
33 
34  using JIO::JReader;
35  using JIO::JWriter;
36  using JIO::JSerialisable;
37 
38  using JLANG::JClonable;
40 
41 
42  /**
43  * Interface class for sets of oscillation parameters.
44  */
45  template<class T = double>
47  public JClonable<JOscParametersInterface<T> >,
48  public JSerialisable
49  {
50  public:
51 
54 
56 
58 
59 
60  /**
61  * Default constructor.
62  */
64  {}
65 
66 
67  /**
68  * Virtual destructor.
69  */
71  {}
72 
73 
74  /**
75  * Get properties of this class.
76  *
77  * \param equation equation parameters
78  * \return properties of this class
79  */
81 
82 
83  /**
84  * Get properties of this class.
85  *
86  * \param equation equation parameters
87  * \return properties of this class
88  */
90 
91 
92  /**
93  * Get oscillation parameters.
94  *
95  * \return reference to oscillation parameters
96  */
98  {
99  return static_cast<JOscParametersInterface_t&>(*this);
100  }
101 
102 
103  /**
104  * Set value for a given oscillation parameter.
105  *
106  * \param name parameter name
107  * \param value parameter value
108  */
109  void set(const std::string& name,
110  argument_type value)
111  {
112  using namespace std;
113  using namespace JPP;
114 
115  JProperties properties = this->getProperties();
116 
117  JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
118 
119  parameter.setValue(value);
120  }
121 
122 
123  /**
124  * Set value for given list of oscillation parameters.
125  *
126  * \param name parameter name
127  * \param value parameter value
128  * \param args remaining pairs of parameter names and values
129  */
130  template<class ...Args>
131  void set(const std::string& name,
132  argument_type value,
133  const Args& ...args)
134  {
135  set(name, value);
136  set(args...);
137  }
138 
139 
140  /**
141  * Set oscillation parameters.
142  *
143  * \param parameters oscillation parameters
144  */
146  {
147  using namespace std;
148  using namespace JPP;
149 
150  JProperties properties = parameters.getProperties();
151 
152  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
153 
154  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
155 
156  this->set(i->first, parameter.getValue());
157  }
158  }
159 
160 
161  /**
162  * Check validity of oscillation parameters.
163  *
164  * \return true if all oscillation parameters are valid; else false
165  */
166  bool is_valid() const
167  {
168  bool valid = true;
169 
170  const JProperties properties = this->getProperties();
171 
172  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && valid; ++i) {
173 
174  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
175 
176  valid = parameter.is_valid();
177  }
178 
179  return valid;
180  }
181 
182 
183  /**
184  * Get equation parameters.
185  *
186  * \return equation parameters
187  */
189  {
190  static JEquationParameters equation("=", "\n\r;,", "./", "#");
191 
192  return equation;
193  }
194 
195 
196  /**
197  * Set equation parameters.
198  *
199  * \param equation equation parameters
200  */
201  static inline void setEquationParameters(const JEquationParameters& equation)
202  {
203  getEquationParameters() = equation;
204  }
205 
206 
207  /**
208  * Binary stream input of oscillation parameters.
209  *
210  * \param in input stream
211  * \return input stream
212  */
213  JReader& read(JReader& in) override
214  {
215  JProperties properties = this->getProperties();
216 
217  for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
218 
219  bool is_defined;
220  T value;
221 
222  if ((in >> is_defined >> value) && is_defined) {
223 
224  JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
225 
226  parameter.setValue(value);
227  }
228  }
229 
230  return in;
231  }
232 
233 
234  /**
235  * Binary stream output of oscillation parameters.
236  *
237  * \param out output stream
238  * \return output stream
239  */
240  JWriter& write(JWriter& out) const override
241  {
242  const JProperties properties = this->getProperties();
243 
244  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
245 
246  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
247 
248  out << parameter.isDefined() << parameter.getValue();
249  }
250 
251  return out;
252  }
253 
254 
255  /**
256  * Stream input of oscillation parameters.
257  *
258  * \param in input stream
259  * \param parameters oscillation parameters
260  * \return input stream
261  */
262  friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters)
263  {
264  using namespace std;
265  using namespace JPP;
266 
267  JStringStream is(in);
268 
269  if (getFileStatus(is.str().c_str())) {
270  is.load();
271  }
272 
273  JProperties properties = parameters.getProperties();
274  is >> properties;
275 
276  return in;
277  }
278 
279 
280  /**
281  * Stream output of oscillation parameters.
282  *
283  * \param out output stream
284  * \param parameters oscillation parameters
285  * \return output stream
286  */
287  friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters)
288  {
289  return out << parameters.getProperties();
290  }
291  };
292 
293 
294  /**
295  * Get size of given oscillation parameters set.
296  *
297  * \param parameters oscillation parameters set
298  * \return size (= number of defined parameters)
299  */
300  template<class T = double>
302  {
303  size_t n = 0;
304 
305  const JProperties properties = parameters.getProperties();
306 
307  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
308  const JOscParameter<T>& parameter = i->second.getValue<const JOscParameter<T> >();
309 
310  n += (size_t) parameter.isDefined();
311  }
312 
313  return n;
314  }
315 
316 
317  /**
318  * Get size of given oscillation parameters grid.
319  *
320  * \param parameters oscillation parameters grid
321  * \return size (= number of defined parameters)
322  */
324  {
325  size_t n = 1;
326 
327  const JProperties properties = parameters.getProperties();
328 
329  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
330  const JOscParameter<JGrid<double> >& parameter = i->second.getValue<const JOscParameter<JGrid<double> > >();
331 
332  if (parameter.isDefined()) {
333  n *= getSize(parameter);
334  }
335  }
336 
337  return n;
338  }
339 }
340 
341 #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.
friend std::istream & operator>>(std::istream &in, JOscParametersInterface_t &parameters)
Stream input of oscillation parameters.
void set(const JOscParametersInterface_t &parameters)
Set oscillation parameters.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
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.
void setValue(argument_type value)
Set parameter.
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.
JParameter_t::argument_type argument_type
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:137
void set(const std::string &name, argument_type value, const Args &...args)
Set value for given list of oscillation parameters.
Forward declaration of binary output.
const int n
Definition: JPolint.hh:786
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
Template class for object cloning.
Definition: JClonable.hh:20
then awk string
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
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 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:48
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:38
void set(const std::string &name, argument_type value)
Set value for a given oscillation parameter.
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:81
static JEquationParameters & getEquationParameters()
Get equation parameters.
JOscParametersInterface_t & getParameters()
Get oscillation parameters.
JOscParametersInterface()
Default constructor.
Interface class for sets of oscillation parameters.
File status.