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 
133 
134 
143  template< typename XValueType > void GetVectorParameter(std::string path, std::vector< XValueType >& values);
144 
151  void SetCompoundParameter(std::string path, const mho_json& values);
152 
160  std::vector< std::string > LogicalIntersection(std::vector< std::string >& values1, std::vector< std::string>& values2) const;
161 
163  mho_json fFormat; //format description for each parameter
164 
165  //provided for the configuration of the parameter that is to be set
168 };
169 
177 template< typename XValueType > void MHO_ParameterConfigurator::SetScalarParameter(std::string path, const XValueType& value)
178 {
179  bool ok = fParameterStore->Set(path, value);
180  if(!ok)
181  {
182  msg_warn("initialization", "could not set parameter: " << path << eom);
183  }
184 }
185 
193 template< typename XValueType > void MHO_ParameterConfigurator::GetScalarParameter(std::string path, XValueType& value)
194 {
195  bool ok = fParameterStore->Get(path, value);
196  if(!ok)
197  {
198  msg_info("initialization", "could not get parameter, using default value for: " << path << eom);
199  }
200 }
201 
209 template< typename XValueType >
210 void MHO_ParameterConfigurator::SetVectorParameter(std::string path, const std::vector< XValueType >& values)
211 {
212  bool ok = fParameterStore->Set(path, values);
213  if(!ok)
214  {
215  msg_warn("initialization", "could not set parameter vector: " << path << eom);
216  }
217 }
218 
226 template< typename XValueType >
227 void MHO_ParameterConfigurator::GetVectorParameter(std::string path, std::vector< XValueType >& values)
228 {
229  bool ok = fParameterStore->Get(path, values);
230  if(!ok)
231  {
232  msg_info("initialization", "could not get parameter vector, using default value for: " << path << eom);
233  }
234 }
235 
236 } // namespace hops
237 
238 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:254
#define msg_info(xKEY, xCONTENT)
Definition: MHO_Message.hh:274
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:210
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:177
mho_json fFormat
Definition: MHO_ParameterConfigurator.hh:163
ParamValueType
Definition: MHO_ParameterConfigurator.hh:72
void GetVectorParameter(std::string path, std::vector< XValueType > &values)
Getter for vector parameter.
Definition: MHO_ParameterConfigurator.hh:227
void GetScalarParameter(std::string path, XValueType &value)
Getter for scalar parameter.
Definition: MHO_ParameterConfigurator.hh:193
ParamType
Definition: MHO_ParameterConfigurator.hh:61
virtual ~MHO_ParameterConfigurator()
Definition: MHO_ParameterConfigurator.hh:32
mho_json fConditions
Definition: MHO_ParameterConfigurator.hh:166
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:249
ParamValueType DetermineParamValueType(const std::string &par_value_type) const
Determines the parameter value type from a given string representation.
Definition: MHO_ParameterConfigurator.cc:169
virtual bool Configure()
Configures parameter value by evaluating conditions and attributes.
Definition: MHO_ParameterConfigurator.cc:9
void SetCompoundParameter(std::string path, const mho_json &values)
Setter for compound parameter.
Definition: MHO_ParameterConfigurator.cc:239
mho_json fAttributes
Definition: MHO_ParameterConfigurator.hh:167
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:210
MHO_ParameterStore * fParameterStore
Definition: MHO_ParameterConfigurator.hh:162
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:193
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:238
Definition: MHO_ChannelLabeler.hh:17
par_type
Definition: MHO_AFileInfoExtractor.hh:29
Definition: vex.h:175