CbmRoot
CbmDigiVector.h
Go to the documentation of this file.
1 
7 #ifndef CBMDIGIVECTOR_H
8 #define CBMDIGIVECTOR_H 1
9 
10 
11 #include <FairLogger.h>
12 #include <vector>
13 
14 #include "CbmDigiContainer.h"
15 #include "CbmMatch.h"
16 
22 template<class Digi>
24 
25 public:
29  CbmDigiVector(Bool_t hasMatches = kFALSE) : fHasMatches(hasMatches) {
30  TString name = Digi::GetClassName();
31  name += "_vector";
32  SetName(name.Data());
33  }
34 
35 
37  virtual ~CbmDigiVector() {}
38 
39 
47  virtual void AddDigi(boost::any digi, const CbmMatch* match = nullptr) {
48  if (fIsLocked) {
49  LOG(fatal) << GetName() << "::AddDigi: Vector is locked.";
50  return;
51  }
52  const Digi* thisDigi = boost::any_cast<const Digi*>(digi);
53  if (!thisDigi) {
54  LOG(fatal) << GetName() << "::AddDigi: Wrong argument type"
55  << " (should be " << Digi::GetClassName() << "*) !";
56  return;
57  } //? Any_cast successful
58  fDigis.push_back(*thisDigi);
59  if (fHasMatches) {
60  if (match == nullptr) {
61  LOG(fatal) << GetName() << "::AddDigi: Valid match object required!";
62  return;
63  }
64  fMatches.push_back(*match);
65  } //? Has matches
66  }
67 
68 
73  virtual Bool_t ConnectToTree() {
74  LOG(fatal) << "Digi vector cannot be connected to a TTree!";
75  return false;
76  }
77 
78 
85  virtual boost::any GetDigi(UInt_t index) {
86  fIsLocked = kTRUE;
87  const Digi* result = nullptr;
88  if (index < fDigis.size()) result = &(fDigis[index]);
89  return boost::any(result);
90  }
91 
92 
100  virtual const CbmMatch* GetDigiMatch(UInt_t index) {
101  fIsLocked = kTRUE;
102  const CbmMatch* result = nullptr;
103  if (fHasMatches && index < fMatches.size()) result = &(fMatches[index]);
104  return result;
105  }
106 
107 
111  virtual Bool_t HasMatches() const { return fHasMatches; }
112 
113 
117  virtual ULong64_t GetNofDigis() const {
118  if (fHasMatches) assert(fMatches.size() == fDigis.size());
119  return static_cast<ULong64_t>(fDigis.size());
120  }
121 
122 
126  virtual std::string ToString() const {
127  std::stringstream ss;
128  ss << GetName() << ", size " << fDigis.size();
129  if (HasMatches()) ss << ", matches present";
130  return ss.str();
131  }
132 
133 
134 private:
135  std::vector<Digi> fDigis {};
136  std::vector<CbmMatch> fMatches {};
137  Bool_t fHasMatches = kFALSE;
138  Bool_t fIsLocked = kFALSE;
139 
140 
142 };
143 
144 #endif /* CBMDIGIVECTOR_H */
CbmMatch
Definition: CbmMatch.h:22
CbmDigiContainer
Abstract container for digis in CBM.
Definition: CbmDigiContainer.h:30
CbmDigiVector::fIsLocked
Bool_t fIsLocked
Definition: CbmDigiVector.h:138
CbmDigiVector
std::vector implementation of CbmDigiContainer
Definition: CbmDigiVector.h:23
CbmDigiVector::GetDigi
virtual boost::any GetDigi(UInt_t index)
Get digi object.
Definition: CbmDigiVector.h:85
CbmMatch.h
CbmDigiVector::fDigis
std::vector< Digi > fDigis
Definition: CbmDigiVector.h:135
CbmDigiVector::~CbmDigiVector
virtual ~CbmDigiVector()
Destructor.
Definition: CbmDigiVector.h:37
CbmDigiVector::fMatches
std::vector< CbmMatch > fMatches
Definition: CbmDigiVector.h:136
CbmDigiVector::GetNofDigis
virtual ULong64_t GetNofDigis() const
Number of digis in the vector.
Definition: CbmDigiVector.h:117
CbmDigiVector::AddDigi
virtual void AddDigi(boost::any digi, const CbmMatch *match=nullptr)
Add a digi (and match) to the vector.
Definition: CbmDigiVector.h:47
CbmDigiVector::CbmDigiVector
CbmDigiVector(Bool_t hasMatches=kFALSE)
Constructor.
Definition: CbmDigiVector.h:29
CbmDigiContainer.h
CbmDigiVector::GetDigiMatch
virtual const CbmMatch * GetDigiMatch(UInt_t index)
Get digi match object.
Definition: CbmDigiVector.h:100
CbmDigiVector::ClassDef
ClassDef(CbmDigiVector, 1)
CbmDigiVector::fHasMatches
Bool_t fHasMatches
Definition: CbmDigiVector.h:137
CbmDigiVector::ConnectToTree
virtual Bool_t ConnectToTree()
Connect to a ROOT TTree.
Definition: CbmDigiVector.h:73
CbmDigiContainer::GetName
virtual const char * GetName() const
Name of container.
Definition: CbmDigiContainer.h:79
CbmDigiVector::ToString
virtual std::string ToString() const
String output.
Definition: CbmDigiVector.h:126
CbmDigiVector::HasMatches
virtual Bool_t HasMatches() const
Presence of match objects.
Definition: CbmDigiVector.h:111