EUDAQ
 All Classes Namespaces Files Functions Variables Pages
EventSynchronisationBase.hh
1 #ifndef EventSynchronisationBase_h__
2 #define EventSynchronisationBase_h__
3 
4 #include "eudaq/DetectorEvent.hh"
5 #include "eudaq/FileSerializer.hh"
6 #include <memory>
7 #include <queue>
8 // base class for all Synchronization Plugins
9 // it is desired to be as modular es possible with this approach.
10 // first step is to separate the events from different Producers.
11 // then it will be recombined to a new event
12 // The Idea is that the user can define a condition that need to be true to
13 // define if an event is sync or not
14 
15 namespace eudaq {
16 
17  class DLLEXPORT SyncBase {
18  public:
19  typedef std::queue<std::shared_ptr<eudaq::Event>> eventqueue_t;
20 
21  int AddDetectorElementToProducerQueue(
22  int fileIndex, std::shared_ptr<eudaq::DetectorEvent> dev);
23  virtual bool SyncFirstEvent();
24  virtual bool SyncNEvents(size_t N);
25  virtual bool getNextEvent(std::shared_ptr<eudaq::DetectorEvent> &ev);
26 
27  virtual bool
28  compareTLUwithEventQueue(std::shared_ptr<eudaq::Event> &tlu_event,
29  SyncBase::eventqueue_t &event_queue);
30  virtual bool
31  compareTLUwithEventQueues(std::shared_ptr<eudaq::Event> &tlu_event);
32 
33  void storeCurrentOrder();
34  bool Event_Queue_Is_Empty();
35  bool SubEventQueueIsEmpty(int i);
36  void event_queue_pop();
37  void event_queue_pop_TLU_event();
38  void makeDetectorEvent();
39  void clearDetectorQueue();
40 
43  virtual ~SyncBase() {}
44  SyncBase(bool sync = true);
45  void addBOREEvent(int fileIndex, const eudaq::DetectorEvent &BOREvent);
46  void PrepareForEvents();
47 
48  protected:
49  eventqueue_t &getQueuefromId(unsigned producerID);
50  eventqueue_t &getQueuefromId(unsigned fileIndex, unsigned eventIndex);
51 
52  eventqueue_t &getFirstTLUQueue();
53  unsigned getUniqueID(unsigned fileIndex, unsigned eventIndex);
54  unsigned getTLU_UniqueID(unsigned fileIndex);
55  std::map<unsigned, size_t> m_ProducerId2Eventqueue;
56  size_t m_registertProducer;
57  std::vector<size_t> m_EventsProFileReader;
58  /* This vector saves for each producer an event queue */
59 
60  std::vector<eventqueue_t> m_ProducerEventQueue;
61 
62  std::queue<std::shared_ptr<eudaq::DetectorEvent>> m_DetectorEventQueue;
63 
64  int m_TLUs_found;
65 
66  bool isAsync_;
67  size_t NumberOfEventsToSync_;
68  uint64_t longTimeDiff_;
69 
70  bool m_sync;
71  };
72 
73 } // namespace eudaq
74 
75 #endif // EventSynchronisationBase_h__
Definition: EventSynchronisationBase.hh:17
virtual ~SyncBase()
Definition: EventSynchronisationBase.hh:43
Definition: DetectorEvent.hh:12