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