Belle II Software development
ClosedRange< MinType, MaxType > Class Template Reference

Represents a closed set of arithmetic types. More...

#include <ClosedRange.h>

Public Member Functions

 ClosedRange (MinType min, MaxType max)
 Constructor.
 
template<class VariableType >
bool contains (const VariableType &x) const
 Method used by the filter tools to decide if accept a combination.
 
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.
 
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.
 
MinType getInf (void) const
 Accessor to the inf of the set (which is also the min)
 
MaxType getSup (void) const
 Accessor to the sup of the set (which is alsto the max)
 
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
 

Private Attributes

MinType m_min
 the minimum of this range
 
MaxType m_max
 the maximum of this range
 

Detailed Description

template<typename MinType, typename MaxType>
class Belle2::ClosedRange< MinType, MaxType >

Represents a closed set of arithmetic types.

Range is used in conjunction with the SelectionVariable to define one of the building blocks of the Filters

Definition at line 32 of file ClosedRange.h.

Constructor & Destructor Documentation

◆ ClosedRange() [1/2]

ClosedRange ( MinType  min,
MaxType  max 
)
inline

Constructor.

Definition at line 36 of file ClosedRange.h.

36: m_min(min), m_max(max) {};
MinType m_min
the minimum of this range
Definition: ClosedRange.h:116
MaxType m_max
the maximum of this range
Definition: ClosedRange.h:118

◆ ClosedRange() [2/2]

ClosedRange ( )
inline

Definition at line 37 of file ClosedRange.h.

37: m_min(0), m_max(0) {};

Member Function Documentation

◆ contains()

bool contains ( const VariableType &  x) const
inline

Method used by the filter tools to decide if accept a combination.

Parameters
xis the result of some SelectionVariable It returns true if x belongs to the closed set [ m_min, m_max ] It does not throw.

Definition at line 46 of file ClosedRange.h.

46{ return m_min <= x && x <= m_max ;};

◆ getInf()

MinType getInf ( void  ) const
inline

Accessor to the inf of the set (which is also the min)

Definition at line 84 of file ClosedRange.h.

84{ return m_min; } ;

◆ getNameAndReference()

std::string getNameAndReference ( std::vector< std::pair< char, void * > > *  pointers = nullptr,
const std::string &  varname = "X" 
)
inline

generates a "name" and fills the vector with the variable references

Parameters
varnamepointer to vector which contains a pair of char which indicates the type object pointed to and the actual pointers to the bounds, if equal to nullptr it will not be filled
pointersoptional name of the filter this range is attached to make the output look nicer

Definition at line 95 of file ClosedRange.h.

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 }
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.

◆ getSup()

MaxType getSup ( void  ) const
inline

Accessor to the sup of the set (which is alsto the max)

Definition at line 87 of file ClosedRange.h.

87{ return m_max; } ;

◆ persist()

void persist ( TTree *  t,
const std::string &  branchName,
const std::string &  variableName 
)
inline

Creates and sets the addresses of the leaves to store the min and max values.

Parameters
tthe pointer to the TTree that will contain the TBranch of this range.
branchNamethe name of the TBranch that will host this range.
variableNamethe name of the selection variable this range is applied to.

The leaves will be named as the selection variable name with the "_min"/"_max" suffixes for the min/max value.

Definition at line 57 of file ClosedRange.h.

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 }

◆ setBranchAddress()

void setBranchAddress ( TTree *  t,
const std::string &  branchName,
const std::string &   
)
inline

sets branch addresses of the given tree to the m_min and m_msx.

Note: it assumes a certain oder for

Parameters
tthe tree of the which the branch addresses need to be set
branchNamename of the branch

Definition at line 76 of file ClosedRange.h.

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 }

Member Data Documentation

◆ m_max

MaxType m_max
private

the maximum of this range

Definition at line 118 of file ClosedRange.h.

◆ m_min

MinType m_min
private

the minimum of this range

Definition at line 116 of file ClosedRange.h.


The documentation for this class was generated from the following file: