PandaRoot
PndTCAInputContainer.h
Go to the documentation of this file.
1 
14 #ifndef PNDTCAINPUTCONTAINER_HH
15 #define PNDTCAINPUTCONTAINER_HH
16 
17 #include <stdexcept>
18 #include <vector>
19 
20 #include "TClonesArray.h"
21 #include "TString.h"
22 
23 #include "FairLogger.h"
24 #include "FairRootManager.h"
25 
26 #include "PndInputContainerI.h"
27 
35 template <class T>
37  public:
43 
48  virtual ~PndTCAInputContainer(){};
49 
55  virtual Bool_t Init(const TString &t_branchname) final
56  {
57  this->fBranchName = t_branchname;
58  FairRootManager *ioman = FairRootManager::Instance();
59  if (ioman == nullptr) {
60  throw std::runtime_error("FairRootManager::Instance() returned nullptr");
61  } else {
62  this->fTCA = dynamic_cast<TClonesArray *>(ioman->GetObject(t_branchname));
63  if (this->fTCA == nullptr) {
64  // throw std::runtime_error(
65  // ("PndTCAInputContainer<" + TString{T().ClassName()} + ">::Init(" + t_branchname + "): No " + TString{T().ClassName()} + " array with name " + t_branchname + " found!")
66  // .Data());
67  LOG(error) << "PndTCAInputContainer<" << T().ClassName() << ">::Init(" << t_branchname << "): No " << T().ClassName() << " array with name " << t_branchname << " found!";
68  return kFALSE;
69  }
70  }
71  return kTRUE;
72  }
73 
80  virtual T const *GetElement(Int_t t_idx) const final
81  {
82  if (fTCA != nullptr) {
83  return static_cast<T *>(fTCA->At(t_idx));
84  }
85  return nullptr;
86  }
87 
93  virtual ssize_t GetSize() const final
94  {
95  if (fTCA != nullptr) {
96  return fTCA->GetEntriesFast();
97  }
98  return 0;
99  }
100 
106  void SetTCA(TClonesArray *t_tca) { fTCA = t_tca; }
107 
113  TClonesArray *GetTCA() { return fTCA; }
114 
115  protected:
116  TClonesArray *fTCA{nullptr};
117 };
118 
119 #endif /*PNDTCAINPUTCONTAINER_HH*/
PndTCAInputContainer implementation of PndInputContainerI<T> for FairRootManager and TClonesArray...
virtual ssize_t GetSize() const final
Get the number of elements.
virtual T const * GetElement(Int_t t_idx) const final
Get pointer to the t_idx-th element.
PndTCAInputContainer()
Construct a new PndTCAInputContainer object.
TString fBranchName
Definition: PndContainerI.h:84
virtual ~PndTCAInputContainer()
Destroy the PndTCAInputContainer object.
virtual Bool_t Init(const TString &t_branchname) final
Fetch the data t_branchname in form of TClonesArray * from the FairRootManager.
TClonesArray * GetTCA()
Get the TClonesArray address.
void SetTCA(TClonesArray *t_tca)
Set the TClonesArray address.