Project
Loading...
Searching...
No Matches
EventHandler.h
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#ifndef ALICEO2_EMCAL_EVENTHANDLER_H_
12#define ALICEO2_EMCAL_EVENTHANDLER_H_
13
14#include <cstdint>
15#include <exception>
16#include <iterator>
17#include <gsl/span>
18#include <vector>
19#include "Rtypes.h"
20#include "fmt/format.h"
28
29namespace o2
30{
31namespace emcal
32{
33
85template <class CellInputType>
87{
88 public:
89 using TriggerRange = gsl::span<const TriggerRecord>;
90 using ClusterRange = gsl::span<const Cluster>;
91 using CellIndexRange = gsl::span<const int>;
92 using CellRange = gsl::span<const CellInputType>;
93
96 class RangeException final : public std::exception
97 {
98 public:
102 RangeException(int eventID, int maxEvents) : std::exception(),
103 mEventID(eventID),
104 mMaxEvents(maxEvents),
105 mErrorMessage()
106 {
107 mErrorMessage = fmt::format("Exceeding range: %d, max %d", mEventID, mMaxEvents);
108 }
109
111 ~RangeException() noexcept final = default;
112
115 const char* what() const noexcept final { return mErrorMessage.data(); }
116
119 int getEventID() const { return mEventID; }
120
123 int getMaxNumberOfEvents() const { return mMaxEvents; }
124
125 private:
126 int mEventID = 0;
127 int mMaxEvents = 0;
128 std::string mErrorMessage;
129 };
130
133 class NotInitializedException final : public std::exception
134 {
135 public:
138
140 ~NotInitializedException() noexcept final = default;
141
144 const char* what() const noexcept final { return "EventHandler not initialized"; }
145 };
146
149 class InteractionRecordInvalidException final : public std::exception
150 {
151 public:
155 InteractionRecordInvalidException(const InteractionRecord& irclusters, const InteractionRecord& ircells) : mInteractionRecordClusters(irclusters),
156 mInteractionRecordCells(ircells)
157 {
158 }
159
161 ~InteractionRecordInvalidException() noexcept final = default;
162
165 const char* what() const noexcept final { return "Interaction records for clusters and cells not matching"; }
166
169 const InteractionRecord& getInteractionRecordClusters() const { return mInteractionRecordClusters; }
170
173 const InteractionRecord& getInteractionRecordCells() const { return mInteractionRecordCells; }
174
175 private:
176 InteractionRecord mInteractionRecordClusters;
177 InteractionRecord mInteractionRecordCells;
178 };
179
182 class TriggerBitsInvalidException final : public std::exception
183 {
184 public:
188 TriggerBitsInvalidException(uint64_t bitsclusters, uint64_t bitscells) : mTriggerBitsClusters(bitsclusters),
189 mTriggerBitsCells(bitscells)
190 {
191 }
192
194 ~TriggerBitsInvalidException() noexcept final = default;
195
198 const char* what() const noexcept final { return "Tigger bits for clusters and cells not matching"; }
199
202 uint64_t getTriggerBitsClusters() const { return mTriggerBitsClusters; }
203
206 uint64_t getTriggerBitsCells() const { return mTriggerBitsCells; }
207
208 private:
209 uint64_t mTriggerBitsClusters;
210 uint64_t mTriggerBitsCells;
211 };
212
218 class EventIterator : public std::iterator_traits<EventData<CellInputType>>
219 {
220 public:
225 EventIterator(const EventHandler& handler, int eventID, bool forward);
226
230
235
237 ~EventIterator() = default;
238
244 bool operator==(const EventIterator& rhs) const;
245
251 bool operator!=(const EventIterator& rhs) const { return !(*this == rhs); }
252
256
260
264
268
271 EventData<CellInputType>* operator*() { return &mCurrentEvent; }
272
275 EventData<CellInputType>& operator&() { return mCurrentEvent; }
276
279 int current_index() const { return mEventID; }
280
281 private:
282 const EventHandler& mEventHandler;
283 EventData<CellInputType> mCurrentEvent;
284 int mEventID = 0;
285 bool mForward = true;
286 };
287
289 EventHandler() = default;
290
295
301 EventHandler(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCellIndex);
302
309 EventHandler(ClusterRange clusters, CellIndexRange cellIndices, CellRange cells, TriggerRange triggersCluster, TriggerRange triggersCellIndex, TriggerRange triggersCell);
310
312 ~EventHandler() = default;
313
316 EventIterator begin() const { return EventIterator(*this, 0, true); }
317
320 EventIterator end() const { return EventIterator(*this, getNumberOfEvents(), true); }
321
324 EventIterator rbegin() const { return EventIterator(*this, getNumberOfEvents() - 1, false); };
325
328 EventIterator rend() const { return EventIterator(*this, -1, false); };
329
333 int getNumberOfEvents() const;
334
344
353 uint64_t getTriggerBitsForEvent(int eventID) const;
354
360 const ClusterRange getClustersForEvent(int eventID) const;
361
367 const CellRange getCellsForEvent(int eventID) const;
368
374 std::vector<gsl::span<const o2::emcal::MCLabel>> getCellMCLabelForEvent(int eventID) const;
375
381 const CellIndexRange getClusterCellIndicesForEvent(int eventID) const;
382
385 bool hasClusters() const { return mTriggerRecordsClusters.size() > 0; }
386
389 bool hasClusterIndices() const { return mTriggerRecordsCellIndices.size() > 0; }
390
393 bool hasCells() const { return mTriggerRecordsCells.size() > 0; }
394
400 void setClusterData(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCellIndex)
401 {
402 mClusters = clusters;
403 mClusterCellIndices = cellIndices;
404 mTriggerRecordsClusters = triggersCluster;
405 mTriggerRecordsCellIndices = triggersCellIndex;
406 }
407
412 {
413 mCells = cells;
414 mTriggerRecordsCells = triggers;
415 }
416
420 {
421 mCellLabels = mclabels;
422 }
423
425 void reset();
426
440 EventData<CellInputType> buildEvent(int eventID) const;
441
442 private:
447 bool compareInteractionRecords(const InteractionRecord& lhs, const InteractionRecord& rhs) const;
448
449 TriggerRange mTriggerRecordsClusters;
450 TriggerRange mTriggerRecordsCellIndices;
451 TriggerRange mTriggerRecordsCells;
452
453 ClusterRange mClusters;
454 CellIndexRange mClusterCellIndices;
455 CellRange mCells;
456 const o2::dataformats::MCTruthContainer<o2::emcal::MCLabel>* mCellLabels = nullptr;
457
458 ClassDefNV(EventHandler, 1);
459};
460
461} // namespace emcal
462} // namespace o2
463
464#endif // ALICEO2_EMCAL_EVENTHANDLER_H__
Definition of a container to keep Monte Carlo truth external to simulation objects.
A container to hold and manage MC truth information/labels.
EventIterator & operator=(const EventIterator &other)=default
Assignment operator.
bool operator!=(const EventIterator &rhs) const
Check for not equalness.
EventIterator & operator++()
Prefix incrementation operator.
int current_index() const
Get the index of the current event.
EventData< CellInputType > & operator&()
Get reference to the current event.
bool operator==(const EventIterator &rhs) const
Check for equalness.
EventData< CellInputType > * operator*()
Get pointer to the current event.
EventIterator & operator--()
Prefix decrementation operator.
EventIterator(const EventIterator &other)=default
Copy constructor.
Error handling in case the interaction records from various sources do not match.
InteractionRecordInvalidException(const InteractionRecord &irclusters, const InteractionRecord &ircells)
Constructor initializing the exception.
const InteractionRecord & getInteractionRecordCells() const
Get the interaction record for the cells subevent.
const InteractionRecord & getInteractionRecordClusters() const
Get the interaction record for the cluster subevent.
~InteractionRecordInvalidException() noexcept final=default
Destructor.
const char * what() const noexcept final
Creating error message of the exception.
Exception handling unitialized event handler.
const char * what() const noexcept final
Creating error message of the exception.
~NotInitializedException() noexcept final=default
Destructor.
NotInitializedException()=default
Constructor initializing the exception.
Exception handling errors due to exceeding the range of triggers handled by the handler.
RangeException(int eventID, int maxEvents)
Constructor defining the error.
int getMaxNumberOfEvents() const
Get the maximum number of events handled by the event handler.
int getEventID() const
Get the ID of the event raising the exception.
~RangeException() noexcept final=default
Destructor.
const char * what() const noexcept final
Provide error message.
Error handling in case the trigger bits from various sources do not match.
uint64_t getTriggerBitsCells() const
Get the trigger bits for the cells subevent.
const char * what() const noexcept final
Creating error message of the exception.
~TriggerBitsInvalidException() noexcept final=default
Destructor.
TriggerBitsInvalidException(uint64_t bitsclusters, uint64_t bitscells)
Constructor initializing the exception.
uint64_t getTriggerBitsClusters() const
Get the trigger bits for the cluster subevent.
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.
EventIterator rbegin() const
Get backward start iterator.
bool hasClusterIndices() const
Check whether event handler has cell index data.
const CellRange getCellsForEvent(int eventID) const
Get range of cells belonging to the given event.
~EventHandler()=default
Destructor.
const CellIndexRange getClusterCellIndicesForEvent(int eventID) const
Get range of cluster cell indices belonging to the given event.
EventIterator end() const
Get forward end iteration marker.
void setClusterData(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCellIndex)
Setting data at cluster level.
EventIterator begin() const
Get forward start iterator.
const ClusterRange getClustersForEvent(int eventID) const
Get range of clusters belonging to the given event.
bool hasClusters() const
Check whether event handler has cluster data.
gsl::span< const Cluster > ClusterRange
EventIterator rend() const
Get backward end iteration marker.
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.
void setCellData(CellRange cells, TriggerRange triggers)
Setting the data at cell level.
void setCellMCTruthContainer(const o2::dataformats::MCTruthContainer< o2::emcal::MCLabel > *mclabels)
Setting the pointer for the MCTruthContainer for cells.
bool hasCells() const
Check whether event handler has cell data.
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.
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
EMCAL event information (per trigger)
Definition EventData.h:38
VectorOfTObjectPtrs other
std::vector< Cluster > clusters
std::vector< Cell > cells