Belle II Software development
ClosedRange.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
17#include <string>
18
19namespace Belle2 {
31 template< typename MinType, typename MaxType>
33 public:
34
36 ClosedRange(MinType min, MaxType max): m_min(min), m_max(max) {};
37 ClosedRange(): m_min(0), m_max(0) {};
38
45 template< class VariableType >
46 inline bool contains(const VariableType& x) const { return m_min <= x && x <= m_max ;};
47
57 void persist(TTree* t, const std::string& branchName, const std::string& variableName)
58 {
59
60 std::string leafList;
61 leafList += variableName;
62 leafList += "_min/";
63 leafList += TBranchLeafType(m_min);
64 leafList += ":";
65 leafList += variableName;
66 leafList += "_max/";
67 leafList += TBranchLeafType(m_max);
68 TBranch* branch = new TBranch(t, branchName.c_str(), & m_min, leafList.c_str());
69 t->GetListOfBranches()->Add(branch);
70 }
71
76 void setBranchAddress(TTree* t, const std::string& branchName,
77 const std::string& /*variableName*/)
78 {
79 // sets branch address and checks for validity
80 if (t->SetBranchAddress(branchName.c_str(), & m_min) < 0) B2FATAL("ClosedRange: branch address not valid");
81 }
82
84 MinType getInf(void) const { return m_min; } ;
85
87 MaxType getSup(void) const { return m_max; } ;
88
89
95 std::string getNameAndReference(std::vector< std::pair<char, void*> >* pointers = nullptr,
96 const std::string& varname = "X")
97 {
98 std::string minVal = std::to_string(m_min);
99 std::string maxVal = std::to_string(m_max);
100 // if pointer to vector is provided fill it
101 if (pointers != nullptr) {
102 // use the position in the vector as unique identifier
103 minVal = "#" + std::to_string(pointers->size());
104 (*pointers).push_back({TBranchLeafType(m_min), &m_min});
105 maxVal = "#" + std::to_string(pointers->size());
106 (*pointers).push_back({TBranchLeafType(m_max), &m_max});
107 }
108 return ("(" + minVal + " <= " + varname + " <= " + maxVal + ")");
109 }
110
111 private:
112
113 // NOTE: the persit function assumes that these data members (m_min, m_max) are in exactly that
114 // order defined! So DO NOT move these declarations!!!!
116 MinType m_min;
118 MaxType m_max;
119
120 };
121
122
124}
Represents a closed set of arithmetic types.
Definition: ClosedRange.h:32
MinType m_min
the minimum of this range
Definition: ClosedRange.h:116
MinType getInf(void) const
Accessor to the inf of the set (which is also the min)
Definition: ClosedRange.h:84
void persist(TTree *t, const std::string &branchName, const std::string &variableName)
Creates and sets the addresses of the leaves to store the min and max values.
Definition: ClosedRange.h:57
MaxType m_max
the maximum of this range
Definition: ClosedRange.h:118
ClosedRange(MinType min, MaxType max)
Constructor.
Definition: ClosedRange.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: ClosedRange.h:95
bool contains(const VariableType &x) const
Method used by the filter tools to decide if accept a combination.
Definition: ClosedRange.h:46
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
sets branch addresses of the given tree to the m_min and m_msx.
Definition: ClosedRange.h:76
MaxType getSup(void) const
Accessor to the sup of the set (which is alsto the max)
Definition: ClosedRange.h:87
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Abstract base class for different kinds of events.