Belle II Software development
Range.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 <tracking/trackFindingVXD/filterMap/filterFramework/TBranchLeafType.h>
12#include <TBranch.h>
13#include <TTree.h>
14
15#include <framework/logging/Logger.h>
16
17namespace Belle2 {
28 template<typename InfType, typename SupType>
29 class Range {
31 const char* c_infSuffix = "_inf";
33 const char* c_supSuffix = "_sup";
34
36 InfType m_inf;
38 SupType m_sup;
39 public:
40
42 Range(InfType inf, SupType sup): m_inf(inf), m_sup(sup) {};
43
44 Range(): m_inf(0.), m_sup(0.) {};
50 template<class VariableType>
51 inline bool contains(const VariableType& x) const { return m_inf < x && x < m_sup ;};
52
62 void persist(TTree* t, const std::string& branchName, const std::string& variableName)
63 {
64
65 std::string leafList;
66 leafList += variableName;
67 leafList += c_infSuffix;
68 leafList += "/";
69 leafList += TBranchLeafType(m_inf);
70 leafList += ":";
71 leafList += variableName;
72 leafList += c_supSuffix;
73 leafList += "/";
74 leafList += TBranchLeafType(m_sup);
75 TBranch* branch = new TBranch(t, branchName.c_str(), & m_inf, leafList.c_str());
76 t->GetListOfBranches()->Add(branch);
77 }
78
83 void setBranchAddress(TTree* t, const std::string& branchName,
84 const std::string& /*variableName*/)
85 {
86 if (t->SetBranchAddress(branchName.c_str(), & m_inf) < 0) B2FATAL("Range: branch address not valid");
87 }
88
90 InfType getInf(void) const { return m_inf; } ;
91
93 SupType getSup(void) const { return m_sup; } ;
94
95
101 std::string getNameAndReference(std::vector<std::pair<char, void*>>* pointers = nullptr, const std::string& varname = "X")
102 {
103 std::string minVal = std::to_string(m_inf);
104 std::string maxVal = std::to_string(m_sup);
105 // if pointer to vector is provided fill it
106 if (pointers != nullptr) {
107 // use the position in the vector as unique identifier
108 minVal = "#" + std::to_string(pointers->size());
109 (*pointers).push_back({TBranchLeafType(m_inf), &m_inf});
110 maxVal = "#" + std::to_string(pointers->size());
111 (*pointers).push_back({TBranchLeafType(m_sup), &m_sup});
112 }
113 return ("(" + minVal + " < " + varname + " < " + maxVal + ")");
114 }
115 };
117}
Represents a range of arithmetic types.
Definition: Range.h:29
SupType m_sup
Supremum of the set.
Definition: Range.h:38
Range(InfType inf, SupType sup)
Constructor.
Definition: Range.h:42
SupType getSup(void) const
Accessor to the sup of the set.
Definition: Range.h:93
const char * c_supSuffix
Char suffix used to indicate the supremum of the set.
Definition: Range.h:33
const char * c_infSuffix
Char suffix used to indicate the infimum of the set.
Definition: Range.h:31
void persist(TTree *t, const std::string &branchName, const std::string &variableName)
Creates and sets the addresses of the leaves to store the inf and sup values.
Definition: Range.h:62
InfType m_inf
Infimum of the set.
Definition: Range.h:36
std::string getNameAndReference(std::vector< std::pair< char, void * > > *pointers=nullptr, const std::string &varname="X")
generates a "name" and fills the vector with the variable references
Definition: Range.h:101
bool contains(const VariableType &x) const
Method used by the filter tools to decide on the fate of the pair.
Definition: Range.h:51
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
Setting the branch address for a filter in a TTree.
Definition: Range.h:83
InfType getInf(void) const
Accessor to the inf of the set.
Definition: Range.h:90
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Abstract base class for different kinds of events.