Belle II Software  release-05-02-19
ProcessController.h
1 #ifndef _Belle2_ProcessController_h
2 #define _Belle2_ProcessController_h
3 
4 #include "daq/slc/readout/RunInfoBuffer.h"
5 
6 #include "daq/slc/runcontrol/RCCallback.h"
7 
8 #include "daq/slc/system/PThread.h"
9 #include "daq/slc/system/Process.h"
10 #include "daq/slc/system/Mutex.h"
11 
12 #include <vector>
13 #include <sstream>
14 
15 namespace Belle2 {
22 
23  friend class ProcessSubmitter;
24 
25  public:
27  {
28  m_callback = NULL;
29  }
30  ProcessController(RCCallback* callback)
31  {
32  m_callback = callback;
33  }
35  {
36  m_info.close();
37  }
38 
39  public:
40  bool init(const std::string& parname, int nodeid = 0);
41  void clear();
42  bool load(int timeout);
43  bool start(int expno, int runno);
44  bool pause();
45  bool resume();
46  bool stop();
47 
48  /***
49  * Guaranteed abort by sending first SIGINT and after the given timeout SIGABRT in case SIGINT is not able to kill
50  * the process. Same cleanup procedure as the abort method, but circumvents hanging SIGINT calls.
51  * @param timeout time (in seconds)
52  * @return
53  */
54  bool abort(unsigned int timeout = 60);
55 
56  const std::string& getName() { return m_name; }
57  const std::string& getParName() { return m_parname; }
58  const std::string& getExecutable() { return m_exename; }
59  RunInfoBuffer& getInfo() { return m_info; }
60  RCCallback* getCallback() { return m_callback; }
61  const Process& getProcess() const { return m_process; }
62  Process& getProcess() { return m_process; }
63  void setCallback(RCCallback* callback) { m_callback = callback; }
64  void setName(const std::string& name) { m_name = name; }
65  void setExecutable(const std::string& exe) { m_exename = exe; }
66  void addArgument(const std::string& arg) { m_arg_v.push_back(arg); }
67  void addArgument(const char* format, ...);
68  template<typename T>
69  void addArgument(T arg);
70  void clearArguments() { m_arg_v = std::vector<std::string>(); }
71  bool isAlive() const { return m_process.isAlive(); }
72  bool waitReady(int timeout);
73 
74  public:
75  void lock() { m_mutex.lock(); }
76  void unlock() { m_mutex.unlock(); }
77 
78  private:
79  RunInfoBuffer m_info;
80  std::string m_name;
81  std::string m_parname;
82  RCCallback* m_callback;
83  std::string m_exename;
84  std::vector<std::string> m_arg_v;
85  Process m_process;
86  Mutex m_mutex;
87  std::string m_message;
88  PThread m_th_log;
89  PThread m_th_process;
90  int m_iopipe[2];
91 
92  };
93 
94  template<typename T>
95  inline void ProcessController::addArgument(T arg)
96  {
97  std::stringstream ss; ss << arg;
98  m_arg_v.push_back(ss.str());
99  }
100 
102 
103  public:
104  ProcessSubmitter(ProcessController* con, int iopipe[2])
105  : m_con(con)
106  {
107  m_iopipe[0] = iopipe[0];
108  m_iopipe[1] = iopipe[1];
109  }
110 
111  public:
112  void run();
113 
114  private:
115  ProcessController* m_con;
116  int m_iopipe[2];
117 
118  };
119 
121 }
122 
123 #endif
Belle2::ProcessSubmitter
Definition: ProcessController.h:101
Belle2::RunInfoBuffer
Definition: RunInfoBuffer.h:15
Belle2::RCCallback
Definition: RCCallback.h:18
Belle2::Mutex
Definition: Mutex.h:12
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ProcessController
Definition: ProcessController.h:21
Belle2::PThread
Definition: PThread.h:16
Belle2::Process
Definition: Process.h:15