| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

EventContext.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_EVENTCONTEXT_H
2 #define GAUDIKERNEL_EVENTCONTEXT_H 1
3
4 #include "GaudiKernel/EventIDBase.h"
5 #include <boost/any.hpp>
6 #include <iostream>
7 #include <limits>
8 #include <unistd.h>
9
24 class EventContext
25 {
26 public:
27 typedef size_t ContextID_t;
28 typedef size_t ContextEvt_t;
29
30 static const ContextID_t INVALID_CONTEXT_ID = std::numeric_limits<ContextID_t>::max();
31 static const ContextEvt_t INVALID_CONTEXT_EVT = std::numeric_limits<ContextEvt_t>::max();
32
33 EventContext(){};
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 ) {
67 m_evt_slot = INVALID_CONTEXT_ID;
68 m_evt_num = INVALID_CONTEXT_EVT;
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>
81 T* getExtension()
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
101 EventIDBase m_eid{};
102 };
103
104 inline std::ostream& operator<<( std::ostream& os, const EventContext& ctx )
105 {
106 if ( ctx.valid() ) {
107 return os << "s: " << ctx.slot() << " e: " << ctx.evt();
108 } else {
109 return os << "INVALID";
110 }
111 }
112
113 inline std::ostream& operator<<( std::ostream& os, const EventContext* c )
114 {
115 if ( c != 0 ) {
116 return os << *c;
117 } else {
118 return os << "INVALID";
119 }
120 }
121
122 #endif // GAUDIKERNEL_EVENTCONTEXT_H
EventContext::m_valid
bool m_valid
Definition: EventContext.h:97
EventContext::setEvt
void setEvt(const ContextEvt_t &e)
Definition: EventContext.h:51
gaudirun.c
c
Definition: gaudirun.py:407
EventContext::setEventID
void setEventID(const EventIDBase &e)
Definition: EventContext.h:72
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:40
EventContext::m_evt_slot
ContextID_t m_evt_slot
Definition: EventContext.h:96
EventContext::INVALID_CONTEXT_EVT
static const ContextEvt_t INVALID_CONTEXT_EVT
Definition: EventContext.h:31
EventContext::setSlot
void setSlot(const ContextID_t &s)
Definition: EventContext.h:57
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
EventContext::ContextID_t
size_t ContextID_t
Definition: EventContext.h:27
std::type_info
EventContext::evt
ContextEvt_t evt() const
Definition: EventContext.h:39
EventIDBase.h
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
EventContext::m_extension
boost::any m_extension
Definition: EventContext.h:99
EventContext::m_eid
EventIDBase m_eid
Definition: EventContext.h:101
EventContext::getExtensionType
const std::type_info & getExtensionType() const
Definition: EventContext.h:92
EventContext::getExtension
T * getExtension()
Definition: EventContext.h:81
EventContext::EventContext
EventContext(const ContextEvt_t &e, const ContextID_t &s=INVALID_CONTEXT_ID)
Definition: EventContext.h:34
EventContext::INVALID_CONTEXT_ID
static const ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:30
std::numeric_limits::max
T max(T...args)
EventContext::setExtension
void setExtension(const T &t)
Definition: EventContext.h:75
EventContext::m_evt_num
ContextEvt_t m_evt_num
Definition: EventContext.h:95
EventIDBase
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:29
gaudirun.s
string s
Definition: gaudirun.py:253
EventContext::setValid
void setValid(const bool &b=true)
Definition: EventContext.h:63
EventContext::eventID
const EventIDBase & eventID() const
Definition: EventContext.h:42
EventContext::EventContext
EventContext()
Definition: EventContext.h:33
EventContext::ContextEvt_t
size_t ContextEvt_t
Definition: EventContext.h:28
operator<<
std::ostream & operator<<(std::ostream &os, const EventContext &ctx)
Definition: EventContext.h:104
std::ostream
STL class.
EventContext::valid
bool valid() const
Definition: EventContext.h:41
EventContext::getExtension
const T * getExtension() const
Definition: EventContext.h:87