EUDAQ
 All Classes Namespaces Files Functions Variables Pages
DetectorEvent.hh
1 #ifndef EUDAQ_INCLUDED_DetectorEvent
2 #define EUDAQ_INCLUDED_DetectorEvent
3 
4 #include <vector>
5 #include "eudaq/TLUEvent.hh"
6 #include <memory>
7 
8 namespace eudaq {
9 
10  class RawDataEvent;
11 
12  class DLLEXPORT DetectorEvent : public Event {
13  EUDAQ_DECLARE_EVENT(DetectorEvent);
14 
15  public:
16  virtual void Serialize(Serializer &) const;
17  explicit DetectorEvent(unsigned runnumber, unsigned eventnumber,
18  uint64_t timestamp)
19  : Event(runnumber, eventnumber, timestamp) {}
20  // explicit DetectorEvent(const TLUEvent & tluev) :
21  // Event(tluev.GetRunNumber(), tluev.GetEventNumber(),
22  // tluev.GetTimestamp())
23  // {}
24  explicit DetectorEvent(Deserializer &);
25  void AddEvent(std::shared_ptr<Event> &evt);
26  virtual void Print(std::ostream &) const;
27 
29  virtual std::string GetType() const { return "DetectorEvent"; }
30 
31  size_t NumEvents() const { return m_events.size(); }
32  Event *GetEvent(size_t i) { return m_events[i].get(); }
33  const Event *GetEvent(size_t i) const { return m_events[i].get(); }
34  std::shared_ptr<Event> GetEventPtr(size_t i) const { return m_events[i]; }
35  const RawDataEvent &GetRawSubEvent(const std::string &subtype,
36  int n = 0) const;
37  template <typename T> const T *GetSubEvent(int n = 0) const {
38  for (size_t i = 0; i < NumEvents(); i++) {
39  const T *sev = dynamic_cast<const T *>(GetEvent(i));
40  if (sev) {
41  if (n > 0) {
42  --n;
43  } else {
44  return sev;
45  }
46  }
47  }
48  return 0;
49  }
50 
51  private:
52  std::vector<std::shared_ptr<Event>> m_events;
53  };
54 }
55 
56 #endif // EUDAQ_INCLUDED_TLUEvent
Definition: Serializer.hh:156
Definition: DetectorEvent.hh:12
Definition: Serializer.hh:19
virtual std::string GetType() const
Return "DetectorEvent" as type.
Definition: DetectorEvent.hh:29
Definition: Event.hh:38