PandaRoot
PndTCAMutableContainer.h
Go to the documentation of this file.
1 
15 #ifndef PNDTCAMUTABLECONTAINER_HH
16 #define PNDTCAMUTABLECONTAINER_HH
17 
18 #include <stdexcept>
19 #include <vector>
20 
21 #include "TClonesArray.h"
22 #include "TString.h"
23 
24 #include "FairLogger.h"
25 #include "FairRootManager.h"
26 
27 #include "PndMutableContainerI.h"
28 
37 template <class T>
39  public:
46  PndTCAMutableContainer(const TString &t_foldername = "", Bool_t t_persistency = kTRUE) : PndMutableContainerI<T>(t_foldername, t_persistency) {}
47 
53 
58  virtual void Reset() final
59  {
60  if (this->fTCA != nullptr) {
61  this->fTCA->Delete();
62  }
63  }
70  virtual T *CreateCopy(const T &t_element)
71  {
72  if (fTCA != nullptr) {
73  new ((*fTCA)[fTCA->GetEntriesFast()]) T{t_element};
74  } else {
75  LOG(error) << "PndTCAMutableContainer::CreateCopy() no underlying TClonesArray";
76  return nullptr;
77  }
78  return GetElement(GetSize() - 1);
79  }
80 
86  virtual void RemoveAt(Int_t t_index)
87  {
88  if (this->fTCA != nullptr) {
89  this->fTCA->RemoveAt(t_index);
90  }
91  }
92 
97  virtual void Compress()
98  {
99  if (this->fTCA != nullptr) {
100  this->fTCA->Compress();
101  }
102  }
103 
110  virtual T *GetElement(Int_t t_idx) const final
111  {
112  if (fTCA != nullptr) {
113  return static_cast<T *>(fTCA->At(t_idx));
114  }
115  return nullptr;
116  }
117 
123  virtual ssize_t GetSize() const final
124  {
125  if (fTCA != nullptr) {
126  return fTCA->GetEntriesFast();
127  }
128  return 0;
129  }
130 
136  void SetTCA(TClonesArray *t_tca) { fTCA = t_tca; }
137 
143  TClonesArray *GetTCA() { return fTCA; }
144 
145  protected:
146  TClonesArray *fTCA{nullptr};
147 };
148 
149 #endif /*PNDTCAMUTABLECONTAINER_HH*/
virtual ~PndTCAMutableContainer()
Destroy the PndTCAOutput Container object.
void SetTCA(TClonesArray *t_tca)
Set the TClonesArray address.
TClonesArray * GetTCA()
Get the TClonesArray address.
virtual void Reset() final
Delete all elements.
virtual ssize_t GetSize() const final
Get the number of elements.
virtual T * GetElement(Int_t t_idx) const final
Get pointer to the t_idx-th element.
PndTCAMutableContainer implementation of PndMutableContainerI<T> for FairRootManager and TClonesArray...
PndTCAMutableContainer(const TString &t_foldername="", Bool_t t_persistency=kTRUE)
Construct a new PndTCAMutableContainer object.
virtual T * CreateCopy(const T &t_element)
Create a copy of t_element in the TClonesArray and return a pointer to it.
virtual void Compress()
Compress.
virtual void RemoveAt(Int_t t_index)
remove the t_index-th element