PandaTree
Element.h
1 #ifndef PandaTree_Framework_Element_h
2 #define PandaTree_Framework_Element_h
3 
4 #include "Object.h"
5 #include "IOUtils.h"
6 
7 #include <map>
8 
9 namespace panda {
10 
11  class ContainerBase;
12  class ArrayBase;
13  class CollectionBase;
14 
16 
32  class Element : public Object {
33  public:
45  struct datastore {
46  datastore() {}
47  virtual ~datastore() { deallocate(); }
48 
49  virtual void allocate(UInt_t n) { nmax_ = n; }
50  virtual void deallocate() {}
51  virtual void setStatus(TTree&, TString const&, utils::BranchList const&) {}
52  virtual utils::BranchList getStatus(TTree&, TString const&) const { return utils::BranchList(); }
53  virtual utils::BranchList getBranchNames(TString const& = "") const { return utils::BranchList(); }
54  virtual void setAddress(TTree&, TString const&, utils::BranchList const& = {"*"}, Bool_t setStatus = kTRUE) {}
55  virtual void book(TTree&, TString const&, utils::BranchList const& = {"*"}, Bool_t dynamic = kTRUE) {}
56  virtual void releaseTree(TTree&, TString const&) {}
57 
58  UInt_t nmax() const { return nmax_; }
59 
61 
64  virtual void resizeVectors_(UInt_t) {}
65 
66  protected:
67  UInt_t nmax_;
68  };
69 
70  typedef ArrayBase array_type;
72 
74  Element() = delete;
76  Element(datastore&, UInt_t) {}
78 
81  Element(Element const& src) : Object(src) {}
82  ~Element();
83  Element& operator=(Element const&) { return *this; }
84 
85  static char const* typeName() { return "Element"; }
86 
87  void setStatus(TTree&, utils::BranchList const& blist) final;
88  utils::BranchList getStatus(TTree&) const final;
89  utils::BranchList getBranchNames(Bool_t fullName = kTRUE, Bool_t = kFALSE) const final;
90  UInt_t setAddress(TTree&, utils::BranchList const& blist = {"*"}, Bool_t setStatus = kTRUE) final;
91  void book(TTree&, utils::BranchList const& blist = {"*"}) final;
92  Int_t getEntry(TTree& tree, Long64_t entry, Bool_t localEntry = kFALSE) final;
93  Int_t getEntry(UInt_t treeId, Long64_t entry, Bool_t localEntry = kFALSE) final;
94  void init() final { doInit_(); }
95  char const* getName() const final;
96  void setName(char const*) final;
97 
98  protected:
100 
105  Element(ArrayBase*);
106 
107  virtual void doBook_(TTree&, TString const&, utils::BranchList const&) = 0;
108  virtual void doInit_() = 0;
109 
111 
117  class StoreManager : public std::map<Element const*, ArrayBase*> {
118  public:
119  ArrayBase& getArray(Element const*) const;
120  template<class O> typename O::datastore& getData(O const*) const;
121  char const* getName(Element const*) const;
122  };
123 
124  static StoreManager gStore;
125  };
126 
127  template<class O>
128  typename O::datastore&
129  Element::StoreManager::getData(O const* _obj) const
130  {
131  return static_cast<typename O::datastore&>(getArray(_obj).getData());
132  }
133 }
134 
135 #endif
Base class for fixed-size containers.
Definition: ArrayBase.h:13
Base class for dynamic-size containers.
Definition: CollectionBase.h:16
Object base class.
Definition: Object.h:22
void setName(char const *) final
Set object name.
Definition: Element.cc:30
virtual void resizeVectors_(UInt_t)
Override when there are vector members.
Definition: Element.h:64
Element(datastore &, UInt_t)
Standard constructor.
Definition: Element.h:76
List of branch names.
Definition: IOUtils.h:64
Definition: Element.h:45
Element(Element const &src)
Copy constructor.
Definition: Element.h:81
Base class for elements of containers.
Definition: Element.h:32
void init() final
Reset the object state.
Definition: Element.h:94
Definition: Array.h:11
Int_t getEntry(TTree &tree, Long64_t entry, Bool_t localEntry=kFALSE) final
Read an entry from an input tree.
Definition: Element.cc:72
Singleton class for bookkeeping of Elements constructed as singlets.
Definition: Element.h:117
Element()=delete
Disabled default constructor.
char const * getName() const final
Name of this object.
Definition: Element.cc:19