PandaRoot
PndOutputContainer.h
Go to the documentation of this file.
1 
14 #ifndef PNDOUTPUTCONTAINER_HH
15 #define PNDOUTPUTCONTAINER_HH
16 
17 #include <vector>
18 
19 #include "PndContainerI.h"
20 #include "PndSTDOutputContainer.h"
21 #include "PndTCAOutputContainer.h"
22 
23 template <class T>
25 
26  public:
33  PndOutputContainer(const TString &t_foldername = "", Bool_t t_persistency = kTRUE) : PndOutputContainerI<T>(t_foldername, t_persistency) {}
34 
39  virtual ~PndOutputContainer(){};
40 
46  virtual Bool_t Init(const TString &t_branchname)
47  {
48  this->fBranchName = t_branchname;
49  Bool_t success = TryTCA(t_branchname);
50  if (!success) {
51  success = TrySTD(t_branchname);
52  }
53  return success;
54  }
55 
62  Bool_t TrySTD(const TString &t_branchname)
63  {
64  this->fImp.reset(new PndSTDOutputContainer<T>{this->fFolderName, this->fPersistency});
65  Bool_t success = this->fImp->Init(t_branchname);
66  if (!success) {
67  LOG(debug) << "No std::vector<T> branch called " << t_branchname << " registered with the FairRootManager.";
68  this->fImp.reset(nullptr);
69  } else {
70  LOG(debug) << "Found std::vector<T> branch called " << t_branchname << " registered with the FairRootManager. ";
71  }
72  return success;
73  }
74 
81  Bool_t TryTCA(const TString &t_branchname)
82  {
83  this->fImp.reset(new PndTCAOutputContainer<T>{this->fFolderName, this->fPersistency});
84  Bool_t success = this->fImp->Init(t_branchname);
85  if (!success) {
86  LOG(debug) << "No TClonesArray branch called " << t_branchname << " registered with the FairRootManager either. !";
87  this->fImp.reset(nullptr);
88  // abort();
89  } else {
90  LOG(debug) << "Found TClonesArray branch called " << t_branchname << " registered with the FairRootManager. ";
91  }
92  return success;
93  }
94 
101  virtual void Reset() final
102  {
103  if (this->fImp != nullptr) {
104  this->fImp->Reset();
105  }
106  }
107 
114  virtual T *CreateCopy(const T &t_data) final
115  {
116  if (this->fImp != nullptr) {
117  return this->fImp->CreateCopy(t_data);
118  }
119  return nullptr;
120  }
121 
127  virtual void RemoveAt(Int_t t_index) final
128  {
129  if (this->fImp != nullptr) {
130  this->fImp->RemoveAt(t_index);
131  }
132  }
133 
139  virtual ssize_t GetSize() const final
140  {
141  if (this->fImp != nullptr) {
142  return this->fImp->GetSize();
143  }
144  return 0;
145  }
146 
153  virtual T *GetElement(Int_t t_index) const final
154  {
155  if (this->fImp != nullptr) {
156  return this->fImp->GetElement(t_index);
157  }
158  return nullptr;
159  }
160 
165  virtual void Compress()
166  {
167  if (this->fImp != nullptr) {
168  this->fImp->Compress();
169  }
170  }
171 
172  protected:
173  std::unique_ptr<PndOutputContainerI<T>> fImp{nullptr};
174 };
175 
176 #endif /*PNDOUTPUTCONTAINER_HH*/
virtual Bool_t Init(const TString &t_branchname)
Init internal data.
virtual T * CreateCopy(const T &t_data) final
Create a copy of t_data in internal data and return ptr to it.
virtual ssize_t GetSize() const final
Get the number of members in internal data.
virtual T * GetElement(Int_t t_index) const final
Get the Element object at t_index.
TString fBranchName
Definition: PndContainerI.h:84
Bool_t TrySTD(const TString &t_branchname)
Create a std::vector based outputcontainer and register/init it with the FairRootManager.
virtual void RemoveAt(Int_t t_index) final
Delete object at t_index in internal data.
PndOutputContainer(const TString &t_foldername="", Bool_t t_persistency=kTRUE)
Construct a new PndOutputContainer object.
Bool_t TryTCA(const TString &t_branchname)
Create a TClonesArray based outputcontainer and register/init it with the FairRootManager.
Input and Output Container implementation of PndOutputContainerI using an underlying std::vector<T> (...
virtual ~PndOutputContainer()
Destroy the PndOutputContainer object.
std::unique_ptr< PndOutputContainerI< T > > fImp
PndTCAOutputContainer implementation of PndOutputContainerI<T> for FairRootManager and TClonesArray...
virtual void Reset() final
Reset data.
Interface to a datacontainer to be used in PandaROOT.
virtual void Compress()
Compress.
Input and Output Container implementation of PndOutputContainerI using an underlying TClonesArray...
PndSTDOutputContainer implementation of PndOutputContainerI<T> for FairRootManager and std::vector<T>...