CbmRoot
CbmDigiBranch.h
Go to the documentation of this file.
1 
6 #include <vector>
7 
8 #include <FairLogger.h>
9 #include <FairRootManager.h>
10 #include <TClonesArray.h>
11 
12 #include "CbmDefs.h"
13 #include "CbmDigiBranchBase.h"
14 #include "CbmMatch.h"
15 
24 template<class Digi>
26 
27 public:
28  // -----------------------------------------------------------------------
32  CbmDigiBranch(const char* name = "unknown")
33  : CbmDigiBranchBase(name)
34  , fDigiVector(nullptr)
35  , fMatchVector(nullptr)
36  , fDigiArray(nullptr)
37  , fMatchArray(nullptr) {}
38  // -----------------------------------------------------------------------
39 
40 
41  // -----------------------------------------------------------------------
43  virtual ~CbmDigiBranch() {}
44  // -----------------------------------------------------------------------
45 
46 
47  // -----------------------------------------------------------------------
54  virtual Bool_t ConnectToTree() {
55 
56  FairRootManager* frm = FairRootManager::Instance();
57 
58  // Try to find a vector branch for the digi
59  fDigiVector = frm->InitObjectAs<std::vector<Digi> const*>(fName.Data());
60 
61  // Try to find a TClonesArray branch for the digi
62  if (!fDigiVector) {
63  fDigiArray = dynamic_cast<TClonesArray*>(frm->GetObject(fName));
64  }
65 
66  // Try to find a vector branch for the match
67  TString mBranch = fName + "Match";
68  fMatchVector =
69  frm->InitObjectAs<std::vector<CbmMatch> const*>(mBranch.Data());
70 
71  // Try to find a TClonesArray branch for the match
72  if (!fMatchVector) {
73  fMatchArray = dynamic_cast<TClonesArray*>(frm->GetObject(mBranch.Data()));
74  }
75 
76  if (fDigiVector || fDigiArray) return kTRUE;
77  return kFALSE;
78  }
79  // -----------------------------------------------------------------------
80 
81 
82  // -----------------------------------------------------------------------
86  virtual std::size_t GetNofDigis() const {
87  std::size_t nDigis = 0;
88  if (fDigiVector)
89  nDigis = fDigiVector->size();
90  else if (fDigiArray) {
91  assert(fDigiArray->GetEntriesFast() >= 0);
92  nDigis = fDigiArray->GetEntriesFast();
93  }
94  return nDigis;
95  }
96  // -----------------------------------------------------------------------
97 
98 
99  // -----------------------------------------------------------------------
106  virtual boost::any GetDigi(UInt_t index) {
107  const Digi* digi = nullptr;
108  if (index < GetNofDigis()) {
109  if (fDigiVector)
110  digi = &((*fDigiVector)[index]);
111  else if (fDigiArray)
112  digi = dynamic_cast<const Digi*>(fDigiArray->At(index));
113  }
114  return digi;
115  }
116  // -----------------------------------------------------------------------
117 
118 
119  // -----------------------------------------------------------------------
126  virtual const CbmMatch* GetDigiMatch(UInt_t index) {
127  const CbmMatch* match = nullptr;
128  if (index < GetNofDigis()) {
129  if (fMatchVector)
130  match = &((*fMatchVector)[index]);
131  else if (fMatchArray)
132  match = static_cast<const CbmMatch*>(fMatchArray->At(index));
133  }
134  return match;
135  }
136  // -----------------------------------------------------------------------
137 
138 
139  // -----------------------------------------------------------------------
143  virtual Bool_t HasMatches() {
144  if (fMatchVector || fMatchArray) return kTRUE;
145  return kFALSE;
146  }
147  // -----------------------------------------------------------------------
148 
149 
150  // -----------------------------------------------------------------------
152  virtual std::string ToString() const {
153  std::stringstream ss;
154  ss << "Branch " << fName << " (";
155  if (fDigiVector)
156  ss << "vector";
157  else if (fDigiArray)
158  ss << "TClonesArray";
159  else
160  ss << "not connected";
161  ss << "), match branch " << fName + "Match (";
162  if (fMatchVector)
163  ss << "vector";
164  else if (fMatchArray)
165  ss << "TClonesArray";
166  else
167  ss << "not connected";
168  ss << ")";
169  return ss.str();
170  }
171  // -----------------------------------------------------------------------
172 
173 
174 private:
175  const std::vector<Digi>* fDigiVector;
176  const std::vector<CbmMatch>* fMatchVector;
177  TClonesArray* fDigiArray;
178  TClonesArray* fMatchArray;
179 };
CbmDigiBranch::fMatchVector
const std::vector< CbmMatch > * fMatchVector
Vector of Digi objects.
Definition: CbmDigiBranch.h:176
CbmMatch
Definition: CbmMatch.h:22
CbmDigiBranch::fMatchArray
TClonesArray * fMatchArray
TClonesArray of Digi objects.
Definition: CbmDigiBranch.h:178
CbmDigiBranch::fDigiVector
const std::vector< Digi > * fDigiVector
Definition: CbmDigiBranch.h:175
CbmDigiBranch::~CbmDigiBranch
virtual ~CbmDigiBranch()
Destructor.
Definition: CbmDigiBranch.h:43
CbmDigiBranch::HasMatches
virtual Bool_t HasMatches()
Presence of match branch.
Definition: CbmDigiBranch.h:143
CbmMatch.h
CbmDigiBranch::CbmDigiBranch
CbmDigiBranch(const char *name="unknown")
Constructor.
Definition: CbmDigiBranch.h:32
CbmDigiBranch::ConnectToTree
virtual Bool_t ConnectToTree()
Connect the branch to the ROOT tree.
Definition: CbmDigiBranch.h:54
CbmDigiBranch::fDigiArray
TClonesArray * fDigiArray
Vector of match objects.
Definition: CbmDigiBranch.h:177
CbmDigiBranchBase.h
CbmDigiBranch::ToString
virtual std::string ToString() const
String output.
Definition: CbmDigiBranch.h:152
CbmDigiBranch::GetDigi
virtual boost::any GetDigi(UInt_t index)
Get digi object.
Definition: CbmDigiBranch.h:106
CbmDigiBranch
Class template for CBM digi branches.
Definition: CbmDigiBranch.h:25
CbmDigiBranchBase::fName
TString fName
Branch name.
Definition: CbmDigiBranchBase.h:79
CbmDigiBranch::GetNofDigis
virtual std::size_t GetNofDigis() const
Number of digis.
Definition: CbmDigiBranch.h:86
CbmDigiBranchBase
Abstract base class for CBM digi branches.
Definition: CbmDigiBranchBase.h:25
CbmDigiBranch::GetDigiMatch
virtual const CbmMatch * GetDigiMatch(UInt_t index)
Get match object.
Definition: CbmDigiBranch.h:126
CbmDefs.h