Belle II Software development
ParameterVariant.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#pragma once
9
10#include <framework/core/ModuleParam.h>
11
12#include <boost/variant/variant.hpp>
13
14#include <string>
15#include <vector>
16#include <map>
17
18namespace Belle2 {
23 class ModuleParamList;
24
25 namespace TrackFindingCDC {
26
28 using ParameterVariant =
29 boost::variant<bool, int, double, std::string, std::vector<double>, std::vector<std::string>>;
30
32 using ParameterVariantMap = std::map<std::string, ParameterVariant>;
33
35 struct AssignParameterVisitor : public boost::static_visitor<> {
36
38 template <class ... T>
39 static void update(ModuleParamList* moduleParamList,
40 const std::map<std::string, boost::variant<T...> >& valuesByName)
41 {
42 for (auto& nameAndValue : valuesByName) {
43 const std::string& name = nameAndValue.first;
44 const boost::variant<T...>& value = nameAndValue.second;
45 AssignParameterVisitor visitor(moduleParamList, name);
46 boost::apply_visitor(visitor, value);
47 }
48 }
49
51 AssignParameterVisitor(ModuleParamList* moduleParamList, const std::string& paramName);
52
54 template <class T>
55 void operator()(const T& t) const;
56
57 private:
60
62 std::string m_paramName;
63 };
64
65 }
66
71}
The Module parameter list class.
A single parameter of the module.
Definition: ModuleParam.h:34
Abstract base class for different kinds of events.
A helper class to unpack a boost::variant parameter value and set it in the parameter list.
void operator()(const T &t) const
Function call that receives the parameter value from the boost::variant with the correct type.
ModuleParamList * m_moduleParamList
Parameter list which contains the parameter to be set.
std::string m_paramName
Name of the parameter to be set.
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 parameter list.