Belle II Software  release-05-02-19
ModuleParam.templateDetails.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/ModuleParam.h>
14 #include <framework/core/PyObjConvUtils.h>
15 #include <boost/python/object.hpp>
16 #include <string>
17 
18 namespace Belle2 {
23  template <class T>
24  std::string ModuleParam<T>::TypeInfo()
25  {
27  }
28 
29  template <class T>
30  ModuleParam<T>::ModuleParam(T& paramVariable, const std::string& description, bool force):
31  ModuleParamBase(TypeInfo(), description, force), m_paramVariable(paramVariable) {};
32 
33  template <class T>
34  ModuleParam<T>::~ModuleParam() = default;
35 
36  template <class T>
37  void ModuleParam<T>::setValue(const T& value)
38  {
39  m_paramVariable = value;
40  m_setInSteering = true;
41  }
42 
43  template <class T>
44  void ModuleParam<T>::setDefaultValue(const T& defaultValue)
45  {
46  m_defaultValue = defaultValue;
47  m_paramVariable = defaultValue;
48  m_setInSteering = false;
49  }
50 
51  template <class T>
53  {
54  return m_paramVariable;
55  }
56 
57  template <class T>
59  {
60  return m_defaultValue;
61  }
62 
63  template <class T>
64  void ModuleParam<T>::setValueFromPythonObject(const boost::python::object& pyObject)
65  {
66  setValue(PyObjConvUtils::convertPythonObject(pyObject, getDefaultValue()));
67  }
68 
69  template <class T>
70  void ModuleParam<T>::setValueToPythonObject(boost::python::object& pyObject,
71  bool defaultValues) const
72  {
73  pyObject =
74  PyObjConvUtils::convertToPythonObject((defaultValues) ? m_defaultValue : m_paramVariable);
75  }
76 
77  template <class T>
79  {
80  const ModuleParam<T>* p = dynamic_cast<const ModuleParam<T>*>(&param);
81  if (p) {
82  m_defaultValue = p->m_defaultValue;
83  m_paramVariable = p->m_paramVariable;
84  m_setInSteering = p->m_setInSteering;
85  }
86  }
87 
88  template <class T>
90  {
91  m_paramVariable = m_defaultValue;
92  m_setInSteering = false;
93  }
94 
96 } // end of Belle2 namespace
Belle2::ModuleParam::ModuleParam
ModuleParam(T &paramVariable, const std::string &description="", bool force=false)
Constructor.
Definition: ModuleParam.templateDetails.h:38
Belle2::ModuleParam::TypeInfo
static std::string TypeInfo()
Static function to generate a string description for the parameter type.
Definition: ModuleParam.templateDetails.h:32
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ModuleParam
A single parameter of the module.
Definition: DisplayUI.h:34
Belle2::ModuleParamBase
Base class for module parameter.
Definition: ModuleParamBase.h:33
Belle2::PyObjConvUtils::Type::name
static std::string name()
type name.
Definition: PyObjConvUtils.h:156