Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
8#include "Jeep/JProperties.hh"
9
11
12
13/**
14 * \author bjung
15 */
16
17namespace JOSCPROB {}
18namespace JPP { using namespace JOSCPROB; }
19
20namespace JOSCPROB {
21
22 /**
23 * Helper class for oscillation parameters.
24 */
25 template<class T>
27 public std::unique_ptr<JOscParametersInterface<T> >
28 {
31
34
37
38 typedef std::unique_ptr<JOscParameters_t> pointer_type;
39
40
41 /**
42 * Default constructor.
43 */
47
48
49 /**
50 * Copy constructor.
51 *
52 * \param p pointer to oscillation parameters
53 */
55 {
56 this->configure(p);
57 }
58
59
60 /**
61 * Constructor.
62 *
63 * \param parameters oscillation parameters
64 */
66 {
67 this->configure(parameters);
68 }
69
70
71 /**
72 * Constructor.
73 *
74 * \param parameters oscillation parameters
75 * \param name parameter name
76 * \param value parameter value
77 * \param args remaining pairs of parameter names and values
78 */
79 template<class ...Args>
81 const std::string& name,
82 argument_type value,
83 const Args& ...args)
84 {
85 this->configure(parameters);
86 this->set(name, value, args...);
87 }
88
89
90 /**
91 * Configure oscillation parameters.
92 *
93 * \param p unique pointer to oscillation parameters
94 */
95 void configure(const pointer_type& p)
96 {
97 if (p) { this->reset(p->clone()); }
98 }
99
100
101 /**
102 * Configure oscillation parameters.
103 *
104 * \param parameters oscillation parameters
105 */
106 void configure(const JOscParameters_t& parameters)
107 {
108 using namespace std;
109 using namespace JPP;
110
111 JOscParameters_t* p = dynamic_cast<JOscParameters_t*>(parameters.clone());
112
113 if (p != NULL) {
114 this->reset(p);
115 } else {
116 THROW(JNullPointerException, "JOscParametersHelper::configure(): Unable to retrieve oscillation parameters interface.");
117 }
118 }
119
120
121 /**
122 * Get reference to oscillation parameters interface.
123 *
124 * \return reference to oscillation parameters interface
125 */
127 {
128 using namespace JPP;
129
130 if (static_cast<const JOscParametersHelper_t&>(*this)) {
131 return *(this->get());
132 } else {
133 THROW(JNullPointerException, "JOscParametersHelper::getParameters(): Oscillation parameters interface is not set.");
134 }
135 }
136
137
138 /**
139 * Get pointer to oscillation parameters interface.
140 *
141 * \return pointer to oscillation parameters interface
142 */
144 {
145 return pointer_type::get();
146 }
147
148
149 /**
150 * Get oscillation parameter.
151 *
152 * \param name parameter name
153 * \return parameter
154 */
155 JOscParameter_t& get(const std::string& name) const
156 {
157 return getParameters().get(name);
158 }
159
160
161
162 /**
163 * Set value for a given oscillation parameter.
164 *
165 * \param name parameter name
166 * \param value parameter value
167 */
168 void set(const std::string& name,
169 const value_type& value) const
170 {
171 getParameters().set(name, value);
172 }
173
174
175 /**
176 * Set value for given list of oscillation parameters.
177 *
178 * \param name parameter name
179 * \param value parameter value
180 * \param args remaining pairs of parameter names and values
181 */
182 template<class ...Args>
183 void set(const std::string& name,
184 const value_type& value,
185 const Args& ...args) const
186 {
187 this->set(name, value);
188 this->set(args...);
189 }
190
191
192 /**
193 * Set oscillation parameters.
194 *
195 * \param parameters oscillation parameters
196 */
197 void set(const JOscParametersInterface<value_type>& parameters) const
198 {
199 using namespace std;
200 using namespace JPP;
201
202 const JProperties properties = parameters.getProperties();
203
204 for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
205
206 const JOscParameter<value_type>& parameter = i->second.getValue<const JOscParameter<value_type> >();
207
208 this->set(i->first, parameter.getValue());
209 }
210 }
211
212
213 /**
214 * Get properties of this class.
215 *
216 * \param equation equation parameters
217 * \return properties of this class
218 */
223
224
225 /**
226 * Get properties of this class.
227 *
228 * \param equation equation parameters
229 * \return properties of this class
230 */
232 {
233 return getParameters().getProperties(equation);
234 }
235 };
236}
237
238#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Utility class to parse parameter values.
Utility class to parse parameter values.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Exception for null pointer operation.
Parameter class.
Definition JParameter.hh:36
const value_type getValue() const
Get value of parameter.
Definition JParameter.hh:82
Interface class for sets of oscillation parameters.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
const JOscParameter_t & get(const std::string &name) const
Get oscillation parameter.
static JEquationParameters & getEquationParameters()
Get equation parameters.
void set(const std::string &name, const value_type &value)
Set value for a given oscillation parameter.
JParameter_t::argument_type argument_type
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
virtual clone_type clone() const override
Get clone of this object.
Definition JClonable.hh:69
Abstract base class for oscillation parameter.
Helper class for oscillation parameters.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParameters_t::getEquationParameters()) const
Get properties of this class.
JOscParametersInterface< T > JOscParameters_t
void configure(const pointer_type &p)
Configure oscillation parameters.
JOscParametersHelper< T > JOscParametersHelper_t
std::unique_ptr< JOscParameters_t > pointer_type
JOscParameters_t * get() const
Get pointer to oscillation parameters interface.
JOscParametersHelper(const JOscParameters_t &parameters)
Constructor.
void configure(const JOscParameters_t &parameters)
Configure oscillation parameters.
JOscParameters_t::JParameter_t JParameter_t
JOscParametersHelper(const JOscParameters_t &parameters, const std::string &name, argument_type value, const Args &...args)
Constructor.
JOscParameters_t & getParameters() const
Get reference to oscillation parameters interface.
JOscParameters_t::argument_type argument_type
JOscParameters_t::JOscParameter_t JOscParameter_t
void set(const std::string &name, const value_type &value, const Args &...args) const
Set value for given list of oscillation parameters.
JOscParametersHelper(const pointer_type &p)
Copy constructor.
void set(const JOscParametersInterface< value_type > &parameters) const
Set oscillation parameters.
JOscParameter_t & get(const std::string &name) const
Get oscillation parameter.
JOscParametersHelper()
Default constructor.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParameters_t::getEquationParameters())
Get properties of this class.
void set(const std::string &name, const value_type &value) const
Set value for a given oscillation parameter.
JOscParameters_t::value_type value_type