Belle II Software light-2607-kasei
ModuleParam.templateDetails.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#include <framework/core/PyObjConvUtils.h>
13#include <boost/python/object.hpp>
14#include <string>
15
16namespace Belle2 {
21 template <class T>
23 {
25 }
26
27 template <class T>
28 ModuleParam<T>::ModuleParam(T& paramVariable, const std::string& description, bool force):
29 ModuleParamBase(TypeInfo(), description, force), m_paramVariable(paramVariable) {};
30
31 template <class T>
33
34 template <class T>
35 void ModuleParam<T>::setValue(const T& value)
36 {
37 m_paramVariable = value;
38 m_setInSteering = true;
39 }
40
41 template <class T>
42 void ModuleParam<T>::setDefaultValue(const T& defaultValue)
43 {
44 m_defaultValue = defaultValue;
45 m_paramVariable = defaultValue;
46 m_setInSteering = false;
47 }
48
49 template <class T>
51 {
52 return m_paramVariable;
53 }
54
55 template <class T>
60
61 template <class T>
62 void ModuleParam<T>::setValueFromPythonObject(const boost::python::object& pyObject)
63 {
64 // For T = std::string the boost::python::extract inside convertPythonObject
65 // triggers a false-positive -Wmaybe-uninitialized in GCC; silence it here.
66#if defined(__GNUC__) && !defined(__clang__)
67#pragma GCC diagnostic push
68#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
69#endif
71#if defined(__GNUC__) && !defined(__clang__)
72#pragma GCC diagnostic pop
73#endif
74 }
75
76 template <class T>
77 void ModuleParam<T>::setValueToPythonObject(boost::python::object& pyObject,
78 bool defaultValues) const
79 {
80 pyObject =
82 }
83
84 template <class T>
86 {
87 const ModuleParam<T>* p = dynamic_cast<const ModuleParam<T>*>(&param);
88 if (p) {
89 m_defaultValue = p->m_defaultValue;
90 m_paramVariable = p->m_paramVariable;
91 m_setInSteering = p->m_setInSteering;
92 }
93 }
94
95 template <class T>
101
103} // end of Belle2 namespace
ModuleParamBase(std::string typeInfo, std::string description, bool force)
Constructor.
bool m_setInSteering
True, if the parameter value was changed in the steering file.
T & m_paramVariable
Reference to the member variable in the module which stores the parameter value.
T m_defaultValue
The default value of the parameter.
virtual void setValueFromPythonObject(const boost::python::object &pyObject) final
Implements a method for setting boost::python objects.
ModuleParam(T &paramVariable, const std::string &description="", bool force=false)
Constructor.
virtual void setValueToPythonObject(boost::python::object &pyObject, bool defaultValues=false) const final
Returns a python object containing the value or the default value of the given parameter.
void resetValue()
Resets the parameter value by assigning the default value to the parameter value.
T & getDefaultValue()
Returns the default value of the parameter.
virtual ~ModuleParam() override
Destructor.
static std::string TypeInfo()
Static function to generate a string description for the parameter type.
T & getValue()
Returns the value of the parameter.
void setDefaultValue(const T &defaultValue)
Sets the default value of a parameter.
void setValue(const T &value)
Sets the value of a parameter.
virtual void setValueFromParam(const ModuleParamBase &param) final
Set value from other ModuleParam of same type.
boost::python::object convertToPythonObject(const Scalar &value)
------------— From C++ TO Python Converter ---------------------—
Scalar convertPythonObject(const boost::python::object &pyObject, Scalar)
Convert from Python to given type.
Abstract base class for different kinds of events.
static std::string name()
type name.