EUDAQ
 All Classes Namespaces Files Functions Variables Pages
DataCollector.hh
1 #ifndef EUDAQ_INCLUDED_DataCollector
2 #define EUDAQ_INCLUDED_DataCollector
3 
4 //#include <pthread.h>
5 #include <string>
6 #include <vector>
7 #include <list>
8 
9 #include "eudaq/TransportServer.hh"
10 #include "eudaq/CommandReceiver.hh"
11 #include "eudaq/Event.hh"
12 #include "eudaq/FileWriter.hh"
13 #include "eudaq/Configuration.hh"
14 #include "eudaq/Utils.hh"
15 #include "eudaq/Platform.hh"
16 #include <memory>
17 namespace eudaq {
18 
22  class DLLEXPORT DataCollector : public CommandReceiver {
23  public:
24  DataCollector(const std::string &name, const std::string &runcontrol,
25  const std::string &listenaddress,
26  const std::string &runnumberfile = "../data/runnumber.dat");
27 
28  virtual void OnConnect(const ConnectionInfo &id);
29  virtual void OnDisconnect(const ConnectionInfo &id);
30  virtual void OnServer();
31  virtual void OnGetRun();
32  virtual void OnConfigure(const Configuration &param);
33  virtual void OnPrepareRun(unsigned runnumber);
34  virtual void OnStopRun();
35  virtual void OnReceive(const ConnectionInfo &id, std::shared_ptr<Event> ev);
36  virtual void OnCompleteEvent();
37  virtual void OnStatus();
38  virtual ~DataCollector();
39 
40  void DataThread();
41 
42  private:
43  struct Info {
44  std::shared_ptr<ConnectionInfo> id;
45  std::list<std::shared_ptr<Event>> events;
46  };
47 
48  const std::string
49  m_runnumberfile; // path to the file containing the run number
50  void DataHandler(TransportEvent &ev);
51  size_t GetInfo(const ConnectionInfo &id);
52 
53  bool m_done, m_listening;
54  TransportServer *m_dataserver;
55  // pthread_t m_thread;
56  // pthread_attr_t m_threadattr;
57  std::unique_ptr<std::thread> m_thread;
58  std::vector<Info> m_buffer;
59  size_t m_numwaiting;
60  size_t m_itlu;
62  unsigned m_runnumber, m_eventnumber;
63  std::shared_ptr<FileWriter> m_writer;
64  Configuration m_config;
65  Time m_runstart;
66  };
67 }
68 
69 #endif // EUDAQ_INCLUDED_DataCollector
Definition: TransportBase.hh:80
Definition: CommandReceiver.hh:20
Definition: Configuration.hh:12
Definition: DataCollector.hh:22
Definition: Time.hh:32
Definition: TransportServer.hh:10
Definition: TransportBase.hh:22