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
12#ifndef ALICEO2_PHOS_EVENTHANDLER_H_
13#define ALICEO2_PHOS_EVENTHANDLER_H_
14
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 phos
32{
33
34// adapted from emcal
35template <class CellInputType>
37{
38 public:
39 using TriggerRange = gsl::span<const TriggerRecord>;
40 using ClusterRange = gsl::span<const Cluster>;
41 using CellIndexRange = gsl::span<const int>;
42 using CellRange = gsl::span<const CellInputType>;
43
46 class RangeException final : public std::exception
47 {
48 public:
52 RangeException(int eventID, int maxEvents) : std::exception(),
53 mEventID(eventID),
54 mMaxEvents(maxEvents),
55 mErrorMessage()
56 {
57 mErrorMessage = fmt::format("Exceeding range: %d, max %d", mEventID, mMaxEvents);
58 }
59
61 ~RangeException() noexcept final = default;
62
65 const char* what() const noexcept final { return mErrorMessage.data(); }
66
69 int getEventID() const { return mEventID; }
70
73 int getMaxNumberOfEvents() const { return mMaxEvents; }
74
75 private:
76 int mEventID = 0;
77 int mMaxEvents = 0;
78 std::string mErrorMessage;
79 };
80
83 class NotInitializedException final : public std::exception
84 {
85 public:
88
90 ~NotInitializedException() noexcept final = default;
91
94 const char* what() const noexcept final { return "EventHandler not initialized"; }
95 };
96
99 class InteractionRecordInvalidException final : public std::exception
100 {
101 public:
105 InteractionRecordInvalidException(const InteractionRecord& irclusters, const InteractionRecord& ircells) : mInteractionRecordClusters(irclusters),
106 mInteractionRecordCells(ircells)
107 {
108 }
109
111 ~InteractionRecordInvalidException() noexcept final = default;
112
115 const char* what() const noexcept final { return "Interaction records for clusters and cells not matching"; }
116
119 const InteractionRecord& getInteractionRecordClusters() const { return mInteractionRecordClusters; }
120
123 const InteractionRecord& getInteractionRecordCells() const { return mInteractionRecordCells; }
124
125 private:
126 InteractionRecord mInteractionRecordClusters;
127 InteractionRecord mInteractionRecordCells;
128 };
129
135 class EventIterator : public std::iterator_traits<EventData<CellInputType>>
136 {
137 public:
142 EventIterator(const EventHandler& handler, int eventID, bool forward);
143
147
152
154 ~EventIterator() = default;
155
161 bool operator==(const EventIterator& rhs) const;
162
168 bool operator!=(const EventIterator& rhs) const { return !(*this == rhs); }
169
173
177
181
185
188 EventData<CellInputType>* operator*() { return &mCurrentEvent; }
189
192 EventData<CellInputType>& operator&() { return mCurrentEvent; }
193
196 int current_index() const { return mEventID; }
197
198 private:
199 const EventHandler& mEventHandler;
200 EventData<CellInputType> mCurrentEvent;
201 int mEventID = 0;
202 bool mForward = true;
203 };
204
206 EventHandler() = default;
207
212
218 EventHandler(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCellIndex);
219
226 EventHandler(ClusterRange clusters, CellIndexRange cellIndices, CellRange cells, TriggerRange triggersCluster, TriggerRange triggersCellIndex, TriggerRange triggersCell);
227
229 ~EventHandler() = default;
230
233 EventIterator begin() const { return EventIterator(*this, 0, true); }
234
237 EventIterator end() const { return EventIterator(*this, getNumberOfEvents(), true); }
238
241 EventIterator rbegin() const { return EventIterator(*this, getNumberOfEvents() - 1, false); };
242
245 EventIterator rend() const { return EventIterator(*this, -1, false); };
246
248 int getNumberOfEvents() const;
250
256 const ClusterRange getClustersForEvent(int eventID) const;
257
263 const CellRange getCellsForEvent(int eventID) const;
264
270 std::vector<gsl::span<const o2::phos::MCLabel>> getCellMCLabelForEvent(int eventID) const;
271
277 const CellIndexRange getClusterCellIndicesForEvent(int eventID) const;
278
281 bool hasClusters() const { return mTriggerRecordsClusters.size() > 0; }
282
285 bool hasClusterIndices() const { return mTriggerRecordsCellIndices.size() > 0; }
286
289 bool hasCells() const { return mTriggerRecordsCells.size() > 0; }
290
296 void setClusterData(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCellIndex)
297 {
298 mClusters = clusters;
299 mClusterCellIndices = cellIndices;
300 mTriggerRecordsClusters = triggersCluster;
301 mTriggerRecordsCellIndices = triggersCellIndex;
302 }
303
308 {
309 mCells = cells;
310 mTriggerRecordsCells = triggers;
311 }
312
316 {
317 mCellLabels = mclabels;
318 }
319
321 void reset();
322
336 EventData<CellInputType> buildEvent(int eventID) const;
337
338 private:
343 bool compareInteractionRecords(const InteractionRecord& lhs, const InteractionRecord& rhs) const;
344
345 TriggerRange mTriggerRecordsClusters;
346 TriggerRange mTriggerRecordsCellIndices;
347 TriggerRange mTriggerRecordsCells;
348
349 ClusterRange mClusters;
350 CellIndexRange mClusterCellIndices;
351 CellRange mCells;
352 const o2::dataformats::MCTruthContainer<o2::phos::MCLabel>* mCellLabels = nullptr;
353
354 ClassDefNV(EventHandler, 2);
355};
356
357} // namespace phos
358} // namespace o2
359
360#endif // ALICEO2_PHOS_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.
EventData< CellInputType > * operator*()
Get pointer to the current event.
EventIterator & operator++()
Prefix incrementation operator.
bool operator==(const EventIterator &rhs) const
Check for equalness.
EventIterator(const EventIterator &other)=default
Copy constructor.
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 not equalness.
EventIterator & operator--()
Prefix decrementation operator.
Error handling in case the interaction records from various sources do not match.
const char * what() const noexcept final
Creating error message of the exception.
InteractionRecordInvalidException(const InteractionRecord &irclusters, const InteractionRecord &ircells)
Constructor initializing the exception.
const InteractionRecord & getInteractionRecordCells() const
Get the interaction record for the cells subevent.
~InteractionRecordInvalidException() noexcept final=default
Destructor.
const InteractionRecord & getInteractionRecordClusters() const
Get the interaction record for the cluster subevent.
Exception handling unitialized event handler.
~NotInitializedException() noexcept final=default
Destructor.
NotInitializedException()=default
Constructor initializing the exception.
const char * what() const noexcept final
Creating error message of the exception.
Exception handling errors due to exceeding the range of triggers handled by the handler.
~RangeException() noexcept final=default
Destructor.
const char * what() const noexcept final
Provide error message.
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.
EventData< CellInputType > buildEvent(int eventID) const
Build event information for a given event number within the timeframe.
gsl::span< const CellInputType > CellRange
bool hasCells() const
Check whether event handler has cell data.
bool hasClusters() const
Check whether event handler has cluster data.
void setCellMCTruthContainer(const o2::dataformats::MCTruthContainer< o2::phos::MCLabel > *mclabels)
Setting the pointer for the MCTruthContainer for cells.
EventHandler()=default
Dummy constructor.
const CellRange getCellsForEvent(int eventID) const
Get range of cells belonging to the given event.
EventIterator rbegin() const
Get backward start iterator.
const CellIndexRange getClusterCellIndicesForEvent(int eventID) const
Get range of cluster cell indices belonging to the given event.
~EventHandler()=default
Destructor.
gsl::span< const int > CellIndexRange
const ClusterRange getClustersForEvent(int eventID) const
Get range of clusters belonging to the given event.
bool hasClusterIndices() const
Check whether event handler has cell index data.
void setCellData(CellRange cells, TriggerRange triggers)
Setting the data at cell level.
void reset()
Reset containers with empty ranges.
std::vector< gsl::span< const o2::phos::MCLabel > > getCellMCLabelForEvent(int eventID) const
Get vector of MC labels belonging to the given event.
EventIterator end() const
Get forward end iteration marker.
EventIterator begin() const
Get forward start iterator.
InteractionRecord getInteractionRecordForEvent(int eventID) const
void setClusterData(ClusterRange clusters, CellIndexRange cellIndices, TriggerRange triggersCluster, TriggerRange triggersCellIndex)
Setting data at cluster level.
int getNumberOfEvents() const
gsl::span< const Cluster > ClusterRange
gsl::span< const TriggerRecord > TriggerRange
EventIterator rend() const
Get backward end iteration marker.
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
VectorOfTObjectPtrs other
std::vector< Cluster > clusters
std::vector< Cell > cells