PandaRoot
PndInputContainer.h
Go to the documentation of this file.
1 
14 #ifndef PNDINPUTCONTAINER_HH
15 #define PNDINPUTCONTAINER_HH
16 
17 #include <vector>
18 
19 #include "PndContainerI.h"
20 #include "PndSTDInputContainer.h"
21 #include "PndTCAInputContainer.h"
22 
23 template <class T>
25 
26  public:
34 
39  virtual ~PndInputContainer(){};
40 
46  virtual Bool_t Init(const TString &t_branchname)
47  {
48  this->fBranchName = t_branchname;
49  this->fImp.reset(nullptr);
50 
51  Bool_t success = TryTCA(t_branchname);
52  if (!success) {
53  success = TrySTD(t_branchname);
54  }
55  if (!success) {
56  this->fImp.reset(nullptr);
57  // throw std::runtime_error(
58  // ("PndInputContainer<" + TString{T().ClassName()} + ">::Init(" + t_branchname + "): No " + TString{T().ClassName()} + " array with name " + t_branchname +
59  // "found!").Data());
60  LOG(error) << "PndInputContainer<" << T().ClassName() << ">::Init(" << t_branchname << "): No " << T().ClassName() << " array with name " << t_branchname << " found!";
61  }
62  return success;
63  }
64 
71  Bool_t TryTCA(const TString &t_branchname)
72  {
73  this->fImp.reset(new PndTCAInputContainer<T>{});
74  Bool_t success = this->fImp->Init(t_branchname);
75  if (!success) {
76  LOG(debug) << "No TClonesArray branch called " << t_branchname << " registered with the FairRootManager. ";
77  this->fImp.reset(nullptr);
78  } else {
79  LOG(debug) << "Found input TClonesArray branch called " << t_branchname << " registered with the FairRootManager.";
80  }
81  return success;
82  }
83 
90  Bool_t TrySTD(const TString &t_branchname)
91  {
92  if (FairRootManager::Instance()->CheckBranch(t_branchname) ==
93  0) { // This test is required here, as you get a segmentation violation if you try to access a not existing branch t_branchname via std
94  return kFALSE;
95  }
96  this->fImp.reset(new PndSTDInputContainer<T>{});
97  Bool_t success = this->fImp->Init(t_branchname);
98  if (!success) {
99  LOG(debug) << "No std::vector<T> branch called " << t_branchname << " registered with the FairRootManager.";
100  this->fImp.reset(nullptr);
101  } else {
102  LOG(debug) << "Found std::vector<T> TClonesArray branch called " << t_branchname << " registered with the FairRootManager.";
103  }
104  return success;
105  }
106 
112  virtual ssize_t GetSize() const final
113  {
114  if (this->fImp != nullptr) {
115  return this->fImp->GetSize();
116  }
117  return 0;
118  }
119 
126  virtual T const *GetElement(Int_t t_index) const final
127  {
128  if (this->fImp != nullptr) {
129  return this->fImp->GetElement(t_index);
130  }
131  return nullptr;
132  }
133 
134  protected:
135  std::unique_ptr<PndInputContainerI<T>> fImp{nullptr};
136 };
137 
138 #endif /*PNDINPUTCONTAINER_HH*/
PndTCAInputContainer implementation of PndInputContainerI<T> for FairRootManager and TClonesArray...
Bool_t TrySTD(const TString &t_branchname)
Tries to find a registered const std::vector<T>* with name t_branchname. Returns kTRUE on success...
TString fBranchName
Definition: PndContainerI.h:84
virtual Bool_t Init(const TString &t_branchname)
Init internal data.
PndSTDInputContainer implementation of PndInputContainerI<T> for FairRootManager and std::vector<T> ...
Bool_t TryTCA(const TString &t_branchname)
Tries to find a registered TClonesArray with name t_branchname. Returns kTRUE on success.
Input and Output Container implementation of PndInputContainerI using an underlying TClonesArray...
virtual ssize_t GetSize() const final
Get the number of members in internal data.
virtual T const * GetElement(Int_t t_index) const final
Get the Element object at t_index.
Interface to a datacontainer to be used in PandaROOT.
std::unique_ptr< PndInputContainerI< T > > fImp
virtual ~PndInputContainer()
Destroy the PndInputContainer object.
Input and Output Container implementation of PndInputContainerI using an underlying std::vector<T> (c...
PndInputContainer()
Construct a new PndInputContainer object.