The Gaudi Framework  v30r3 (a5ef0a68)
EventContext.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_EVENTCONTEXT_H
2 #define GAUDIKERNEL_EVENTCONTEXT_H 1
3 
5 #include <boost/any.hpp>
6 #include <iostream>
7 #include <limits>
8 #include <unistd.h>
9 
25 {
26 public:
27  typedef size_t ContextID_t;
28  typedef size_t ContextEvt_t;
29 
32 
34  EventContext( const ContextEvt_t& e, const ContextID_t& s = INVALID_CONTEXT_ID ) : m_evt_num( e ), m_evt_slot( s )
35  {
36  m_valid = ( e == INVALID_CONTEXT_EVT || s == INVALID_CONTEXT_ID ) ? false : true;
37  }
38 
39  ContextEvt_t evt() const { return m_evt_num; }
40  ContextID_t slot() const { return m_evt_slot; }
41  bool valid() const { return m_valid; }
42  const EventIDBase& eventID() const { return m_eid; }
43 
44  void set( const ContextEvt_t& e = 0, const ContextID_t& s = INVALID_CONTEXT_ID )
45  {
46  m_valid = ( e == INVALID_CONTEXT_EVT || s == INVALID_CONTEXT_ID ) ? false : true;
47  m_evt_num = e;
48  m_evt_slot = s;
49  }
50 
51  void setEvt( const ContextEvt_t& e )
52  {
53  if ( e == INVALID_CONTEXT_EVT ) setValid( false );
54  m_evt_num = e;
55  }
56 
57  void setSlot( const ContextID_t& s )
58  {
59  if ( s == INVALID_CONTEXT_ID ) setValid( false );
60  m_evt_slot = s;
61  }
62 
63  void setValid( const bool& b = true )
64  {
65  m_valid = b;
66  if ( !m_valid ) {
69  }
70  }
71 
72  void setEventID( const EventIDBase& e ) { m_eid = e; }
73 
74  template <typename T>
75  void setExtension( const T& t )
76  {
77  m_extension = t;
78  }
79 
80  template <typename T>
82  {
83  return boost::any_cast<T>( &m_extension );
84  }
85 
86  template <typename T>
87  const T* getExtension() const
88  {
89  return boost::any_cast<T>( &m_extension );
90  }
91 
92  const std::type_info& getExtensionType() const { return m_extension.type(); }
93 
94 private:
95  ContextEvt_t m_evt_num{INVALID_CONTEXT_EVT};
96  ContextID_t m_evt_slot{INVALID_CONTEXT_ID};
97  bool m_valid{false};
98 
99  boost::any m_extension;
100 
102 };
103 
105 {
106  if ( ctx.valid() ) {
107  return os << "s: " << ctx.slot() << " e: " << ctx.evt();
108  } else {
109  return os << "INVALID";
110  }
111 }
112 
114 {
115  if ( c != 0 ) {
116  return os << *c;
117  } else {
118  return os << "INVALID";
119  }
120 }
121 
122 #endif // GAUDIKERNEL_EVENTCONTEXT_H
void setEvt(const ContextEvt_t &e)
Definition: EventContext.h:51
void setEventID(const EventIDBase &e)
Definition: EventContext.h:72
ContextID_t slot() const
Definition: EventContext.h:40
ContextID_t m_evt_slot
Definition: EventContext.h:96
static const ContextEvt_t INVALID_CONTEXT_EVT
Definition: EventContext.h:31
void setSlot(const ContextID_t &s)
Definition: EventContext.h:57
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
size_t ContextID_t
Definition: EventContext.h:27
ContextEvt_t evt() const
Definition: EventContext.h:39
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
boost::any m_extension
Definition: EventContext.h:99
EventIDBase m_eid
Definition: EventContext.h:101
const std::type_info & getExtensionType() const
Definition: EventContext.h:92
T * getExtension()
Definition: EventContext.h:81
EventContext(const ContextEvt_t &e, const ContextID_t &s=INVALID_CONTEXT_ID)
Definition: EventContext.h:34
static const ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:30
void setExtension(const T &t)
Definition: EventContext.h:75
ContextEvt_t m_evt_num
Definition: EventContext.h:95
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:60
string s
Definition: gaudirun.py:253
void setValid(const bool &b=true)
Definition: EventContext.h:63
const EventIDBase & eventID() const
Definition: EventContext.h:42
size_t ContextEvt_t
Definition: EventContext.h:28
std::ostream & operator<<(std::ostream &os, const EventContext &ctx)
Definition: EventContext.h:104
STL class.
bool valid() const
Definition: EventContext.h:41
const T * getExtension() const
Definition: EventContext.h:87