Belle II Software  release-05-02-19
ParameterVariant.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/core/ModuleParam.h>
13 
14 #include <boost/variant/variant.hpp>
15 
16 #include <string>
17 #include <vector>
18 #include <map>
19 
20 namespace Belle2 {
25  class ModuleParamList;
26 
27  namespace TrackFindingCDC {
28 
30  using ParameterVariant =
31  boost::variant<bool, int, double, std::string, std::vector<double>, std::vector<std::string>>;
32 
34  using ParameterVariantMap = std::map<std::string, ParameterVariant>;
35 
37  struct AssignParameterVisitor : public boost::static_visitor<> {
38 
40  template <class ... T>
41  static void update(ModuleParamList* moduleParamList,
42  const std::map<std::string, boost::variant<T...> >& valuesByName)
43  {
44  for (auto& nameAndValue : valuesByName) {
45  const std::string& name = nameAndValue.first;
46  const boost::variant<T...>& value = nameAndValue.second;
47  AssignParameterVisitor visitor(moduleParamList, name);
48  boost::apply_visitor(visitor, value);
49  }
50  }
51 
53  AssignParameterVisitor(ModuleParamList* moduleParamList, const std::string& paramName);
54 
56  template <class T>
57  void operator()(const T& t) const;
58 
59  private:
62 
64  std::string m_paramName;
65  };
66 
67  }
68 
73 }
Belle2::TrackFindingCDC::AssignParameterVisitor::operator()
void operator()(const T &t) const
Function call that receives the parameter value from the boost::variant with the correct type.
Belle2::TrackFindingCDC::AssignParameterVisitor::m_moduleParamList
ModuleParamList * m_moduleParamList
Parameter list which contains the parameter to be set.
Definition: ParameterVariant.h:69
Belle2::TrackFindingCDC::AssignParameterVisitor
A helper class to unpack a boost::variant parameter value and set it in the parameter list.
Definition: ParameterVariant.h:45
Belle2::TrackFindingCDC::AssignParameterVisitor::AssignParameterVisitor
AssignParameterVisitor(ModuleParamList *moduleParamList, const std::string &paramName)
Constructor taking the module parameter list and the name of the parameter to be set from the boost::...
Definition: ParameterVariant.cc:20
Belle2::TrackFindingCDC::AssignParameterVisitor::update
static void update(ModuleParamList *moduleParamList, const std::map< std::string, boost::variant< T... > > &valuesByName)
Transfer all the parameters from the map boost:variant values to the module parmeter list.
Definition: ParameterVariant.h:49
Belle2::TrackFindingCDC::AssignParameterVisitor::m_paramName
std::string m_paramName
Name of the parameter to be set.
Definition: ParameterVariant.h:72
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::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46