Jpp  19.0.0
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>
25  public std::shared_ptr<JOscParametersInterface<T> >
26  {
29 
32 
35 
36  typedef std::shared_ptr<JOscParameters_t> pointer_type;
37 
38  using pointer_type::reset;
39 
40 
41  /**
42  * Default constructor.
43  */
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param parameters oscillation parameters
52  */
54  {
55  this->configure(parameters);
56  }
57 
58 
59  /**
60  * Constructor.
61  *
62  * \param parameters oscillation parameters
63  * \param name parameter name
64  * \param value parameter value
65  * \param args remaining pairs of parameter names and values
66  */
67  template<class ...Args>
69  const std::string& name,
70  argument_type value,
71  const Args& ...args)
72  {
73  this->configure(parameters);
74  this->set(name, value, args...);
75  }
76 
77 
78  /**
79  * Configure oscillation parameters.
80  *
81  * \param parameters oscillation parameters
82  */
83  virtual void configure(const JOscParameters_t& parameters)
84  {
85  using namespace std;
86  using namespace JPP;
87 
88  JOscParameters_t* p = dynamic_cast<JOscParameters_t*>(parameters.clone());
89 
90  if (p != NULL) {
91  reset(p);
92  } else {
93  THROW(JNullPointerException, "JOscParametersHelper::configure(): Unable to retrieve oscillation parameters interface.");
94  }
95  }
96 
97 
98  /**
99  * Get reference to oscillation parameters interface.
100  *
101  * \return reference to oscillation parameters interface
102  */
104  {
105  using namespace JPP;
106 
107  if (static_cast<const JOscParametersHelper_t&>(*this)) {
108  return *(this->get());
109  } else {
110  THROW(JNullPointerException, "JOscParametersHelper::getParameters(): Oscillation parameters interface is not set.");
111  }
112  }
113 
114 
115  /**
116  * Set value for a given oscillation parameter.
117  *
118  * \param name parameter name
119  * \param value parameter value
120  */
121  virtual void set(const std::string& name,
122  const value_type& value) const
123  {
124  getParameters().set(name, value);
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 value_type& value,
138  const Args& ...args) const
139  {
140  this->set(name, value);
141  this->set(args...);
142  }
143 
144 
145  /**
146  * Set oscillation parameters.
147  *
148  * \param parameters oscillation parameters
149  */
151  {
152  using namespace std;
153  using namespace JPP;
154 
155  const JProperties properties = parameters.getProperties();
156 
157  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
158  const JOscParameter<value_type>& parameter = i->second.getValue<const JOscParameter<value_type> >();
159 
160  this->set(i->first, parameter.getValue());
161  }
162  }
163 
164 
165  /**
166  * Check validity of oscillation parameters.
167  *
168  * \return true if all oscillation parameters are valid; else false
169  */
170  bool is_valid() const
171  {
172  return getParameters().is_valid();
173  }
174  };
175 }
176 
177 #endif
void set(const std::string &name, const value_type &value, const Args &...args) const
Set value for given list of oscillation parameters.
Abstract base class for oscillation parameter.
void set(const JOscParametersInterface< value_type > &parameters) const
Set oscillation parameters.
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.
virtual void set(const std::string &name, const value_type &value) const
Set value for a given oscillation parameter.
JOscParametersHelper(const JOscParameters_t &parameters)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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, const value_type &value)
Set value for a given oscillation parameter.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
Exception for null pointer operation.
Definition: JException.hh:232
Helper class for oscillation parameters.
bool is_valid() const
Check validity of oscillation parameters.
virtual void configure(const JOscParameters_t &parameters)
Configure oscillation parameters.
then fatal The output file must have the wildcard in the name
Definition: JCanberra.sh:31
void reset(T &value)
Reset value.
JOscParameters_t::value_type value_type
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
JOscParameters_t::argument_type argument_type
Interface class for sets of oscillation parameters.
JOscParametersInterface< T > JOscParameters_t
const value_type getValue() const
Get value of parameter.
Definition: JParameter.hh:82
std::shared_ptr< JOscParameters_t > pointer_type