The Gaudi Framework  v32r2 (46d42edc)
EventContext.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_EVENTCONTEXT_H
2 #define GAUDIKERNEL_EVENTCONTEXT_H 1
3 
5 #include <any>
6 #include <cstddef>
7 #include <iostream>
8 #include <limits>
9 
24 class EventContext {
25 public:
26  using ContextID_t = size_t;
27  using ContextEvt_t = size_t;
28 
31 
32  EventContext() = default;
33 
36  : m_evt_num( e ), m_evt_slot( s ), m_sub_slot( subSlot ) {
38  }
39 
40  ContextEvt_t evt() const { return m_evt_num; }
41  ContextID_t slot() const { return m_evt_slot; }
42  ContextID_t subSlot() const { return m_sub_slot; }
43  bool usesSubSlot() const { return m_sub_slot != INVALID_CONTEXT_ID; }
44  bool valid() const { return m_valid; }
45  const EventIDBase& eventID() const { return m_eid; }
46 
47  void set( const ContextEvt_t e = 0, const ContextID_t s = INVALID_CONTEXT_ID,
50  m_evt_num = e;
51  m_evt_slot = s;
53  }
54 
55  void setEvt( const ContextEvt_t e ) {
56  if ( e == INVALID_CONTEXT_EVT ) setValid( false );
57  m_evt_num = e;
58  }
59 
60  void setSlot( const ContextID_t s ) {
61  if ( s == INVALID_CONTEXT_ID ) setValid( false );
62  m_evt_slot = s;
63  }
64 
65  void setSubSlot( const ContextID_t subslot ) { m_sub_slot = subslot; }
66 
67  void setValid( const bool b = true ) {
68  m_valid = b;
69  if ( !m_valid ) {
72  }
73  }
74 
75  void setEventID( const EventIDBase& e ) { m_eid = e; }
76 
77  template <typename ValueType, typename... Args>
78  auto& emplaceExtension( Args&&... args ) {
79  return m_extension.emplace<ValueType>( std::forward<Args>( args )... );
80  }
81 
82  template <typename T>
83  auto& setExtension( T&& t ) {
84  m_extension = std::forward<T>( t );
85  return getExtension<T>();
86  }
87 
88  template <typename T>
89  auto& getExtension() {
90  return std::any_cast<std::decay_t<T>&>( m_extension );
91  }
92 
93  template <typename T>
94  const auto& getExtension() const {
95  return std::any_cast<std::decay_t<T> const&>( m_extension );
96  }
97 
98  bool hasExtension() const { return m_extension.has_value(); }
99 
100  template <typename T>
101  bool hasExtension() const {
102  return hasExtension() && m_extension.type() == typeid( std::decay_t<T> );
103  }
104 
105  const std::type_info& getExtensionType() const { return m_extension.type(); }
106 
107 private:
112  bool m_valid{false};
113 
114  std::any m_extension;
115 };
116 
118  if ( ctx.valid() ) {
119  os << "s: " << ctx.slot() << " e: " << ctx.evt();
120  if ( ctx.usesSubSlot() ) os << " sub: " << ctx.subSlot();
121  return os;
122  } else {
123  return os << "INVALID";
124  }
125 }
126 
128  if ( c ) {
129  return os << *c;
130  } else {
131  return os << "INVALID";
132  }
133 }
134 
135 #endif // GAUDIKERNEL_EVENTCONTEXT_H
void setEvt(const ContextEvt_t e)
Definition: EventContext.h:55
ContextID_t slot() const
Definition: EventContext.h:41
ContextEvt_t evt() const
Definition: EventContext.h:40
void setEventID(const EventIDBase &e)
Definition: EventContext.h:75
ContextID_t m_evt_slot
Definition: EventContext.h:110
size_t ContextID_t
Definition: EventContext.h:26
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
bool valid() const
Definition: EventContext.h:44
const auto & getExtension() const
Definition: EventContext.h:94
auto & emplaceExtension(Args &&... args)
Definition: EventContext.h:78
auto & getExtension()
Definition: EventContext.h:89
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
static constexpr ContextEvt_t INVALID_CONTEXT_EVT
Definition: EventContext.h:30
auto & setExtension(T &&t)
Definition: EventContext.h:83
const std::type_info & getExtensionType() const
Definition: EventContext.h:105
size_t ContextEvt_t
Definition: EventContext.h:27
EventIDBase m_eid
Definition: EventContext.h:108
static constexpr ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:29
void setSubSlot(const ContextID_t subslot)
Definition: EventContext.h:65
void setSlot(const ContextID_t s)
Definition: EventContext.h:60
T max(T... args)
std::any m_extension
Definition: EventContext.h:114
ContextID_t subSlot() const
Definition: EventContext.h:42
void set(const ContextEvt_t e=0, const ContextID_t s=INVALID_CONTEXT_ID, const ContextID_t subSlot=INVALID_CONTEXT_ID)
Definition: EventContext.h:47
EventContext(const ContextEvt_t e, const ContextID_t s=INVALID_CONTEXT_ID, const ContextID_t subSlot=INVALID_CONTEXT_ID)
Definition: EventContext.h:34
ContextEvt_t m_evt_num
Definition: EventContext.h:109
ContextID_t m_sub_slot
Definition: EventContext.h:111
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:56
string s
Definition: gaudirun.py:318
bool hasExtension() const
Definition: EventContext.h:98
void setValid(const bool b=true)
Definition: EventContext.h:67
std::ostream & operator<<(std::ostream &os, const EventContext &ctx)
Definition: EventContext.h:117
STL class.
EventContext()=default
bool hasExtension() const
Definition: EventContext.h:101
const EventIDBase & eventID() const
Definition: EventContext.h:45
bool usesSubSlot() const
Definition: EventContext.h:43