PandaTree
CollectionBase.h
1 #ifndef PandaTree_Framework_CollectionBase_h
2 #define PandaTree_Framework_CollectionBase_h
3 
4 #include "ContainerBase.h"
5 
6 #include <vector>
7 #include <utility>
8 
9 namespace panda {
10 
12 
16  class CollectionBase : public ContainerBase {
17  public:
18  CollectionBase() = delete;
19  CollectionBase(CollectionBase const& src) = delete;
20  ~CollectionBase();
21 
22  void setStatus(TTree&, utils::BranchList const& blist) final;
23  utils::BranchList getStatus(TTree&) const final;
24  utils::BranchList getBranchNames(Bool_t fullName = kTRUE, Bool_t = kFALSE) const final;
25  UInt_t setAddress(TTree&, utils::BranchList const& blist = {"*"}, Bool_t setStatus = kTRUE) final;
26  void book(TTree&, utils::BranchList const& blist = {"*"}) final;
28  Int_t getEntry(UInt_t, Long64_t entry, Bool_t localEntry = kFALSE) final;
29  Int_t fill(TTree&) final;
30  void init() final { clear(); }
31  void print(std::ostream& = std::cout, UInt_t level = 1) const override;
32  void dump(std::ostream& = std::cout) const override;
33  void unlink(TTree&) final;
34  UInt_t size() const final { return size_; }
35 
36  Bool_t empty() const { return size_ == 0; }
37 
39 
45  void resize(UInt_t size);
46 
48 
53  void reserve(UInt_t size);
54 
56  void clear() { size_ = 0; getData().resizeVectors_(0); }
57 
59  void prepareFill(TTree&);
60 
61  protected:
62  CollectionBase(char const* name, UInt_t unitSize, Bool_t dummy) : ContainerBase(name, unitSize) {}
63 
64  virtual void reallocate_(UInt_t) = 0;
65 
66  private:
67  void doSetAddress_(TTree&, utils::BranchList const&, Bool_t setStatus, Bool_t asInput);
68 
70  UInt_t size_{0};
71 
73 
78  UInt_t sizeIn_{0};
79 
81  std::vector<Bool_t> inputInSynch_{};
82 
84 
88  std::vector<std::pair<TTree*, Bool_t>> outputs_{};
89  };
90 
91 }
92 
93 #endif
void prepareFill(TTree &)
Check for address change before fill.
Definition: CollectionBase.cc:230
void unlink(TTree &) final
Unlink from a tree.
Definition: CollectionBase.cc:179
Base class for dynamic-size containers.
Definition: CollectionBase.h:16
Int_t getEntry(TTree &tree, Long64_t entry, Bool_t localEntry=kFALSE) final
Read an entry from an input tree.
Definition: ReaderObject.cc:21
void reserve(UInt_t size)
Pre-allocate space for the container.
Definition: CollectionBase.cc:217
void book(TTree &, utils::BranchList const &blist={"*"}) final
Book new branches bound to this object on the tree.
Definition: CollectionBase.cc:85
virtual void resizeVectors_(UInt_t)
Override when there are vector members.
Definition: Element.h:64
List of branch names.
Definition: IOUtils.h:64
utils::BranchList getBranchNames(Bool_t fullName=kTRUE, Bool_t=kFALSE) const final
Get the full list of branch names.
Definition: CollectionBase.cc:50
Int_t getEntry(UInt_t, Long64_t entry, Bool_t localEntry=kFALSE) final
Read an entry from an input tree.
Definition: CollectionBase.cc:107
void init() final
Reset the object state.
Definition: CollectionBase.h:30
utils::BranchList getStatus(TTree &) const final
Get status of branches in the tree.
Definition: CollectionBase.cc:35
void dump(std::ostream &=std::cout) const override
Dump the object content.
Definition: CollectionBase.cc:171
Base class for all containers.
Definition: ContainerBase.h:18
Int_t fill(TTree &) final
Fill a tree.
Definition: CollectionBase.cc:156
void print(std::ostream &=std::cout, UInt_t level=1) const override
Print the object content.
Definition: CollectionBase.cc:164
void setStatus(TTree &, utils::BranchList const &blist) final
Set status of branches to true (matching branch) or false (vetoed branch)
Definition: CollectionBase.cc:18
void clear()
Clear the container (set size = 0)
Definition: CollectionBase.h:56
Definition: Array.h:11
void resize(UInt_t size)
Resize the container.
Definition: CollectionBase.cc:192
UInt_t setAddress(TTree &, utils::BranchList const &blist={"*"}, Bool_t setStatus=kTRUE) final
Bind the tree branches to the elements of this object.
Definition: CollectionBase.cc:71