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