Belle II Software development
ModuleParamList.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/ModuleParam.h>
12
13#include <map>
14#include <vector>
15#include <string>
16#include <memory>
17
18namespace boost {
19 namespace python {
20 class list;
21 namespace api {
22 class object;
23 }
24 using api::object;
25 }
26}
27
28namespace Belle2 {
33 //------------------------------------------------------
34 // Define convenient typdefs
35 //------------------------------------------------------
36
38 using ModuleParamPtr = std::shared_ptr<ModuleParamBase>;
39
45
46 private:
52 [[noreturn]] static void throwNotFoundError(const std::string& name);
53
61 [[noreturn]] static void throwTypeError(const std::string& name,
62 const std::string& expectedTypeInfo,
63 const std::string& typeInfo);
64 public:
69
74
87 template<typename T>
88 void addParameter(const std::string& name, T& paramVariable, const std::string& description, const T& defaultValue);
89
102 template<typename T>
103 void addParameter(const std::string& name, T& paramVariable, const std::string& description);
104
113 template<typename T>
114 void setParameter(const std::string& name, const T& value);
115
117 void setParameters(const ModuleParamList& params);
118
124 std::vector<std::string> getParameterNames() const;
125
134 std::string getParameterDescription(const std::string& name) const;
135
144 std::string getParameterTypeInfo(const std::string& name) const;
145
155 template<typename T>
156 ModuleParam<T>& getParameter(const std::string& name) const;
157
159 std::vector<std::string> getUnsetForcedParams() const;
160
161 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162 // Python API
163 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164
174 std::shared_ptr<boost::python::list> getParamInfoListPython() const;
175
186 template<typename PythonObject>
187 void setParamPython(const std::string& name, const PythonObject& pyObj);
188
198 template<typename PythonObject>
199 void getParamValuesPython(const std::string& name, PythonObject& pyOutput, bool defaultValues) const;
200
201 private:
210 ModuleParamPtr getParameterPtr(const std::string& name) const;
211
212 private:
214 std::map<std::string, ModuleParamPtr> m_paramMap;
215 };
216
217 // These frequent template instantiations are provided by the library and do not require including the details header
218 extern template void ModuleParamList::addParameter(const std::string&, bool&, const std::string&, const bool&);
219 extern template void ModuleParamList::addParameter(const std::string&, double&, const std::string&, const double&);
220 extern template void ModuleParamList::addParameter(const std::string&, float&, const std::string&, const float&);
221 extern template void ModuleParamList::addParameter(const std::string&, int&, const std::string&, const int&);
222 extern template void ModuleParamList::addParameter(const std::string&, std::string&, const std::string&, const std::string&);
223
225} //end of Belle2 namespace
The Module parameter list class.
std::shared_ptr< boost::python::list > getParamInfoListPython() const
Returns a python list of all parameters.
std::map< std::string, ModuleParamPtr > m_paramMap
Stores the module parameters together with a string name as key.
ModuleParamList()
Constructor.
std::string getParameterDescription(const std::string &name) const
Returns the description of a parameter given by its name.
std::vector< std::string > getUnsetForcedParams() const
Returns list of unset parameters (if they are required to have a value.
std::string getParameterTypeInfo(const std::string &name) const
Returns the type info of a parameter given by its name.
void setParameters(const ModuleParamList &params)
Set values for parameters from other parameter list.
std::vector< std::string > getParameterNames() const
Returns the names of all parameters in this parameter list.
static void throwTypeError(const std::string &name, const std::string &expectedTypeInfo, const std::string &typeInfo)
Throws an error for a requested parameter that exists but was request with the wrong type.
ModuleParamPtr getParameterPtr(const std::string &name) const
Returns a ModuleParamPtr to a parameter.
static void throwNotFoundError(const std::string &name)
Throws an error for a requested parameter that does not exist.
A single parameter of the module.
Definition: ModuleParam.h:34
ModuleParam< T > & getParameter(const std::string &name) const
Returns a reference to a parameter.
void setParameter(const std::string &name, const T &value)
Sets the value of a parameter given by its name.
std::shared_ptr< ModuleParamBase > ModuleParamPtr
Defines a pointer to a module parameter as a boost shared pointer. *‍/.
void setParamPython(const std::string &name, const PythonObject &pyObj)
Implements a method for setting boost::python objects.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
void getParamValuesPython(const std::string &name, PythonObject &pyOutput, bool defaultValues) const
Returns a python object containing the value or default value of the given parameter.
Abstract base class for different kinds of events.