Belle II Software development
ModuleParamList Class Reference

The Module parameter list class. More...

#include <ModuleParamList.h>

Public Member Functions

 ModuleParamList ()
 Constructor.
 
 ~ModuleParamList ()
 Destructor.
 
template<typename T >
void addParameter (const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
 Adds a new parameter to the module list.
 
template<typename T >
void addParameter (const std::string &name, T &paramVariable, const std::string &description)
 Adds a new enforced parameter to the module list.
 
template<typename T >
void setParameter (const std::string &name, const T &value)
 Sets the value 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.
 
std::string getParameterDescription (const std::string &name) const
 Returns the description of a parameter given by its name.
 
std::string getParameterTypeInfo (const std::string &name) const
 Returns the type info of a parameter given by its name.
 
template<typename T >
ModuleParam< T > & getParameter (const std::string &name) const
 Returns a reference to a parameter.
 
std::vector< std::string > getUnsetForcedParams () const
 Returns list of unset parameters (if they are required to have a value.
 
std::shared_ptr< boost::python::list > getParamInfoListPython () const
 Returns a python list of all parameters.
 
template<typename PythonObject >
void setParamPython (const std::string &name, const PythonObject &pyObj)
 Implements a method for setting boost::python objects.
 
template<typename PythonObject >
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.
 

Private Member Functions

ModuleParamPtr getParameterPtr (const std::string &name) const
 Returns a ModuleParamPtr to a parameter.
 

Static Private Member Functions

static void throwNotFoundError (const std::string &name)
 Throws an error for a requested parameter that does not exist.
 
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.
 

Private Attributes

std::map< std::string, ModuleParamPtrm_paramMap
 Stores the module parameters together with a string name as key.
 

Detailed Description

The Module parameter list class.

Stores and manages all parameters of a module.

Definition at line 44 of file ModuleParamList.h.

Constructor & Destructor Documentation

◆ ~ModuleParamList()

Destructor.

Definition at line 48 of file ModuleParamList.cc.

49{
50 m_paramMap.clear();
51}
std::map< std::string, ModuleParamPtr > m_paramMap
Stores the module parameters together with a string name as key.

Member Function Documentation

◆ getParameterDescription()

std::string getParameterDescription ( const std::string &  name) const

Returns the description of a parameter given by its name.

Throws an exception of type ModuleParameterNotFoundError if a parameter with the given name does not exist.

Parameters
nameThe unique name of the parameter.
Returns
The description of the parameter as string

Definition at line 105 of file ModuleParamList.cc.

106{
107 return getParameterPtr(name)->getDescription();
108}
ModuleParamPtr getParameterPtr(const std::string &name) const
Returns a ModuleParamPtr to a parameter.

◆ getParameterNames()

std::vector< std::string > getParameterNames ( ) const

Returns the names of all parameters in this parameter list.

Returns
The names of the parameters

Definition at line 95 of file ModuleParamList.cc.

96{
97 std::vector<std::string> names;
98 names.reserve(m_paramMap.size());
99 for (const auto& nameAndParam : m_paramMap) {
100 names.push_back(nameAndParam.first);
101 }
102 return names;
103}

◆ getParameterPtr()

ModuleParamPtr getParameterPtr ( const std::string &  name) const
private

Returns a ModuleParamPtr to a parameter.

Throws an exception of type ModuleParameterNotFoundError if a parameter with the given name does not exist.

Parameters
nameThe unique name of the parameter.
Returns
A ModuleParamPtr to a module parameter.

Definition at line 124 of file ModuleParamList.cc.

125{
126 //Check if a parameter with the given name exists
127 std::map<std::string, ModuleParamPtr>::const_iterator mapIter;
128 mapIter = m_paramMap.find(name);
129
130 if (mapIter != m_paramMap.end()) {
131 return mapIter->second;
132 } else throw (ModuleParameterNotFoundError() << name);
133}

◆ getParameterTypeInfo()

std::string getParameterTypeInfo ( const std::string &  name) const

Returns the type info of a parameter given by its name.

Throws an exception of type ModuleParameterNotFoundError if a parameter with the given name does not exist.

Parameters
nameThe unique name of the parameter.
Returns
The type information as descriptive string

Definition at line 110 of file ModuleParamList.cc.

111{
112 return getParameterPtr(name)->getTypeInfo();
113}

◆ getParamInfoListPython()

std::shared_ptr< boost::python::list > getParamInfoListPython ( ) const

Returns a python list of all parameters.

Each item in the list consists of the name of the parameter, a string describing its type, a python list of all values, a python list of all default values, the information of the parameter was set in the steering file and the description of the parameter.

Returns
A python list containing the parameters of this parameter list.

Definition at line 64 of file ModuleParamList.cc.

65{
66 std::shared_ptr<boost::python::list> returnList(new boost::python::list);
67 std::map<std::string, ModuleParamPtr>::const_iterator mapIter;
68
69 for (mapIter = m_paramMap.begin(); mapIter != m_paramMap.end(); ++mapIter) {
70 ModuleParamInfoPython newParamInfo;
71 ModuleParamPtr currParam = mapIter->second;
72
73 newParamInfo.m_name = mapIter->first;
74 newParamInfo.m_description = currParam->getDescription();
75 newParamInfo.m_typeName = currParam->getTypeInfo();
76 newParamInfo.m_setInSteering = currParam->isSetInSteering();
77 newParamInfo.m_forceInSteering = currParam->isForcedInSteering();
78 getParamValuesPython(mapIter->first, newParamInfo.m_defaultValues, true);
79 getParamValuesPython(mapIter->first, newParamInfo.m_values, false);
80
81 returnList->append(boost::python::object(newParamInfo));
82 }
83 return returnList;
84}
Class to store basic information about a parameter.
bool m_forceInSteering
If true the parameter has to be set by the user in the steering file.
bool m_setInSteering
True if the parameter was set in the steering file.
std::string m_description
The description of the parameter.
boost::python::list m_defaultValues
The default values of the parameter as a python list.
std::string m_name
The name of the parameter.
boost::python::list m_values
The values of the parameter as a python list.
std::string m_typeName
The name of the type of the parameter.
std::shared_ptr< ModuleParamBase > ModuleParamPtr
Defines a pointer to a module parameter as a boost shared pointer. *‍/.
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.

◆ getUnsetForcedParams()

std::vector< std::string > getUnsetForcedParams ( ) const

Returns list of unset parameters (if they are required to have a value.

Definition at line 54 of file ModuleParamList.cc.

55{
56 std::vector<std::string> missingParam;
57 for (const auto& mapEntry : m_paramMap) {
58 if (mapEntry.second->isForcedInSteering() && !mapEntry.second->isSetInSteering())
59 missingParam.push_back(mapEntry.first);
60 }
61 return missingParam;
62}

◆ setParameters()

void setParameters ( const ModuleParamList params)

Set values for parameters from other parameter list.

Definition at line 86 of file ModuleParamList.cc.

87{
88 for (const auto& param : params.m_paramMap) {
89 auto& myParam = m_paramMap.at(param.first);
90 myParam->setValueFromParam(*param.second.get());
91 }
92}

◆ throwNotFoundError()

void throwNotFoundError ( const std::string &  name)
staticprivate

Throws an error for a requested parameter that does not exist.

Parameters
nameThe name of the parameter.

Definition at line 33 of file ModuleParamList.cc.

34{
35 throw (ModuleParameterNotFoundError() << name);
36}

◆ throwTypeError()

void throwTypeError ( const std::string &  name,
const std::string &  expectedTypeInfo,
const std::string &  typeInfo 
)
staticprivate

Throws an error for a requested parameter that exists but was request with the wrong type.

Parameters
nameThe name of the parameter.
expectedTypeInfoType information which the parameter actually has.
typeInfoType information with which the parameter was looked up.

Definition at line 38 of file ModuleParamList.cc.

41{
42 throw (ModuleParameterTypeError() << name << expectedTypeInfo << typeInfo);
43}

Member Data Documentation

◆ m_paramMap

std::map<std::string, ModuleParamPtr> m_paramMap
private

Stores the module parameters together with a string name as key.

Definition at line 214 of file ModuleParamList.h.


The documentation for this class was generated from the following files: