1 #ifndef EUDAQ_INCLUDED_Event
2 #define EUDAQ_INCLUDED_Event
10 #include "eudaq/Serializable.hh"
11 #include "eudaq/Serializer.hh"
12 #include "eudaq/Exception.hh"
14 #include "eudaq/Platform.hh"
16 #define EUDAQ_DECLARE_EVENT(type) \
18 static unsigned eudaq_static_id(); \
19 virtual unsigned get_id() const { return eudaq_static_id(); } \
22 static const int EUDAQ_DUMMY_VAR_DONT_USE = 0
24 #define EUDAQ_DEFINE_EVENT(type, id) \
25 unsigned type::eudaq_static_id() { \
26 static const unsigned id_(id); \
29 namespace _eudaq_dummy_ { \
30 static eudaq::RegisterEventType<type> eudaq_reg; \
32 static const int EUDAQ_DUMMY_VAR_DONT_USE = 0
36 static const uint64_t NOTIMESTAMP = (uint64_t)-1;
50 FLAG_ALL = (unsigned)-1
52 Event(
unsigned run,
unsigned event, uint64_t timestamp = NOTIMESTAMP,
54 : m_flags(flags), m_runnumber(run), m_eventnumber(event),
55 m_timestamp(timestamp) {}
57 virtual void Serialize(
Serializer &)
const = 0;
59 unsigned GetRunNumber()
const {
return m_runnumber; }
60 unsigned GetEventNumber()
const {
return m_eventnumber; }
61 uint64_t GetTimestamp()
const {
return m_timestamp; }
68 virtual void Print(std::ostream &os)
const = 0;
70 bool HasTag(
const std::string &name)
const;
71 std::vector<std::string> GetTagList(
const std::string &prefix)
const;
73 Event &SetTag(
const std::string &name,
const std::string &val);
74 template <
typename T>
Event &SetTag(
const std::string &name,
const T &val) {
77 std::string GetTag(
const std::string &name,
78 const std::string &def =
"")
const;
79 std::string GetTag(
const std::string &name,
const char *def)
const {
80 return GetTag(name, std::string(def));
82 template <
typename T> T GetTag(
const std::string &name, T def)
const {
86 bool IsBORE()
const {
return GetFlags(FLAG_BORE) != 0; }
87 bool IsEORE()
const {
return GetFlags(FLAG_EORE) != 0; }
88 bool HasHits()
const {
return GetFlags(FLAG_HITS) != 0; }
89 bool IsFake()
const {
return GetFlags(FLAG_FAKE) != 0; }
90 bool IsSimulation()
const {
return GetFlags(FLAG_SIMU) != 0; }
92 static unsigned str2id(
const std::string &idstr);
93 static std::string id2str(
unsigned id);
94 unsigned GetFlags(
unsigned f = FLAG_ALL)
const {
return m_flags & f; }
95 void SetFlags(
unsigned f) { m_flags |= f; }
96 void SetTimeStampToNow();
97 void setTimeStamp(uint64_t timeStamp) { m_timestamp = timeStamp; }
98 void ClearFlags(
unsigned f = FLAG_ALL) { m_flags &= ~f; }
99 virtual unsigned get_id()
const = 0;
102 typedef std::map<std::string, std::string> map_t;
104 unsigned m_flags, m_runnumber, m_eventnumber;
105 uint64_t m_timestamp;
109 DLLEXPORT std::ostream &operator<<(std::ostream &,
const Event &);
117 event_creator cr = GetCreator(
id);
119 EUDAQ_THROW(
"Unrecognised Event type (" + Event::id2str(
id) +
")");
124 static void Register(uint32_t
id, event_creator func);
125 static event_creator GetCreator(uint32_t
id);
128 typedef std::map<uint32_t, event_creator> map_t;
129 static map_t &get_map();
136 EventFactory::Register(T_Evt::eudaq_static_id(), &factory_func);
142 #endif // EUDAQ_INCLUDED_Event
virtual std::string GetSubType() const
Definition: Event.hh:66
map_t m_tags
Metadata tags in (name=value) pairs of strings.
Definition: Event.hh:106
Definition: Serializer.hh:156
Definition: Serializable.hh:13
T DLLEXPORT from_string(const std::string &x, const T &def=0)
Definition: Utils.hh:115
std::string to_string(const T &x, int digits=0)
Definition: Utils.hh:54
Definition: Serializer.hh:19