Project
Loading...
Searching...
No Matches
EventHandler.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <optional>
14
15using namespace o2::emcal;
16
17template <class CellInputType>
18EventHandler<CellInputType>::EventHandler(CellRange cells, TriggerRange triggers) : mTriggerRecordsCells(triggers),
19 mCells(cells)
20{
21}
22
23template <class CellInputType>
24EventHandler<CellInputType>::EventHandler(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCells) : mTriggerRecordsClusters(triggersCluster),
25 mTriggerRecordsCellIndices(triggersCells),
26 mClusters(clusters),
27 mClusterCellIndices(cellIndices)
28{
29}
30
31template <class CellInputType>
32EventHandler<CellInputType>::EventHandler(ClusterRange clusters, CellIndexRange cellIndices, CellRange cells, TriggerRange triggersCluster, TriggerRange triggersCellIndex, TriggerRange triggersCell) : mTriggerRecordsClusters(triggersCluster),
33 mTriggerRecordsCellIndices(triggersCellIndex),
34 mTriggerRecordsCells(triggersCell),
35 mClusters(clusters),
36 mClusterCellIndices(cellIndices),
37 mCells(cells)
38{
39}
40
41template <class CellInputType>
43{
44 int neventsClusters = mTriggerRecordsClusters.size(),
45 neventsCells = mTriggerRecordsCells.size();
46 if (neventsClusters) {
47 return neventsClusters;
48 } else if (neventsCells) {
49 return neventsCells;
50 } else {
51 return 0;
52 }
53}
54
55template <class CellInputType>
57{
58 std::optional<o2::InteractionRecord> irClusters, irCells;
59 if (mTriggerRecordsClusters.size()) {
60 if (eventID >= mTriggerRecordsClusters.size()) {
61 throw RangeException(eventID, mTriggerRecordsClusters.size());
62 }
63 irClusters = mTriggerRecordsClusters[eventID].getBCData();
64 }
65 if (mTriggerRecordsCells.size()) {
66 if (eventID >= mTriggerRecordsCells.size()) {
67 throw RangeException(eventID, mTriggerRecordsCells.size());
68 }
69 irCells = mTriggerRecordsCells[eventID].getBCData();
70 }
71 if (irClusters && irCells) {
72 if (compareInteractionRecords(irClusters.value(), irCells.value())) {
73 return irClusters.value();
74 } else {
75 throw InteractionRecordInvalidException(irClusters.value(), irCells.value());
76 }
77 } else if (irClusters) {
78 return irClusters.value();
79 } else if (irCells) {
80 return irCells.value();
81 }
83}
84
85template <class CellInputType>
87{
88 std::optional<uint64_t> triggerBitsClusters, triggerBitsCells;
89 if (mTriggerRecordsClusters.size()) {
90 if (eventID >= mTriggerRecordsClusters.size()) {
91 throw RangeException(eventID, mTriggerRecordsClusters.size());
92 }
93 triggerBitsClusters = mTriggerRecordsClusters[eventID].getTriggerBits();
94 }
95 if (mTriggerRecordsCells.size()) {
96 if (eventID >= mTriggerRecordsCells.size()) {
97 throw RangeException(eventID, mTriggerRecordsCells.size());
98 }
99 triggerBitsClusters = mTriggerRecordsCells[eventID].getTriggerBits();
100 }
101 if (triggerBitsClusters && triggerBitsCells) {
102 if (triggerBitsClusters == triggerBitsCells) {
103 return triggerBitsClusters.value();
104 } else {
105 throw TriggerBitsInvalidException(triggerBitsClusters.value(), triggerBitsCells.value());
106 }
107 } else if (triggerBitsClusters) {
108 return triggerBitsClusters.value();
109 } else if (triggerBitsCells) {
110 return triggerBitsCells.value();
111 }
113}
114
115template <class CellInputType>
117{
118 if (mTriggerRecordsClusters.size()) {
119 if (eventID >= mTriggerRecordsClusters.size()) {
120 throw RangeException(eventID, mTriggerRecordsClusters.size());
121 }
122 auto& trgrecord = mTriggerRecordsClusters[eventID];
123 return ClusterRange(mClusters.data() + trgrecord.getFirstEntry(), trgrecord.getNumberOfObjects());
124 }
126}
127
128template <class CellInputType>
130{
131 if (mTriggerRecordsCells.size()) {
132 if (eventID >= mTriggerRecordsCells.size()) {
133 throw RangeException(eventID, mTriggerRecordsCells.size());
134 }
135 auto& trgrecord = mTriggerRecordsCells[eventID];
136 return CellRange(mCells.data() + trgrecord.getFirstEntry(), trgrecord.getNumberOfObjects());
137 }
139}
140
141template <class CellInputType>
142std::vector<gsl::span<const o2::emcal::MCLabel>> EventHandler<CellInputType>::getCellMCLabelForEvent(int eventID) const
143{
144 if (mCellLabels && mTriggerRecordsCells.size()) {
145 if (eventID >= mTriggerRecordsCells.size()) {
146 throw RangeException(eventID, mTriggerRecordsCells.size());
147 }
148 auto& trgrecord = mTriggerRecordsCells[eventID];
149 std::vector<gsl::span<const o2::emcal::MCLabel>> eventlabels(trgrecord.getNumberOfObjects());
150 for (int index = 0; index < trgrecord.getNumberOfObjects(); index++) {
151 eventlabels[index] = mCellLabels->getLabels(trgrecord.getFirstEntry() + index);
152 }
153 return eventlabels;
154 }
156}
157
158template <class CellInputType>
160{
161 if (mTriggerRecordsCellIndices.size()) {
162 if (eventID >= mTriggerRecordsCellIndices.size()) {
163 throw RangeException(eventID, mTriggerRecordsCellIndices.size());
164 }
165 auto& trgrecord = mTriggerRecordsCellIndices[eventID];
166 return CellIndexRange(mClusterCellIndices.data() + trgrecord.getFirstEntry(), trgrecord.getNumberOfObjects());
167 }
169}
170
171template <class CellInputType>
173{
174 mTriggerRecordsClusters = TriggerRange();
175 mTriggerRecordsCellIndices = TriggerRange();
176 mTriggerRecordsCells = TriggerRange();
177 mClusters = ClusterRange();
178 mClusterCellIndices = CellIndexRange();
179 mCells = CellRange();
180 mCellLabels = nullptr;
181}
182
183template <class CellInputType>
185{
186 EventData<CellInputType> outputEvent;
187 outputEvent.mInteractionRecord = getInteractionRecordForEvent(eventID);
188 outputEvent.mTriggerBits = getTriggerBitsForEvent(eventID);
189 if (hasClusters()) {
190 outputEvent.mClusters = getClustersForEvent(eventID);
191 }
192 if (hasClusterIndices()) {
193 outputEvent.mCellIndices = getClusterCellIndicesForEvent(eventID);
194 }
195 if (hasCells()) {
196 outputEvent.mCells = getCellsForEvent(eventID);
197 }
198 if (mCellLabels) {
199 outputEvent.mMCCellLabels = getCellMCLabelForEvent(eventID);
200 }
201
202 return outputEvent;
203}
204
205template <class CellInputType>
207{
208 return lhs.bc == rhs.bc && lhs.orbit == rhs.orbit;
209}
210
211template <class CellInputType>
212EventHandler<CellInputType>::EventIterator::EventIterator(const EventHandler<CellInputType>& handler, int eventID, bool forward) : mEventHandler(handler),
213 mCurrentEvent(),
214 mEventID(eventID),
215 mForward(forward)
216{
217 mCurrentEvent = mEventHandler.buildEvent(mEventID);
218}
219
220template <class CellInputType>
222{
223 return &mEventHandler == &rhs.mEventHandler && mEventID == rhs.mEventID && mForward == rhs.mForward;
224}
226template <class CellInputType>
228{
229 if (mForward) {
230 mEventID++;
231 } else {
232 mEventID--;
233 }
234 mCurrentEvent = mEventHandler.buildEvent(mEventID);
235 return *this;
236}
237
238template <class CellInputType>
240{
241 auto tmp = *this;
242 ++(*this);
243 return tmp;
244}
245
246template <class CellInputType>
248{
249 if (mForward) {
250 mEventID--;
251 } else {
252 mEventID++;
253 }
254 mCurrentEvent = mEventHandler.buildEvent(mEventID);
255 return *this;
256}
257
258template <class CellInputType>
EventIterator & operator++()
Prefix incrementation operator.
bool operator==(const EventIterator &rhs) const
Check for equalness.
EventIterator(const EventHandler &handler, int eventID, bool forward)
Constructor, initializing the iterator.
EventIterator & operator--()
Prefix decrementation operator.
Error handling in case the interaction records from various sources do not match.
Exception handling unitialized event handler.
Exception handling errors due to exceeding the range of triggers handled by the handler.
Error handling in case the trigger bits from various sources do not match.
Handler for EMCAL event data.
EventData< CellInputType > buildEvent(int eventID) const
Build event information for a given event number within the timeframe.
EventHandler()=default
Dummy constructor.
const CellRange getCellsForEvent(int eventID) const
Get range of cells belonging to the given event.
const CellIndexRange getClusterCellIndicesForEvent(int eventID) const
Get range of cluster cell indices belonging to the given event.
const ClusterRange getClustersForEvent(int eventID) const
Get range of clusters belonging to the given event.
gsl::span< const Cluster > ClusterRange
gsl::span< const CellInputType > CellRange
std::vector< gsl::span< const o2::emcal::MCLabel > > getCellMCLabelForEvent(int eventID) const
Get vector of MC labels belonging to the given event.
void reset()
Reset containers with empty ranges.
gsl::span< const int > CellIndexRange
gsl::span< const TriggerRecord > TriggerRange
InteractionRecord getInteractionRecordForEvent(int eventID) const
Get the interaction record for the given event.
int getNumberOfEvents() const
Get the number of events handled by the event handler.
uint64_t getTriggerBitsForEvent(int eventID) const
Get the interaction record for the given event.
GLuint index
Definition glcorearb.h:781
EMCAL event information (per trigger)
Definition EventData.h:38
uint64_t mTriggerBits
Trigger bits for the event.
Definition EventData.h:44
gsl::span< const int > mCellIndices
Cell indices in cluster.
Definition EventData.h:42
gsl::span< const Cluster > mClusters
EMCAL clusters.
Definition EventData.h:40
gsl::span< const InputType > mCells
EMCAL cells / digits.
Definition EventData.h:41
std::vector< gsl::span< const o2::emcal::MCLabel > > mMCCellLabels
span of MC labels for each cell
Definition EventData.h:43
InteractionRecord mInteractionRecord
Interaction record for the trigger corresponding to this event.
Definition EventData.h:39
std::vector< Cluster > clusters
std::vector< Cell > cells