DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventHandler.h
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 #ifndef DD4HEP_DDEVE_EVENTHANDLER_H
15 #define DD4HEP_DDEVE_EVENTHANDLER_H
16 
17 // Framework include files
18 #include "DDEve/DDEveEventData.h"
19 #include "TClass.h"
20 class TH2F;
21 
22 // C/C++ include files
23 #include <set>
24 #include <map>
25 #include <vector>
26 
27 // Forward declarations
28 #define MEV_2_GEV 0.001
29 
30 /*
31  * DD4hep namespace declaration
32  */
33 namespace DD4hep {
34 
35  // Forward declarations
36  class EventConsumer;
37 
39 
44  struct DDEveHitActor {
45  virtual ~DDEveHitActor() {}
46  virtual void operator()(const DDEveHit&) = 0;
47  virtual void setSize(size_t /* num_elements */) {}
48  };
49 
51 
56  virtual ~DDEveParticleActor() {}
57  virtual void operator()(const DDEveParticle&) = 0;
58  virtual void setSize(size_t /* num_elements */) {}
59  };
60 
62 
66  class EventHandler {
67  public:
75  };
77  typedef std::pair<const char*,size_t> Collection;
79  typedef std::map<std::string,std::vector<Collection> > TypedEventCollections;
80 
81  protected:
83  bool m_hasFile;
85  bool m_hasEvent;
86  public:
88  EventHandler();
90  virtual ~EventHandler();
92  virtual bool hasEvent() const { return m_hasEvent; }
94  virtual bool hasFile() const { return m_hasFile; }
96  virtual const TypedEventCollections& data() const = 0;
98  virtual long numEvents() const = 0;
100  virtual std::string datasourceName() const = 0;
102  virtual size_t collectionLoop(const std::string& collection, DDEveHitActor& actor) = 0;
104  virtual size_t collectionLoop(const std::string& collection, DDEveParticleActor& actor) = 0;
106  virtual CollectionType collectionType(const std::string& collection) const = 0;
108  virtual bool Open(const std::string& type, const std::string& file_name) = 0;
110  virtual bool NextEvent() = 0;
112  virtual bool PreviousEvent() = 0;
114  virtual bool GotoEvent(long event_number) = 0;
115 
117  };
118 
125  public:
127  EventConsumer();
129  virtual ~EventConsumer();
131  virtual void OnNewEvent(EventHandler* /* handler */) {}
133  virtual void OnFileOpen(EventHandler* /* handler */) {}
134 
136  };
137 
138 } /* End namespace DD4hep */
139 
140 
141 #endif /* DD4HEP_DDEVE_EVENTHANDLER_H */
142 
Event data actor base class for hits. Used to extract data from concrete classes. ...
Definition: EventHandler.h:44
virtual bool hasFile() const
Check if a data file is connected to the handler.
Definition: EventHandler.h:94
virtual long numEvents() const =0
Access the number of events on the current input data source (-1 if no data source connected) ...
ClassDef(EventConsumer, 0)
virtual void setSize(size_t)
Definition: EventHandler.h:47
virtual CollectionType collectionType(const std::string &collection) const =0
Access to the collection type by name.
Data structure to store the MC particle information.
virtual void operator()(const DDEveHit &)=0
virtual size_t collectionLoop(const std::string &collection, DDEveHitActor &actor)=0
Loop over collection and extract hit data.
bool m_hasFile
Flag to indicate that a file is opened.
Definition: EventHandler.h:83
virtual std::string datasourceName() const =0
Access the data source name.
bool m_hasEvent
Flag to indicate that an event is loaded.
Definition: EventHandler.h:85
Event handler base class. Interface to all DDEve I/O actions.
Definition: EventHandler.h:66
virtual void setSize(size_t)
Definition: EventHandler.h:58
EventConsumer()
Standard constructor.
virtual const TypedEventCollections & data() const =0
Access the map of simulation data collections.
virtual void OnNewEvent(EventHandler *)
Consumer event data callback.
Definition: EventHandler.h:131
DDEve event classes: Basic hit.
ClassDef(EventHandler, 0)
virtual ~DDEveHitActor()
Definition: EventHandler.h:45
virtual bool PreviousEvent()=0
User overloadable function: Load the previous event.
virtual ~EventConsumer()
Default destructor.
virtual bool NextEvent()=0
Load the next event.
virtual bool GotoEvent(long event_number)=0
Goto a specified event in the file.
std::map< std::string, std::vector< Collection > > TypedEventCollections
Types collection: collections are grouped by type (class name)
Definition: EventHandler.h:79
EventHandler()
Standard constructor.
virtual bool Open(const std::string &type, const std::string &file_name)=0
Open a new event data file.
virtual ~EventHandler()
Default destructor.
std::pair< const char *, size_t > Collection
Collection definition: name, size.
Definition: EventHandler.h:77
Event data actor base class for particles. Used to extract data from concrete classes.
Definition: EventHandler.h:55
virtual void OnFileOpen(EventHandler *)
Consumer file open callback.
Definition: EventHandler.h:133
virtual bool hasEvent() const
Check if an event is present in memory.
Definition: EventHandler.h:92
virtual void operator()(const DDEveParticle &)=0