Belle II Software development
ClosedUpperBoundedSet.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
13#include <framework/logging/Logger.h>
14
15#include <TBranch.h>
16#include <TTree.h>
17
18namespace Belle2 {
29 template< typename MaxType >
31
33 MaxType m_max;
34
35 public:
37 explicit ClosedUpperBoundedSet(MaxType max): m_max(max) {};
38
41
48 template< class VariableType >
49 inline bool contains(const VariableType& x) const { return x <= m_max;};
50
61 void persist(TTree* t, const std::string& branchName, const std::string& variableName)
62 {
63
64 std::string leafList;
65 leafList += variableName;
66 leafList += "_max/";
67 leafList += TBranchLeafType(m_max);
68
69 TBranch* branch = new TBranch(t, branchName.c_str(), & m_max, leafList.c_str());
70 t->GetListOfBranches()->Add(branch);
71 }
72
77 void setBranchAddress(TTree* t, const std::string& branchName,
78 const std::string& /*variableName*/)
79 {
80 if (t->SetBranchAddress(branchName.c_str(), & m_max) < 0) B2FATAL("ClosedUpperBoundedSet: branch address not valid!");
81 }
82
84 MaxType getSup(void) const { return m_max; } ;
85
86
92 std::string getNameAndReference(std::vector< std::pair<char, void*> >* pointers = nullptr,
93 const std::string& varname = "X")
94 {
95 std::string maxVal = std::to_string(m_max);
96 // if pointer to vector is provided fill it
97 if (pointers != nullptr) {
98 // use the position in the vector as unique identifier
99 maxVal = "#" + std::to_string(pointers->size());
100 (*pointers).push_back({TBranchLeafType(m_max), &m_max});
101 }
102 return ("(" + varname + " <= " + maxVal + ")");
103 }
104
105 };
106
108}
Represents an upper bounded set of arithmetic types.
ClosedUpperBoundedSet()
constructor without argument
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.
MaxType m_max
maximum of the set
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
bool contains(const VariableType &x) const
Method used by the filter tools to decide on the fate of the pair.
ClosedUpperBoundedSet(MaxType max)
constructor
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
Set the branch address of the specified leafes to the data members.
MaxType getSup(void) const
Accessor to the sup of the set (which is also the max)
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Abstract base class for different kinds of events.