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