Belle II Software  release-05-01-25
UpperBoundedSet.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Eugenio Paoloni *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <tracking/trackFindingVXD/filterMap/filterFramework/TBranchLeafType.h>
14 #include <TBranch.h>
15 #include <TTree.h>
16 
17 #include <framework/logging/Logger.h>
18 
19 namespace Belle2 {
30  template< typename SupType >
31  class UpperBoundedSet {
32 
34  SupType m_sup;
35  public:
37  explicit UpperBoundedSet(SupType sup): m_sup(sup) {};
38 
40  UpperBoundedSet(): m_sup(0) {};
41 
47  template< class VariableType >
48  inline bool contains(const VariableType& x) const { return x < m_sup;};
49 
59  void persist(TTree* t, const std::string& branchName, const std::string& variableName)
60  {
61 
62  std::string leafList;
63  leafList += variableName;
64  leafList += "_sup/";
65  leafList += TBranchLeafType(m_sup);
66 
67  TBranch* branch = new TBranch(t, branchName.c_str() , & m_sup, leafList.c_str());
68  t->GetListOfBranches()->Add(branch);
69  }
70 
75  void setBranchAddress(TTree* t, const std::string& branchName,
76  const std::string& /*variableName*/)
77  {
78  if (t->SetBranchAddress(branchName, & m_sup) < 0) B2FATAL("UpperBoundedSet: branch address not valid!");
79  }
80 
82  SupType getSup(void) const { return m_sup; } ;
83 
84 
90  std::string getNameAndReference(std::vector<std::pair<char, void*>>* pointers = nullptr, const std::string& varname = "X")
91  {
92  std::string maxVal = std::to_string(m_sup);
93  // if pointer to vector is provided fill it
94  if (pointers != nullptr) {
95  // use the position in the vector as unique identifier
96  maxVal = "#" + std::to_string(pointers->size());
97  (*pointers).push_back({TBranchLeafType(m_sup), &m_sup});
98  }
99  return ("(" + varname + " < " + maxVal + ")");
100  }
101  };
103 }
Belle2::TBranchLeafType
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Definition: TBranchLeafType.h:29
Belle2::UpperBoundedSet::setBranchAddress
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
Setting the branch address for a filter in a TTree.
Definition: UpperBoundedSet.h:83
Belle2::UpperBoundedSet::getSup
SupType getSup(void) const
Accessor to the sup of the set.
Definition: UpperBoundedSet.h:90
Belle2::UpperBoundedSet::persist
void persist(TTree *t, const std::string &branchName, const std::string &variableName)
Creates and sets the addresses of the leaves to store sup value.
Definition: UpperBoundedSet.h:67
Belle2::UpperBoundedSet::getNameAndReference
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: UpperBoundedSet.h:98
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::UpperBoundedSet::m_sup
SupType m_sup
Supremum of the set.
Definition: UpperBoundedSet.h:42
Belle2::UpperBoundedSet::UpperBoundedSet
UpperBoundedSet()
Constructor without argument.
Definition: UpperBoundedSet.h:48
Belle2::UpperBoundedSet::contains
bool contains(const VariableType &x) const
Method used by the filter tools to decide on the fate of the pair.
Definition: UpperBoundedSet.h:56