HOPS
HOPS class reference
MHO_ParameterConfigurator.hh
Go to the documentation of this file.
1 #ifndef MHO_ParameterConfigurator_HH__
2 #define MHO_ParameterConfigurator_HH__
3 
4 #include <string>
5 #include <utility>
6 #include <vector>
7 
9 #include "MHO_Message.hh"
10 #include "MHO_ParameterStore.hh"
11 
12 namespace hops
13 {
14 
24 {
25 
26  public:
28  {
29  fFormat = control_format;
30  };
31 
33 
40  virtual void SetConditions(const mho_json& cond) { fConditions = cond; } //conditional statements
41 
48  virtual void SetAttributes(const mho_json& attr) { fAttributes = attr; }; //configuration parameters
49 
56  virtual bool Configure();
57 
58  protected:
60  enum class ParamType
61  {
62  config,
63  global,
64  station,
65  baseline,
66  fit,
67  plot,
68  unknown
69  };
70 
71  enum class ParamValueType
72  {
73  int_type, //single integer parameter
74  real_type, //single float parameter
75  bool_type, //single boolean parameter
76  string_type, //single string parameter
77  list_int_type, //list of ints with arbitrary length
78  list_real_type, //list of floats with arbitrary length
79  list_string_type, //list of strings with arbitrary length
80  compound_type, //multiple elements of different types
81  logical_intersection_list_string_type, //list of strings, if multiple lists are encountered take the logical intersection (e.g. freqs)
82  unknown
83  };
84 
85  typedef ParamType param_t;
87 
94  ParamType DetermineParamType(const std::string& par_type) const;
95 
102  ParamValueType DetermineParamValueType(const std::string& par_value_type) const;
103 
111  template< typename XValueType > void SetScalarParameter(std::string path, const XValueType& value);
112 
121  template< typename XValueType > void GetScalarParameter(std::string path, XValueType& value);
122 
131  template< typename XValueType > void SetVectorParameter(std::string path, const std::vector< XValueType >& values);
132 
141  template< typename XValueType > void GetVectorParameter(std::string path, std::vector< XValueType >& values);
142 
149  void SetCompoundParameter(std::string path, const mho_json& values);
150 
158  std::vector< std::string > LogicalIntersection(std::vector< std::string >& values1,
159  std::vector< std::string >& values2) const;
160 
162  mho_json fFormat; //format description for each parameter
163 
164  //provided for the configuration of the parameter that is to be set
167 };
168 
176 template< typename XValueType > void MHO_ParameterConfigurator::SetScalarParameter(std::string path, const XValueType& value)
177 {
178  bool ok = fParameterStore->Set(path, value);
179  if(!ok)
180  {
181  msg_warn("initialization", "could not set parameter: " << path << eom);
182  }
183 }
184 
192 template< typename XValueType > void MHO_ParameterConfigurator::GetScalarParameter(std::string path, XValueType& value)
193 {
194  bool ok = fParameterStore->Get(path, value);
195  if(!ok)
196  {
197  msg_info("initialization", "could not get parameter, using default value for: " << path << eom);
198  }
199 }
200 
208 template< typename XValueType >
209 void MHO_ParameterConfigurator::SetVectorParameter(std::string path, const std::vector< XValueType >& values)
210 {
211  bool ok = fParameterStore->Set(path, values);
212  if(!ok)
213  {
214  msg_warn("initialization", "could not set parameter vector: " << path << eom);
215  }
216 }
217 
225 template< typename XValueType >
226 void MHO_ParameterConfigurator::GetVectorParameter(std::string path, std::vector< XValueType >& values)
227 {
228  bool ok = fParameterStore->Get(path, values);
229  if(!ok)
230  {
231  msg_info("initialization", "could not get parameter vector, using default value for: " << path << eom);
232  }
233 }
234 
235 } // namespace hops
236 
237 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:248
#define msg_info(xKEY, xCONTENT)
Definition: MHO_Message.hh:268
some control statements simply trigger a parameter value to be set to a certain value,...
Definition: MHO_ParameterConfigurator.hh:24
void SetVectorParameter(std::string path, const std::vector< XValueType > &values)
Setter for vector parameter.
Definition: MHO_ParameterConfigurator.hh:209
ParamType param_t
Definition: MHO_ParameterConfigurator.hh:85
MHO_ParameterConfigurator(MHO_ParameterStore *pstore, mho_json control_format)
Definition: MHO_ParameterConfigurator.hh:27
void SetScalarParameter(std::string path, const XValueType &value)
Setter for scalar parameter.
Definition: MHO_ParameterConfigurator.hh:176
mho_json fFormat
Definition: MHO_ParameterConfigurator.hh:162
ParamValueType
Definition: MHO_ParameterConfigurator.hh:72
void GetVectorParameter(std::string path, std::vector< XValueType > &values)
Getter for vector parameter.
Definition: MHO_ParameterConfigurator.hh:226
void GetScalarParameter(std::string path, XValueType &value)
Getter for scalar parameter.
Definition: MHO_ParameterConfigurator.hh:192
ParamType
Definition: MHO_ParameterConfigurator.hh:61
virtual ~MHO_ParameterConfigurator()
Definition: MHO_ParameterConfigurator.hh:32
mho_json fConditions
Definition: MHO_ParameterConfigurator.hh:165
std::vector< std::string > LogicalIntersection(std::vector< std::string > &values1, std::vector< std::string > &values2) const
Calculates logical intersection of two sorted string vectors.
Definition: MHO_ParameterConfigurator.cc:265
ParamValueType DetermineParamValueType(const std::string &par_value_type) const
Determines the parameter value type from a given string representation.
Definition: MHO_ParameterConfigurator.cc:186
virtual bool Configure()
Configures parameter value by evaluating conditions and attributes.
Definition: MHO_ParameterConfigurator.cc:10
void SetCompoundParameter(std::string path, const mho_json &values)
Setter for compound parameter.
Definition: MHO_ParameterConfigurator.cc:256
mho_json fAttributes
Definition: MHO_ParameterConfigurator.hh:166
virtual void SetAttributes(const mho_json &attr)
Setter for (current) data attributes.
Definition: MHO_ParameterConfigurator.hh:48
ParamValueType paramv_t
Definition: MHO_ParameterConfigurator.hh:86
virtual void SetConditions(const mho_json &cond)
set conditions for this parameter (parsed from the control file)
Definition: MHO_ParameterConfigurator.hh:40
ParamType DetermineParamType(const std::string &par_type) const
Determines parameter type from string input.
Definition: MHO_ParameterConfigurator.cc:227
MHO_ParameterStore * fParameterStore
Definition: MHO_ParameterConfigurator.hh:161
Class MHO_ParameterStore.
Definition: MHO_ParameterStore.hh:52
bool Set(const std::string &value_path, const XValueType &value)
Setter for value at specified path in the parameter store.
Definition: MHO_ParameterStore.hh:210
bool Get(const std::string &value_path, XValueType &value) const
Retrieves a value by path and returns it as XValueType, using default constructor if not found.
Definition: MHO_ParameterStore.hh:255
Definition: MHO_AdhocFlagging.hh:18
par_type
Definition: MHO_AFileInfoExtractor.hh:29
Definition: vex.h:175