EUDAQ
 All Classes Namespaces Files Functions Variables Pages
RunControl.hh
1 #ifndef EUDAQ_INCLUDED_RunControl
2 #define EUDAQ_INCLUDED_RunControl
3 
4 #include "eudaq/TransportServer.hh"
5 #include "eudaq/Logger.hh"
6 #include "eudaq/ConnectionState.hh"
7 #include "eudaq/Configuration.hh"
8 #include "eudaq/Platform.hh"
9 #include "eudaq/MachineState.hh"
10 
11 #include <string>
12 #include <memory>
13 #include <thread>
14 
15 namespace eudaq {
16 
20  class DLLEXPORT RunControl {
21  public:
22  explicit RunControl(const std::string &listenaddress = "");
23 
24  void StartServer(const std::string &listenaddress);
25  void StopServer();
26 
27  void Init(const std::string &settings);
28  void Configure(const Configuration &
29  settings);
30  void Configure(const std::string &settings,
31  int geoid = 0);
32  void Reset();
33  void GetConnectionState();
34  virtual void StartRun(const std::string &msg = "");
35  virtual void StopRun(bool listen = true);
38  void Terminate();
39 
40 
41  void TestCommand(); //Test Command
42  virtual void OnConnect(const ConnectionInfo & /*id*/) {}
43  virtual void OnDisconnect(const ConnectionInfo & /*id*/) {}
44  virtual void OnReceive(const ConnectionInfo & /*id*/,
45  std::shared_ptr<ConnectionState>) {}
46 
47  virtual void SendState(int state){}
48 
49  virtual ~RunControl();
50 
51  void CommandThread();
52  size_t NumConnections() const { return m_cmdserver->NumConnections(); }
53  const ConnectionInfo &GetConnection(size_t i) const {
54  return m_cmdserver->GetConnection(i);
55  }
56 
57  int GetFSMState(){return current_State.GetState();}
58 
59  private:
60  void InitLog(const ConnectionInfo &id);
61  void InitData(const ConnectionInfo &id);
62  void InitOther(const ConnectionInfo &id);
63  void SendCommand(const std::string &cmd, const std::string &param = "",
64  const ConnectionInfo &id = ConnectionInfo::ALL);
65  std::string
66  SendReceiveCommand(const std::string &cmd, const std::string &param = "",
67  const ConnectionInfo &id = ConnectionInfo::ALL);
68  void CommandHandler(TransportEvent &ev);
69  bool m_done;
70  bool m_listening;
71 
72  MachineState current_State;
73 
74 
75 
76  protected:
77  int32_t m_runnumber;
79  std::unique_ptr<std::thread> m_thread;
80  size_t m_idata, m_ilog;
81  std::string m_logaddr; // address of log collector
82  std::map<size_t, std::string> m_dataaddr; // map of data collector addresses
83  int64_t m_runsizelimit;
84  int64_t m_runeventlimit;
85  bool m_nextconfigonrunchange;
86  bool m_stopping, m_busy, m_producerbusy;
87  };
88 }
89 
90 #endif // EUDAQ_INCLUDED_RunControl
Definition: TransportBase.hh:80
Definition: RunControl.hh:20
Definition: Configuration.hh:12
int32_t m_runnumber
The current run number.
Definition: RunControl.hh:77
Definition: MachineState.hh:13
TransportServer * m_cmdserver
Transport for sending commands.
Definition: RunControl.hh:78
Definition: TransportServer.hh:10
Definition: TransportBase.hh:22