Belle II Software development
UpperBoundedSet.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 SupType >
30
32 SupType m_sup;
33 public:
35 explicit UpperBoundedSet(SupType sup): m_sup(sup) {};
36
39
45 template< class VariableType >
46 inline bool contains(const VariableType& x) const { return x < m_sup;};
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 += "_sup/";
63 leafList += TBranchLeafType(m_sup);
64
65 TBranch* branch = new TBranch(t, branchName.c_str(), & m_sup, leafList.c_str());
66 t->GetListOfBranches()->Add(branch);
67 }
68
73 void setBranchAddress(TTree* t, const std::string& branchName,
74 const std::string& /*variableName*/)
75 {
76 if (t->SetBranchAddress(branchName, & m_sup) < 0) B2FATAL("UpperBoundedSet: branch address not valid!");
77 }
78
80 SupType getSup(void) const { return m_sup; } ;
81
82
88 std::string getNameAndReference(std::vector<std::pair<char, void*>>* pointers = nullptr, const std::string& varname = "X")
89 {
90 std::string maxVal = std::to_string(m_sup);
91 // if pointer to vector is provided fill it
92 if (pointers != nullptr) {
93 // use the position in the vector as unique identifier
94 maxVal = "#" + std::to_string(pointers->size());
95 (*pointers).push_back({TBranchLeafType(m_sup), &m_sup});
96 }
97 return ("(" + varname + " < " + maxVal + ")");
98 }
99 };
101}
Represents an upper bounded set of arithmetic types.
SupType m_sup
Supremum of the set.
UpperBoundedSet()
Constructor without argument.
SupType getSup(void) const
Accessor to the sup of the set.
void persist(TTree *t, const std::string &branchName, const std::string &variableName)
Creates and sets the addresses of the leaves to store sup value.
UpperBoundedSet(SupType sup)
Constructor.
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.
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
Setting the branch address for a filter in a TTree.
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Abstract base class for different kinds of events.