CbmRoot
Loading...
Searching...
No Matches
CbmDigiManager.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer], Florian Uhlig */
4
9#include "CbmDigiManager.h"
10
11#include "CbmBmonDigi.h" // for CbmBmonDigi
12#include "CbmDefs.h" // for kMuch
13#include "CbmDigiBranch.h" // for CbmDigiBranch
14#include "CbmFsdDigi.h" // for CbmFsdDigi
15#include "CbmMuchBeamTimeDigi.h" // for CbmMuchBeamTimeDigi
16#include "CbmMuchDigi.h" // for CbmMuchDigi
17#include "CbmMvdDigi.h" // for CbmMvdDigi
18#include "CbmPsdDigi.h" // for CbmPsdDigi
19#include "CbmRichDigi.h" // for CbmRichDigi
20#include "CbmStsDigi.h" // for CbmStsDigi
21#include "CbmTofDigi.h" // for CbmTofDigi
22#include "CbmTrdDigi.h" // for CbmTrdDigi
23
24#include <FairTask.h> // for kSUCCESS, InitStatus
25
26#include <TGenericClassInfo.h> // for TGenericClassInfo
27#include <TString.h> // for operator+, operator<<
28
29#include <iostream> // for string, endl, basic_ostream, cout
30#include <string> // for operator==, basic_string
31
32
33using std::string;
34
35// ----- Initialisation of static variables ----------------------------
37std::map<ECbmModuleId, CbmDigiBranchBase*> CbmDigiManager::fBranches = std::map<ECbmModuleId, CbmDigiBranchBase*>();
38Bool_t CbmDigiManager::fIsInitialised = kFALSE;
40// -------------------------------------------------------------------------
41
42
43// ----- Constructor ---------------------------------------------------
45// -------------------------------------------------------------------------
46
47
48// ----- Destructor ----------------------------------------------------
50{
51 for (auto& entry : fBranches) {
52 if (entry.second) delete entry.second;
53 }
54}
55// -------------------------------------------------------------------------
56
57
58// ----- Get a match object --------------------------------------------
59const CbmMatch* CbmDigiManager::GetMatch(ECbmModuleId systemId, UInt_t index) const
60{
61 assert(fIsInitialised);
62 if (fBranches.find(systemId) == fBranches.end()) return nullptr;
63 return fBranches[systemId]->GetDigiMatch(index);
64}
65
66// ----- Get number of digis in branch ---------------------------------
68{
69 assert(fIsInitialised);
70 if (fBranches.find(systemId) == fBranches.end()) return -1;
71 return fBranches[systemId]->GetNofDigis();
72}
73// -------------------------------------------------------------------------
74
75
76// ----- Initialisation ------------------------------------------------
78{
79
80 if (fIsInitialised) return kSUCCESS;
81
82 std::cout << std::endl << std::endl;
83 LOG(info) << "==================================================";
84 LOG(info) << "DigiManager: Initialising...";
85
90 else
97 LOG(info) << "Present branches:";
98 for (auto const& branch : fBranches) {
99 LOG(info) << " " << branch.second->ToString();
100 }
101
102 fIsInitialised = kTRUE;
103 LOG(info) << "==================================================";
104 std::cout << std::endl << std::endl;
105
106 return kSUCCESS;
107}
108// -------------------------------------------------------------------------
109
110
111// ----- Check presence of a match branch ------------------------------
113{
114 if (fBranches.find(systemId) == fBranches.end()) return kFALSE;
115 return fBranches[systemId]->HasMatches();
116}
117// -------------------------------------------------------------------------
118
119
120// ----- Check presence of a digi branch -------------------------------
122{
123 if (fBranches.find(systemId) == fBranches.end()) return kFALSE;
124 return kTRUE;
125}
126// -------------------------------------------------------------------------
127
128
129// ----- Set a digi branch ---------------------------------------------
130template<class Digi>
132{
133
134 // Get system ID and class name from digi class.
135 ECbmModuleId systemId = Digi::GetSystem();
136 string className = Digi::GetClassName();
137 LOG(info) << "systemId= " << systemId << " className= " << className;
138
139 // --- Catch branch being already set
140 if (fBranches.find(systemId) != fBranches.end()) {
141 LOG(warn) << "DigiManager: Branch for system " << systemId << " is already set.";
142 return;
143 } //? branch already present
144
145 // --- Branch name. If not set explicitly, taken from the class name
146 // --- minus the leading "Cbm" (CBM convention)
147 string branchName {};
148 if (fBranchNames.find(systemId) != fBranchNames.end()) {
149 branchName = fBranchNames[systemId];
150 } //? branch name explicitly set
151 else {
152 if (className.substr(0, 3) == "Cbm") branchName = className.substr(3);
153 else
154 branchName = className;
155 } //? Branch name not explicitly set
156
157 // --- Add branch object and connect it to the tree
158 CbmDigiBranchBase* branch = new CbmDigiBranch<Digi>(branchName.c_str());
159 if (branch->ConnectToTree()) {
160 LOG(debug) << "DigiManager: Search branch " << branchName << " for class " << className << ": successful";
161 fBranches[systemId] = branch;
162 }
163 else {
164 LOG(debug) << "DigiManager: Search branch " << branchName << " for class " << className << ": failed";
165 delete branch;
166 }
167
168 // Special cases for mCBM TOF
169 if (systemId == ECbmModuleId::kTof) {
170 if (fBranches.find(systemId) == fBranches.end()) {
171 branchName = "TofCalDigi";
172 branch = new CbmDigiBranch<Digi>(branchName.c_str());
173 if (branch->ConnectToTree()) {
174 LOG(info) << "DigiManager: Search branch " << branchName << " for class " << className << ": successful";
175 fBranches[systemId] = branch;
176 }
177 else {
178 LOG(info) << "DigiManager: Search branch " << branchName << " for class " << className << ": failed";
179 delete branch;
180 }
181 }
182 if (fBranches.find(systemId) == fBranches.end()) {
183 branchName = "CbmTofDigi";
184 branch = new CbmDigiBranch<Digi>(branchName.c_str());
185 if (branch->ConnectToTree()) {
186 LOG(info) << "DigiManager: Search branch " << branchName << " for class " << className << ": successful";
187 fBranches[systemId] = branch;
188 }
189 else {
190 LOG(info) << "DigiManager: Search branch " << branchName << " for class " << className << ": failed";
191 delete branch;
192 }
193 }
194 if (fBranches.find(systemId) == fBranches.end()) {
195 branchName = "CbmTofCalDigi";
196 branch = new CbmDigiBranch<Digi>(branchName.c_str());
197 if (branch->ConnectToTree()) fBranches[systemId] = branch;
198 else
199 delete branch;
200 }
201 }
202}
203// -------------------------------------------------------------------------
204
205
ClassImp(CbmConverterManager)
ECbmModuleId
Definition CbmDefs.h:39
@ kTof
Time-of-flight Detector.
Abstract base class for CBM digi branches.
virtual bool ConnectToTree()=0
Connect the branch to the ROOT tree.
Class template for CBM digi branches.
CbmDigiManager.
static std::map< ECbmModuleId, CbmDigiBranchBase * > fBranches
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
std::map< ECbmModuleId, std::string > fBranchNames
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match branch.
static Bool_t fUseMuchBeamTimeDigi
virtual ~CbmDigiManager()
static CbmDigiManager * fgInstance
InitStatus Init()
Initialisation.
static Bool_t fIsInitialised
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
void SetBranch()
Set a digi branch.