Belle II Software  release-05-02-19
LowerBoundedSet.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 {
31  template< typename InfType >
32  class LowerBoundedSet {
33  InfType m_inf;
34  public:
35 
37  explicit LowerBoundedSet(InfType inf): m_inf(inf) {};
38 
41 
47  template< class VariableType >
48  inline bool contains(const VariableType& x) const { return m_inf < x ;};
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 += "_inf/";
65  leafList += TBranchLeafType(m_inf);
66  TBranch* branch = new TBranch(t, branchName.c_str() , & m_inf, leafList.c_str());
67  t->GetListOfBranches()->Add(branch);
68  }
69 
74  void setBranchAddress(TTree* t, const std::string& branchName,
75  const std::string& /*variableName*/)
76  {
77  if (t->SetBranchAddress(branchName, & m_inf) < 0) B2FATAL("LowerBoundedSet: branch address not valid");
78  }
79 
81  InfType getInf(void) const { return m_inf; } ;
82 
88  std::string getNameAndReference(std::vector<std::pair<char, void*>>* pointers = nullptr, const std::string& varname = "X")
89  {
90  std::string minVal = std::to_string(m_inf);
91  // if pointer to vector is provided fill it
92  if (pointers != nullptr) {
93  // use the position in the vector as unique identifier
94  minVal = "#" + std::to_string(pointers->size());
95  (*pointers).push_back({TBranchLeafType(m_inf), &m_inf});
96  }
97  return ("(" + minVal + " < " + varname + ")");
98  }
99  };
101 }
Belle2::TBranchLeafType
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Definition: TBranchLeafType.h:29
Belle2::LowerBoundedSet::LowerBoundedSet
LowerBoundedSet()
Constructor without argument.
Definition: LowerBoundedSet.h:48
Belle2::LowerBoundedSet::persist
void persist(TTree *t, const std::string &branchName, const std::string &variableName)
Creates and sets the addresses of the leaves to store the inf value.
Definition: LowerBoundedSet.h:67
Belle2::LowerBoundedSet::m_inf
InfType m_inf
infinity value
Definition: LowerBoundedSet.h:41
Belle2::LowerBoundedSet::setBranchAddress
void setBranchAddress(TTree *t, const std::string &branchName, const std::string &)
Setting the branch address for a filter in a TTree.
Definition: LowerBoundedSet.h:82
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::LowerBoundedSet::contains
bool contains(const VariableType &x) const
Method used by the filter tools to decide on the fate of the pair.
Definition: LowerBoundedSet.h:56
Belle2::LowerBoundedSet::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: LowerBoundedSet.h:96
Belle2::LowerBoundedSet::getInf
InfType getInf(void) const
Accessor to the inf of the set.
Definition: LowerBoundedSet.h:89