Belle II Software development
Types.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 <variant>
12#include <string>
13#include <functional>
14#include <stdexcept>
15#include <map>
16#include <memory>
17
18namespace Belle2::VariablePersistenceManager {
19
20 enum VariableDataType {
21 c_double = 0,
22 c_int = 1,
23 c_bool = 2
24 };
25
30 class Variable {
31 public:
36 Variable(const std::string& variableName) : name{variableName} {}
37
42 virtual std::string getName() const { return name; }
43
47 virtual ~Variable() = default;
48
49 private:
50 std::string name;
51 };
52
57 class TypedVariable : public Variable {
58 public:
64 TypedVariable(const std::string& variableName, const VariableDataType& variableDataType)
65 : Variable(variableName)
66 , dataType{variableDataType}
67 {}
68
73 VariableDataType getDataType() const { return dataType; }
74
75 private:
76 VariableDataType dataType;
77 };
78
83 class BinnedVariable : public Variable {
84 public:
92 BinnedVariable(const std::string& variableName, int _nBins, float _lowBin, float _highBin)
93 : Variable(variableName)
94 , nBins{_nBins}
95 , lowBin{_lowBin}
96 , highBin{_highBin}
97 {}
98
103 int getNbins() const { return nBins; }
104
109 float getLowBin() const { return lowBin; }
110
115 float getHighBin() const { return highBin; }
116
117 private:
118 int nBins;
119 float lowBin;
120 float highBin;
121 };
122
127 typedef std::variant<double, int, bool> VariableType;
128
133 typedef std::vector<std::variant<TypedVariable, BinnedVariable>> Variables;
134
139 typedef std::map<std::string, VariableType> EvaluatedVariables;
140}
float lowBin
The lower bin boundary.
Definition Types.h:119
float highBin
The upper bin boundary.
Definition Types.h:120
float getHighBin() const
Retrieves the upper bin edge.
Definition Types.h:115
BinnedVariable(const std::string &variableName, int _nBins, float _lowBin, float _highBin)
Constructs a new BinnedVariable.
Definition Types.h:92
float getLowBin() const
Retrieves the lower bin edge.
Definition Types.h:109
int getNbins() const
Retrieves the number of bins.
Definition Types.h:103
TypedVariable(const std::string &variableName, const VariableDataType &variableDataType)
Constructs a new TypedVariable.
Definition Types.h:64
VariableDataType dataType
The data type of the variable.
Definition Types.h:76
VariableDataType getDataType() const
Retrieves the data type of this variable.
Definition Types.h:73
virtual std::string getName() const
Retrieves the name of the variable.
Definition Types.h:42
std::string name
The name of the variable.
Definition Types.h:50
Variable(const std::string &variableName)
Constructs a new Variable.
Definition Types.h:36
virtual ~Variable()=default
Virtual destructor.