DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
EventHandler.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DDEVE_EVENTHANDLER_H
14 #define DDEVE_EVENTHANDLER_H
15 
16 // Framework include files
17 #include "DDEve/DDEveEventData.h"
18 #include "TClass.h"
19 class TH2F;
20 
21 // C/C++ include files
22 #include <set>
23 #include <map>
24 #include <vector>
25 
26 // Forward declarations
27 #define MEV_2_GEV 0.001
28 
29 /*
30  * dd4hep namespace declaration
31  */
32 namespace dd4hep {
33 
34  // Forward declarations
35  class EventConsumer;
36 
38 
43  struct DDEveHitActor {
44  virtual ~DDEveHitActor() {}
45  virtual void operator()(const DDEveHit&) = 0;
46  virtual void setSize(size_t /* num_elements */) {}
47  };
48 
50 
56  virtual ~DDEveParticleActor() {}
57  virtual void operator()(const DDEveParticle&) = 0;
58  virtual void setSize(size_t /* num_elements */) {}
59  };
60 
62 
67  class EventHandler {
68  public:
76  };
78  typedef std::pair<const char*,size_t> Collection;
80  typedef std::map<std::string,std::vector<Collection> > TypedEventCollections;
81 
82  protected:
84  bool m_hasFile = false;
86  bool m_hasEvent = false;
87  public:
89  EventHandler() = default;
91  virtual ~EventHandler();
93  virtual bool hasEvent() const { return m_hasEvent; }
95  virtual bool hasFile() const { return m_hasFile; }
97  virtual const TypedEventCollections& data() const = 0;
99  virtual long numEvents() const = 0;
101  virtual std::string datasourceName() const = 0;
103  virtual size_t collectionLoop(const std::string& collection, DDEveHitActor& actor) = 0;
105  virtual size_t collectionLoop(const std::string& collection, DDEveParticleActor& actor) = 0;
107  virtual CollectionType collectionType(const std::string& collection) const = 0;
109  virtual bool Open(const std::string& type, const std::string& file_name) = 0;
111  virtual bool NextEvent() = 0;
113  virtual bool PreviousEvent() = 0;
115  virtual bool GotoEvent(long event_number) = 0;
116 
118  };
119 
121 
128  public:
130  EventConsumer() = default;
132  virtual ~EventConsumer();
134  virtual void OnNewEvent(EventHandler& /* handler */) = 0;
136  virtual void OnFileOpen(EventHandler& /* handler */) = 0;
137 
139  };
140 } /* End namespace dd4hep */
141 #endif // DDEVE_EVENTHANDLER_H
142 
dd4hep::EventHandler::collectionType
virtual CollectionType collectionType(const std::string &collection) const =0
Access to the collection type by name.
dd4hep::DDEveParticleActor
Event data actor base class for particles. Used to extract data from concrete classes.
Definition: EventHandler.h:55
dd4hep::EventHandler::NO_COLLECTION
@ NO_COLLECTION
Definition: EventHandler.h:70
dd4hep::DDEveHit
DDEve event classes: Basic hit.
Definition: DDEveEventData.h:29
dd4hep::EventHandler::PreviousEvent
virtual bool PreviousEvent()=0
User overloadable function: Load the previous event.
dd4hep::EventHandler::m_hasEvent
bool m_hasEvent
Flag to indicate that an event is loaded.
Definition: EventHandler.h:86
dd4hep::EventHandler
Event handler base class: Interface to all DDEve I/O actions.
Definition: EventHandler.h:67
dd4hep::DDEveParticleActor::~DDEveParticleActor
virtual ~DDEveParticleActor()
Definition: EventHandler.h:56
dd4hep::EventHandler::TRACKER_HIT_COLLECTION
@ TRACKER_HIT_COLLECTION
Definition: EventHandler.h:74
dd4hep::EventHandler::HIT_COLLECTION
@ HIT_COLLECTION
Definition: EventHandler.h:75
dd4hep::EventConsumer::ClassDef
ClassDef(EventConsumer, 0)
dd4hep::DDEveParticleActor::operator()
virtual void operator()(const DDEveParticle &)=0
dd4hep::DDEveHitActor
Event data actor base class for hits. Used to extract data from concrete classes.
Definition: EventHandler.h:43
dd4hep::EventHandler::Open
virtual bool Open(const std::string &type, const std::string &file_name)=0
Open a new event data file.
dd4hep::EventHandler::datasourceName
virtual std::string datasourceName() const =0
Access the data source name.
dd4hep::EventHandler::hasEvent
virtual bool hasEvent() const
Check if an event is present in memory.
Definition: EventHandler.h:93
dd4hep::EventHandler::m_hasFile
bool m_hasFile
Flag to indicate that a file is opened.
Definition: EventHandler.h:84
dd4hep::EventConsumer
Event event consumer base class for DDEve: Interface class for event I/O.
Definition: EventHandler.h:127
dd4hep::EventHandler::EventHandler
EventHandler()=default
Standard constructor.
dd4hep::EventConsumer::OnNewEvent
virtual void OnNewEvent(EventHandler &)=0
Consumer event data callback.
dd4hep::EventHandler::hasFile
virtual bool hasFile() const
Check if a data file is connected to the handler.
Definition: EventHandler.h:95
dd4hep::DDEveHitActor::operator()
virtual void operator()(const DDEveHit &)=0
DDEveEventData.h
dd4hep::EventHandler::NextEvent
virtual bool NextEvent()=0
Load the next event.
dd4hep::EventHandler::CALO_HIT_COLLECTION
@ CALO_HIT_COLLECTION
Definition: EventHandler.h:73
dd4hep::EventConsumer::~EventConsumer
virtual ~EventConsumer()
Default destructor.
Definition: EventHandler.cpp:27
dd4hep::EventConsumer::OnFileOpen
virtual void OnFileOpen(EventHandler &)=0
Consumer file open callback.
dd4hep::EventHandler::CollectionType
CollectionType
Definition: EventHandler.h:69
dd4hep::EventHandler::ClassDef
ClassDef(EventHandler, 0)
dd4hep::EventHandler::TRACK_COLLECTION
@ TRACK_COLLECTION
Definition: EventHandler.h:72
dd4hep::DDEveParticleActor::setSize
virtual void setSize(size_t)
Definition: EventHandler.h:58
dd4hep::EventHandler::Collection
std::pair< const char *, size_t > Collection
Collection definition: name, size.
Definition: EventHandler.h:78
dd4hep::DDEveHitActor::~DDEveHitActor
virtual ~DDEveHitActor()
Definition: EventHandler.h:44
dd4hep::EventHandler::PARTICLE_COLLECTION
@ PARTICLE_COLLECTION
Definition: EventHandler.h:71
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::EventHandler::collectionLoop
virtual size_t collectionLoop(const std::string &collection, DDEveHitActor &actor)=0
Loop over collection and extract hit data.
dd4hep::EventHandler::GotoEvent
virtual bool GotoEvent(long event_number)=0
Goto a specified event in the file.
dd4hep::EventHandler::collectionLoop
virtual size_t collectionLoop(const std::string &collection, DDEveParticleActor &actor)=0
Loop over collection and extract particle data.
dd4hep::EventHandler::numEvents
virtual long numEvents() const =0
Access the number of events on the current input data source (-1 if no data source connected)
dd4hep::EventHandler::~EventHandler
virtual ~EventHandler()
Default destructor.
dd4hep::DDEveParticle
Data structure to store the MC particle information.
Definition: DDEveEventData.h:56
dd4hep::EventHandler::TypedEventCollections
std::map< std::string, std::vector< Collection > > TypedEventCollections
Types collection: collections are grouped by type (class name)
Definition: EventHandler.h:80
dd4hep::EventConsumer::EventConsumer
EventConsumer()=default
Standard constructor.
dd4hep::EventHandler::data
virtual const TypedEventCollections & data() const =0
Access the map of simulation data collections.
dd4hep::DDEveHitActor::setSize
virtual void setSize(size_t)
Definition: EventHandler.h:46