PandaRoot
PndSTDInputContainer.h
Go to the documentation of this file.
1 
18 #ifndef PNDSTDINPUTCONTAINER_HH
19 #define PNDSTDINPUTCONTAINER_HH
20 
21 #include <stdexcept>
22 #include <vector>
23 
24 #include "TString.h"
25 
26 #include "FairLogger.h"
27 #include "FairRootManager.h"
28 
29 #include "PndInputContainerI.h"
30 
38 template <class T>
40  public:
50  virtual ~PndSTDInputContainer(){};
51 
57  virtual Bool_t Init(const TString &t_branchname) final
58  {
59  this->fBranchName = t_branchname;
60  FairRootManager *ioman = FairRootManager::Instance();
61  if (ioman == nullptr) {
62  throw std::runtime_error("FairRootManager::Instance() returned nullptr");
63  } else {
64  this->fSTD = ioman->InitObjectAs<std::vector<T> const *>(t_branchname);
65  if (this->fSTD == nullptr) {
66  // throw std::runtime_error(
67  // ("PndSTDInputContainer<" + TString{T().ClassName()} + ">::Init(" + t_branchname + "): No " + TString{T().ClassName()} + " array with name " + t_branchname + " found!")
68  // .Data());
69  LOG(error) << "PndSTDInputContainer<" << T().ClassName() << ">::Init(" << t_branchname << "): No " << T().ClassName() << " array with name " << t_branchname << " found!";
70  return kFALSE;
71  }
72  }
73  LOG(INFO) << "virtual Bool_t PndSTDInputContainer::Init(const TString &t_branchname) final successful";
74  return kTRUE;
75  }
76 
83  virtual T const *GetElement(Int_t t_idx) const final
84  {
85  if (fSTD != nullptr) {
86  return &(fSTD->at(t_idx));
87  }
88 
89  return nullptr;
90  }
91 
97  virtual ssize_t GetSize() const final
98  {
99  if (fSTD != nullptr) {
100  return fSTD->size();
101  }
102  return 0;
103  }
109  void SetData(std::vector<T> const *t_container) { fSTD = t_container; }
110 
116  std::vector<T> const *GetData() { return fSTD; }
117 
118  private:
119  std::vector<T> const *fSTD{nullptr};
120 };
121 
122 #endif /*PNDSTDINPUTCONTAINER_HH*/
TString fBranchName
Definition: PndContainerI.h:84
std::vector< T > const * GetData()
Get the Data.
virtual T const * GetElement(Int_t t_idx) const final
Get the t_idx Element.
PndSTDInputContainer implementation of PndInputContainerI<T> for FairRootManager and std::vector<T> ...
virtual ~PndSTDInputContainer()
Destroy the PndSTDInputContainer object.
virtual Bool_t Init(const TString &t_branchname) final
Retrieve t_branchname as std::vector<T> const * from FairRootManager.
void SetData(std::vector< T > const *t_container)
Set the Data.
virtual ssize_t GetSize() const final
Get the number of elements.
PndSTDInputContainer()
Construct a new PndSTDInputContainer object.