Belle II Software light-2406-ragdoll
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>
57 {
58 return m_defaultValue;
59 }
60
61 template <class T>
62 void ModuleParam<T>::setValueFromPythonObject(const boost::python::object& pyObject)
63 {
64 setValue(PyObjConvUtils::convertPythonObject(pyObject, getDefaultValue()));
65 }
66
67 template <class T>
68 void ModuleParam<T>::setValueToPythonObject(boost::python::object& pyObject,
69 bool defaultValues) const
70 {
71 pyObject =
72 PyObjConvUtils::convertToPythonObject((defaultValues) ? m_defaultValue : m_paramVariable);
73 }
74
75 template <class T>
77 {
78 const ModuleParam<T>* p = dynamic_cast<const ModuleParam<T>*>(&param);
79 if (p) {
80 m_defaultValue = p->m_defaultValue;
81 m_paramVariable = p->m_paramVariable;
82 m_setInSteering = p->m_setInSteering;
83 }
84 }
85
86 template <class T>
88 {
89 m_paramVariable = m_defaultValue;
90 m_setInSteering = false;
91 }
92
94} // end of Belle2 namespace
Base class for module parameter.
A single parameter of the module.
Definition: ModuleParam.h:34
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.
static std::string TypeInfo()
Static function to generate a string description for the parameter type.
virtual ~ModuleParam()
Destructor.
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.
Definition: ClusterUtils.h:24
static std::string name()
type name.