CbmRoot
Loading...
Searching...
No Matches
CbmEventStore.h
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer], Florian Uhlig */
4
11#ifndef CBMEVENTSTORE_H
12#define CBMEVENTSTORE_H 1
13
14#include "CbmDefs.h" // for kNofSystems
15#include "CbmDigiContainer.h" // for CbmDigiContainer
16#include "CbmDigiVector.h" // for CbmDigiVector
17
18#include <Logger.h> // for LOG
19
20#include <Rtypes.h> // for THashConsistencyHolder, ClassDef
21#include <TObjArray.h> // for TObjArray
22#include <TObject.h> // for TObject
23
24#include <boost/any.hpp> // for any_cast
25
26#include <cassert> // for assert
27#include <cstdint>
28#include <string> // for string
29
30class CbmMatch;
31
43class CbmEventStore : public TObject {
44
45public:
50 CbmEventStore(uint32_t eventId = 0, bool hasMatches = false);
51
52
55
56
59
60
62 virtual ~CbmEventStore();
63
64
73 template<class Digi>
74 void AddDigi(const Digi* digi)
75 {
76 if (fHasMatches) {
77 LOG(fatal) << "CbmEventStore: Trying to add digi without match!";
78 return;
79 }
80 assert(digi);
81 ECbmModuleId system = Digi::GetSystem();
82 assert(system < ECbmModuleId::kNofSystems);
83 if (!fDigis[system]) fDigis[system] = new CbmDigiVector<Digi>(false);
84 auto digis = static_cast<CbmDigiContainer*>(fDigis.at(system));
85 assert(digis);
86 digis->AddDigi(digi, nullptr);
87 }
88
89
99 template<class Digi>
100 void AddDigi(const Digi* digi, const CbmMatch* match)
101 {
102 if (!fHasMatches) {
103 LOG(fatal) << "CbmEventStore: Trying to add digi without match!";
104 return;
105 }
106 assert(digi);
107 assert(match);
108 ECbmModuleId system = Digi::GetSystem();
109 assert(system < ECbmModuleId::kNofSystems);
110 if (!fDigis[system]) fDigis[system] = new CbmDigiVector<Digi>(true);
111 auto digis = static_cast<CbmDigiContainer*>(fDigis.at(system));
112 assert(digis);
113 digis->AddDigi(digi, match);
114 }
115
116
124 template<class Digi>
125 const Digi* GetDigi(uint32_t index) const
126 {
127 ECbmModuleId system = Digi::GetSystem();
128 assert(system < ECbmModuleId::kNofSystems);
129 auto digis = static_cast<CbmDigiContainer*>(fDigis.at(system));
130 assert(digis);
131 return boost::any_cast<const Digi*>(digis->GetDigi(index));
132 }
133
134
138 uint32_t GetEventId() const { return fEventId; }
139
140
145 uint32_t GetNofDigis(ECbmModuleId system) const;
146
147
151 bool HasMatches() const { return fHasMatches; }
152
153
157 bool IsEmpty() const;
158
159
166 void MatchToMC(CbmMatch& result) const;
167
168
171
172
174 std::string ToString() const;
175
176
177private:
178 uint32_t fEventId = -1;
179 bool fHasMatches = false;
180 // TObjArray* fDigis = nullptr; ///< Array of CbmDigiVector
181 std::map<ECbmModuleId, TObject*> fDigis;
182
184};
185
186#endif /* CBMEVENTSTORE_H */
ECbmModuleId
Definition CbmDefs.h:39
@ kNofSystems
For loops over active systems.
Abstract container for digis in CBM.
std::vector implementation of CbmDigiContainer
Storable event class for CBM.
uint32_t GetNofDigis(ECbmModuleId system) const
Number of digis for a given system.
const Digi * GetDigi(uint32_t index) const
Get a digi object.
CbmEventStore(CbmEventStore &&)=default
Move constructor.
bool HasMatches() const
Presence of match objects.
void AddDigi(const Digi *digi)
Add a digi object to the event.
void MatchToMC(CbmMatch &result) const
Match to MC event.
CbmEventStore(uint32_t eventId=0, bool hasMatches=false)
Default constructor.
std::map< ECbmModuleId, TObject * > fDigis
Map of CbmDigiVector.
CbmEventStore & operator=(const CbmEventStore &)=delete
Assignment operator.
ClassDef(CbmEventStore, 2)
uint32_t fEventId
Event identifier.
std::string ToString() const
bool IsEmpty() const
Indicate whether event contains no digis.
uint32_t GetEventId() const
Get event ID.
bool fHasMatches
Presence of matches to MC.
void AddDigi(const Digi *digi, const CbmMatch *match)
Add a digi and its match object to the event.
virtual ~CbmEventStore()
Destructor.