Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOscParametersHelper.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCPARAMETERSHELPER__
2 #define __JOSCPROB__JOSCPARAMETERSHELPER__
3 
4 #include <memory>
5 
6 #include "JLang/JException.hh"
7 
9 
10 
11 /**
12  * \author bjung
13  */
14 
15 namespace JOSCPROB {}
16 namespace JPP { using namespace JOSCPROB; }
17 
18 namespace JOSCPROB {
19 
20  /**
21  * Helper class for oscillation parameters.
22  */
23  template<class T = double>
25  public std::shared_ptr<JOscParametersInterface<T> >
26  {
29 
33 
34  typedef std::shared_ptr<JOscParameters_t> pointer_type;
35 
36  using pointer_type::reset;
37 
38 
39  /**
40  * Default constructor.
41  */
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param parameters oscillation parameters
50  */
52  {
53  this->configure(parameters);
54  }
55 
56 
57  /**
58  * Constructor.
59  *
60  * \param parameters oscillation parameters
61  * \param name parameter name
62  * \param value parameter value
63  * \param args remaining pairs of parameter names and values
64  */
65  template<class ...Args>
67  const std::string& name,
68  argument_type value,
69  const Args& ...args)
70  {
71  this->configure(parameters);
72  this->set(name, value, args...);
73  }
74 
75 
76  /**
77  * Configure oscillation parameters.
78  *
79  * \param parameters oscillation parameters
80  */
81  virtual void configure(const JOscParameters_t& parameters)
82  {
83  using namespace std;
84  using namespace JPP;
85 
86  JOscParameters_t* p = dynamic_cast<JOscParameters_t*>(parameters.clone());
87 
88  if (p != NULL) {
89  reset(p);
90  } else {
91  THROW(JNullPointerException, "JOscParametersHelper::configure(): Unable to retrieve oscillation parameters interface.");
92  }
93  }
94 
95 
96  /**
97  * Get reference to oscillation parameters interface.
98  *
99  * \return reference to oscillation parameters interface
100  */
102  {
103  using namespace JPP;
104 
105  if (static_cast<const JOscParametersHelper_t&>(*this)) {
106  return *(this->get());
107  } else {
108  THROW(JNullPointerException, "JOscParametersHelper::getParameters(): Oscillation parameters interface is not set.");
109  }
110  }
111 
112 
113  /**
114  * Set value for a given oscillation parameter.
115  *
116  * \param name parameter name
117  * \param value parameter value
118  */
119  virtual void set(const std::string& name,
120  argument_type value) const
121  {
122  getParameters().set(name, value);
123  }
124 
125 
126  /**
127  * Set value for given list of oscillation parameters.
128  *
129  * \param name parameter name
130  * \param value parameter value
131  * \param args remaining pairs of parameter names and values
132  */
133  template<class ...Args>
134  void set(const std::string& name,
135  argument_type value,
136  const Args& ...args) const
137  {
138  this->set(name, value);
139  this->set(args...);
140  }
141 
142 
143  /**
144  * Set oscillation parameters.
145  *
146  * \param parameters oscillation parameters
147  */
148  void set(const JOscParameters_t& parameters) const
149  {
150  using namespace std;
151  using namespace JPP;
152 
153  const JProperties properties = parameters.getProperties();
154 
155  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
156  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
157 
158  this->set(i->first, parameter.getValue());
159  }
160  }
161 
162 
163  /**
164  * Check validity of oscillation parameters.
165  *
166  * \return true if all oscillation parameters are valid; else false
167  */
168  bool is_valid() const
169  {
170  return getParameters().is_valid();
171  }
172  };
173 }
174 
175 #endif
Abstract base class for oscillation parameter.
Exceptions.
JOscParameters_t::JParameter_t JParameter_t
JOscParameters_t & getParameters() const
Get reference to oscillation parameters interface.
Parameter class.
Definition: JParameter.hh:34
JOscParameters_t::JOscParameter_t JOscParameter_t
JOscParametersHelper< T > JOscParametersHelper_t
JOscParametersHelper(const JOscParameters_t &parameters, const std::string &name, argument_type value, const Args &...args)
Constructor.
JOscParametersHelper(const JOscParameters_t &parameters)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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
bool is_valid() const
Check validity of oscillation parameters.
JOscParametersHelper()
Default constructor.
JParameter_t::argument_type argument_type
void set(const std::string &name, argument_type value, const Args &...args) const
Set value for given list of oscillation parameters.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
virtual void set(const std::string &name, argument_type value) const
Set value for a given oscillation parameter.
Exception for null pointer operation.
Definition: JException.hh:232
Helper class for oscillation parameters.
then awk string
bool is_valid() const
Check validity of oscillation parameters.
virtual void configure(const JOscParameters_t &parameters)
Configure oscillation parameters.
void reset(T &value)
Reset value.
void set(const JOscParameters_t &parameters) const
Set oscillation parameters.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
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
JOscParameters_t::argument_type argument_type
Interface class for sets of oscillation parameters.
JOscParametersInterface< T > JOscParameters_t
std::shared_ptr< JOscParameters_t > pointer_type