CbmRoot
Loading...
Searching...
No Matches
CbmDigiBranch.h
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
10#include "CbmDefs.h"
11#include "CbmDigiBranchBase.h"
12#include "CbmMatch.h"
13
14#include <FairRootManager.h>
15#include <Logger.h>
16
17#include <TClonesArray.h>
18
19#include <vector>
20
29template<class Digi>
31
32public:
33 // -----------------------------------------------------------------------
37 CbmDigiBranch(const char* name = "unknown")
38 : CbmDigiBranchBase(name)
39 , fDigiVector(nullptr)
40 , fMatchVector(nullptr)
41 , fDigiArray(nullptr)
42 , fMatchArray(nullptr)
43 {
44 }
45 // -----------------------------------------------------------------------
46
47
48 // -----------------------------------------------------------------------
50 virtual ~CbmDigiBranch() {}
51 // -----------------------------------------------------------------------
52
53
54 // -----------------------------------------------------------------------
61 virtual bool ConnectToTree()
62 {
63
64 FairRootManager* frm = FairRootManager::Instance();
65
66 // Try to find a vector branch for the digi
67 fDigiVector = frm->InitObjectAs<std::vector<Digi> const*>(fName.Data());
68
69 // Try to find a TClonesArray branch for the digi
70 if (!fDigiVector) { fDigiArray = dynamic_cast<TClonesArray*>(frm->GetObject(fName)); }
71
72 // Try to find a vector branch for the match
73 TString mBranch = fName + "Match";
74 fMatchVector = frm->InitObjectAs<std::vector<CbmMatch> const*>(mBranch.Data());
75
76 // Try to find a TClonesArray branch for the match
77 if (!fMatchVector) { fMatchArray = dynamic_cast<TClonesArray*>(frm->GetObject(mBranch.Data())); }
78
79 if (fDigiVector || fDigiArray) return true;
80 return false;
81 }
82 // -----------------------------------------------------------------------
83
84
85 // -----------------------------------------------------------------------
89 virtual std::size_t GetNofDigis() const
90 {
91 std::size_t nDigis = 0;
92 if (fDigiVector) nDigis = fDigiVector->size();
93 else if (fDigiArray) {
94 assert(fDigiArray->GetEntriesFast() >= 0);
95 nDigis = fDigiArray->GetEntriesFast();
96 }
97 return nDigis;
98 }
99 // -----------------------------------------------------------------------
100
101
102 // -----------------------------------------------------------------------
109 virtual boost::any GetDigi(uint32_t index)
110 {
111 const Digi* digi = nullptr;
112 if (index < GetNofDigis()) {
113 if (fDigiVector) digi = &((*fDigiVector)[index]);
114 else if (fDigiArray)
115 digi = dynamic_cast<const Digi*>(fDigiArray->At(index));
116 }
117 return digi;
118 }
119 // -----------------------------------------------------------------------
120
121
122 // -----------------------------------------------------------------------
129 virtual const CbmMatch* GetDigiMatch(uint32_t index)
130 {
131 const CbmMatch* match = nullptr;
132 if (index < GetNofDigis()) {
133 if (fMatchVector) match = &((*fMatchVector)[index]);
134 else if (fMatchArray)
135 match = static_cast<const CbmMatch*>(fMatchArray->At(index));
136 }
137 return match;
138 }
139 // -----------------------------------------------------------------------
140
141
142 // -----------------------------------------------------------------------
146 virtual bool HasMatches()
147 {
148 if (fMatchVector || fMatchArray) return true;
149 return false;
150 }
151 // -----------------------------------------------------------------------
152
153
154 // -----------------------------------------------------------------------
156 virtual std::string ToString() const
157 {
158 std::stringstream ss;
159 ss << "Branch " << fName << " (";
160 if (fDigiVector) ss << "vector";
161 else if (fDigiArray)
162 ss << "TClonesArray";
163 else
164 ss << "not connected";
165 ss << "), match branch " << fName + "Match (";
166 if (fMatchVector) ss << "vector";
167 else if (fMatchArray)
168 ss << "TClonesArray";
169 else
170 ss << "not connected";
171 ss << ")";
172 return ss.str();
173 }
174 // -----------------------------------------------------------------------
175
176 // -----------------------------------------------------------------------
183 virtual boost::any GetBranchContainer() const
184 {
185 if (fDigiVector) return fDigiVector;
186 else if (fDigiArray)
187 return fDigiArray;
188 return nullptr;
189 }
190 // -----------------------------------------------------------------------
191
192
193private:
194 const std::vector<Digi>* fDigiVector;
195 const std::vector<CbmMatch>* fMatchVector;
196 TClonesArray* fDigiArray;
197 TClonesArray* fMatchArray;
198};
Abstract base class for CBM digi branches.
TString fName
Branch name.
Class template for CBM digi branches.
virtual std::size_t GetNofDigis() const
Number of digis.
virtual boost::any GetDigi(uint32_t index)
Get digi object.
virtual bool ConnectToTree()
Connect the branch to the ROOT tree.
virtual ~CbmDigiBranch()
Destructor.
virtual std::string ToString() const
String output.
CbmDigiBranch(const char *name="unknown")
Constructor.
const std::vector< Digi > * fDigiVector
virtual bool HasMatches()
Presence of match branch.
virtual const CbmMatch * GetDigiMatch(uint32_t index)
Get match object.
TClonesArray * fMatchArray
TClonesArray of Digi objects.
const std::vector< CbmMatch > * fMatchVector
Vector of Digi objects.
TClonesArray * fDigiArray
Vector of match objects.
virtual boost::any GetBranchContainer() const
Get branch pointer.