Belle II Software  release-05-02-19
SingleElementSet.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 namespace Belle2 {
28  template<typename Type>
29  class SingleElementSet {
31  Type m_element;
32  public:
34  explicit SingleElementSet(Type element): m_element(element) {};
35 
41  template< class VariableType >
42  inline bool contains(const VariableType& x) const { return x == m_element;};
43 
53  void persist(TTree* t, const std::string& branchName, const std::string& variableName)
54  {
55 
56  std::string leafList;
57  leafList += variableName;
58  leafList += "_sup/";
59  leafList += TBranchLeafType(m_element);
60 
61  TBranch* branch = new TBranch(t, branchName.c_str() , & m_element, leafList.c_str());
62  t->GetListOfBranches()->Add(branch);
63  }
64 
66  Type getElement(void) const { return m_element; } ;
67 
73  std::string getNameAndReference(std::vector<std::pair<char, void*>>* pointers = nullptr, const std::string& varname = "x")
74  {
75  std::string val = std::to_string(m_element);
76  // if pointer to vector is provided fill it
77  if (pointers != nullptr) {
78  // use the position in the vector as unique identifier
79  val = "#" + std::to_string(pointers->size());
80  (*pointers).push_back({TBranchLeafType(m_element), &m_element});
81  }
82  return ("(" + val + " == " + varname + ")");
83  }
84  };
86 }
Belle2::TBranchLeafType
char TBranchLeafType(const char *)
Overloading TBranchLeafType to be able to get identifier 'C' for type char*.
Definition: TBranchLeafType.h:29
Belle2::SingleElementSet::contains
bool contains(const VariableType &x) const
Method used by the filter tools to decide on the fate of the pair.
Definition: SingleElementSet.h:50
Belle2::SingleElementSet::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: SingleElementSet.h:61
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SingleElementSet::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: SingleElementSet.h:81
Belle2::SingleElementSet::getElement
Type getElement(void) const
Accessor to the sup of the set.
Definition: SingleElementSet.h:74
Belle2::SingleElementSet::m_element
Type m_element
Member variable for the single element of the set.
Definition: SingleElementSet.h:39
Belle2::SingleElementSet::SingleElementSet
SingleElementSet(Type element)
Constructor.
Definition: SingleElementSet.h:42