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