CbmRoot
Loading...
Searching...
No Matches
CbmDigiManager.h
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
11#ifndef CBMDIGIMANAGER_H
12#define CBMDIGIMANAGER_H 1
13
14#include "CbmDefs.h" // for ECbmModuleId
15#include "CbmDigiBranchBase.h" // for CbmDigiBranchBase
16
17#include <FairTask.h> // for InitStatus
18#include <Logger.h> // for LOG
19
20#include <Rtypes.h> // for THashConsistencyHolder, Cla...
21#include <RtypesCore.h> // for UInt_t, Bool_t, Int_t, kTRUE
22
23#include <boost/any.hpp> // for any_cast, bad_any_cast (ptr...
24#include <boost/exception/exception.hpp> // for clone_impl, error_info_inje...
25
26#include <cassert> // for assert
27#include <gsl/span>
28#include <iosfwd> // for string
29#include <map> // for map, map<>::mapped_type
30#include <vector> // for vector
31
32class CbmMatch;
33
43
44public:
46 virtual ~CbmDigiManager();
47
48
56 template<class Digi>
57 const Digi* Get(Int_t index) const
58 {
59 assert(fIsInitialised);
60 ECbmModuleId system = Digi::GetSystem();
61 if (fBranches.find(system) == fBranches.end()) return nullptr;
62 try {
63 return boost::any_cast<const Digi*>(fBranches[system]->GetDigi(index));
64 }
65 catch (
66 const boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_any_cast>>&) {
67 LOG(fatal) << "Failed boost any_cast in Digimanager::Get for a digi of type " << Digi::GetClassName();
68 } // catch only boost::bad_any_cast which can be triggered by CbmMuchDigi/CbmMuchBeamTimeDigi
69 return nullptr;
70 }
71
72 template<class Digi>
73 gsl::span<const Digi> GetArray() const
74 {
75 assert(fIsInitialised);
76 ECbmModuleId system = Digi::GetSystem();
77
78 auto branch = fBranches.find(system);
79 if (branch == fBranches.end()) {
80 LOG(error) << "Failed to find branch for Digi of type " << Digi::GetClassName();
81 return {};
82 }
83
84 boost::any container = branch->second->GetBranchContainer();
85 LOG_IF(fatal, container.type() != typeid(const std::vector<Digi>*))
86 << "Digis of type " << Digi::GetClassName() << " not stored with std::vector";
87
88 return *boost::any_cast<const std::vector<Digi>*>(container);
89 }
90
96 {
97 auto it = fBranches.find(system);
98 return (it != fBranches.end() ? it->second : nullptr);
99 }
100
101
107 const CbmMatch* GetMatch(ECbmModuleId systemId, UInt_t index) const;
108
109
114 static Int_t GetNofDigis(ECbmModuleId systemId);
115
116
122 InitStatus Init();
123
124
127 {
129 return fgInstance;
130 }
131
132
137 static Bool_t IsPresent(ECbmModuleId systemId);
138
139
144 static Bool_t IsMatchPresent(ECbmModuleId systemId);
145
146
154 void SetBranchName(ECbmModuleId system, const char* name) { fBranchNames[system] = std::string(name); }
155
156
162 //void UseMuchBeamTimeDigi(Bool_t choice = kTRUE) { fUseMuchBeamTimeDigi = choice; }
163 void UseMuchBeamTimeDigi(Bool_t /*choice = kTRUE*/) { fUseMuchBeamTimeDigi = kFALSE; }
165
166private:
167 static std::map<ECbmModuleId, CbmDigiBranchBase*> fBranches;
169 static Bool_t fIsInitialised;
170 std::map<ECbmModuleId, std::string> fBranchNames {};
171 static Bool_t fUseMuchBeamTimeDigi;
172
173
176
177
180
181
184
185
187 template<class Digi>
188 void SetBranch();
189
190
192};
193
194
195#endif /* CBMDIGIMANAGER_H */
ECbmModuleId
Definition CbmDefs.h:39
Abstract base class for CBM digi branches.
CbmDigiManager.
void SetBranchName(ECbmModuleId system, const char *name)
Set the digi branch name for a system.
static std::map< ECbmModuleId, CbmDigiBranchBase * > fBranches
gsl::span< const Digi > GetArray() const
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
std::map< ECbmModuleId, std::string > fBranchNames
CbmDigiBranchBase * GetBranch(ECbmModuleId system)
Access to a digi branch.
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match branch.
static Bool_t fUseMuchBeamTimeDigi
CbmDigiManager & operator=(const CbmDigiManager &)=delete
void UseMuchBeamTimeDigi(Bool_t)
Use CbmMuchBeamTimeDigi instead of CbmMuchDigi for MUCH.
virtual ~CbmDigiManager()
static CbmDigiManager * fgInstance
ClassDef(CbmDigiManager, 5)
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
CbmDigiManager(const CbmDigiManager &)=delete
static Bool_t fIsInitialised
void UseMuchBeamTimeDigi()
static CbmDigiManager * Instance()
Static instance.
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
void SetBranch()
Set a digi branch.