1 #include "artdaq/Application/Commandable.hh"
2 #include "artdaq/DAQdata/Globals.hh"
13 std::lock_guard<std::mutex> lk(primary_mutex_);
14 external_request_status_ =
true;
15 report_string_ =
"All is OK.";
17 std::string initialState = fsm_.getState().getName();
18 fsm_.init(pset, timeout, timestamp);
19 if (external_request_status_)
21 std::string finalState = fsm_.getState().getName();
22 TLOG_DEBUG(
"CommandableInterface")
23 <<
"States before and after an init transition: "
24 << initialState <<
" and " << finalState << TLOG_ENDL;
27 return (external_request_status_);
32 std::lock_guard<std::mutex> lk(primary_mutex_);
33 external_request_status_ =
true;
34 report_string_ =
"All is OK.";
36 std::string initialState = fsm_.getState().getName();
37 fsm_.start(
id, timeout, timestamp);
38 if (external_request_status_)
40 std::string finalState = fsm_.getState().getName();
41 TLOG_DEBUG(
"CommandableInterface")
42 <<
"States before and after a start transition: "
43 << initialState <<
" and " << finalState << TLOG_ENDL;
46 return (external_request_status_);
51 std::lock_guard<std::mutex> lk(primary_mutex_);
52 external_request_status_ =
true;
53 report_string_ =
"All is OK.";
55 std::string initialState = fsm_.getState().getName();
56 fsm_.stop(timeout, timestamp);
57 if (external_request_status_)
59 std::string finalState = fsm_.getState().getName();
60 TLOG_DEBUG(
"CommandableInterface")
61 <<
"States before and after a stop transition: "
62 << initialState <<
" and " << finalState << TLOG_ENDL;
65 return (external_request_status_);
70 std::lock_guard<std::mutex> lk(primary_mutex_);
71 external_request_status_ =
true;
72 report_string_ =
"All is OK.";
74 std::string initialState = fsm_.getState().getName();
75 fsm_.pause(timeout, timestamp);
76 if (external_request_status_)
78 std::string finalState = fsm_.getState().getName();
79 TLOG_DEBUG(
"CommandableInterface")
80 <<
"States before and after a pause transition: "
81 << initialState <<
" and " << finalState << TLOG_ENDL;
84 return (external_request_status_);
89 std::lock_guard<std::mutex> lk(primary_mutex_);
90 external_request_status_ =
true;
91 report_string_ =
"All is OK.";
93 std::string initialState = fsm_.getState().getName();
94 fsm_.resume(timeout, timestamp);
95 if (external_request_status_)
97 std::string finalState = fsm_.getState().getName();
98 TLOG_DEBUG(
"CommandableInterface")
99 <<
"States before and after a resume transition: "
100 << initialState <<
" and " << finalState << TLOG_ENDL;
103 return (external_request_status_);
108 std::lock_guard<std::mutex> lk(primary_mutex_);
109 external_request_status_ =
true;
110 report_string_ =
"All is OK.";
112 std::string initialState = fsm_.getState().getName();
113 fsm_.shutdown(timeout);
114 if (external_request_status_)
116 std::string finalState = fsm_.getState().getName();
117 TLOG_DEBUG(
"CommandableInterface")
118 <<
"States before and after a shutdown transition: "
119 << initialState <<
" and " << finalState << TLOG_ENDL;
122 return (external_request_status_);
127 std::lock_guard<std::mutex> lk(primary_mutex_);
128 external_request_status_ =
true;
129 report_string_ =
"All is OK.";
131 std::string initialState = fsm_.getState().getName();
132 fsm_.soft_init(pset, timeout, timestamp);
133 if (external_request_status_)
135 std::string finalState = fsm_.getState().getName();
136 TLOG_DEBUG(
"CommandableInterface")
137 <<
"States before and after a soft_init transition: "
138 << initialState <<
" and " << finalState << TLOG_ENDL;
141 return (external_request_status_);
146 std::lock_guard<std::mutex> lk(primary_mutex_);
147 external_request_status_ =
true;
148 report_string_ =
"All is OK.";
150 std::string initialState = fsm_.getState().getName();
151 fsm_.reinit(pset, timeout, timestamp);
152 if (external_request_status_)
154 std::string finalState = fsm_.getState().getName();
155 TLOG_DEBUG(
"CommandableInterface")
156 <<
"States before and after a reinit transition: "
157 << initialState <<
" and " << finalState << TLOG_ENDL;
160 return (external_request_status_);
165 std::lock_guard<std::mutex> lk(primary_mutex_);
166 external_request_status_ =
true;
167 report_string_ =
"An error condition was reported while running.";
169 std::string initialState = fsm_.getState().getName();
170 fsm_.in_run_failure();
171 if (external_request_status_)
173 std::string finalState = fsm_.getState().getName();
174 TLOG_DEBUG(
"CommandableInterface")
175 <<
"States before and after an in_run_failure transition: "
176 << initialState <<
" and " << finalState << TLOG_ENDL;
179 return (external_request_status_);
184 std::lock_guard<std::mutex> lk(primary_mutex_);
185 std::string currentState = this->current_state();
186 if (currentState ==
"InRunError")
196 std::lock_guard<std::mutex> lk(primary_mutex_);
197 std::string currentState = this->current_state();
199 if (currentState ==
"Ready")
201 return {
"init",
"soft_init",
"start",
"shutdown" };
203 if (currentState ==
"Running")
207 return {
"pause",
"stop" };
209 if (currentState ==
"Paused")
211 return {
"resume",
"stop" };
213 if (currentState ==
"InRunError")
215 return {
"pause",
"stop" };
219 return {
"init",
"shutdown" };
228 TLOG_DEBUG(
"CommandableInterface") <<
"do_initialize called." << TLOG_ENDL;
229 external_request_status_ =
true;
230 return external_request_status_;
235 TLOG_DEBUG(
"CommandableInterface") <<
"do_start called." << TLOG_ENDL;
236 external_request_status_ =
true;
237 return external_request_status_;
242 TLOG_DEBUG(
"CommandableInterface") <<
"do_stop called." << TLOG_ENDL;
243 external_request_status_ =
true;
244 return external_request_status_;
249 TLOG_DEBUG(
"CommandableInterface") <<
"do_pause called." << TLOG_ENDL;
250 external_request_status_ =
true;
251 return external_request_status_;
256 TLOG_DEBUG(
"CommandableInterface") <<
"do_resume called." << TLOG_ENDL;
257 external_request_status_ =
true;
258 return external_request_status_;
263 TLOG_DEBUG(
"CommandableInterface") <<
"do_shutdown called." << TLOG_ENDL;
264 external_request_status_ =
true;
265 return external_request_status_;
270 TLOG_DEBUG(
"CommandableInterface") <<
"do_reinitialize called." << TLOG_ENDL;
271 external_request_status_ =
true;
272 return external_request_status_;
277 TLOG_DEBUG(
"CommandableInterface") <<
"do_soft_initialize called." << TLOG_ENDL;
278 external_request_status_ =
true;
279 return external_request_status_;
284 std::string currentState = this->current_state();
285 if (currentState ==
"InRunError")
287 currentState =
"Error";
290 report_string_ =
"An invalid transition (";
291 report_string_.append(trans);
292 report_string_.append(
") was requested; transition not allowed from this process's current state of \"");
293 report_string_.append(currentState);
294 report_string_.append(
"\"");
296 TLOG_WARNING(
"CommandableInterface") << report_string_ << TLOG_ENDL;
298 external_request_status_ =
false;
303 TLOG_DEBUG(
"CommandableInterface") <<
"BootedEnter called." << TLOG_ENDL;
308 TLOG_DEBUG(
"CommandableInterface") <<
"InRunExit called." << TLOG_ENDL;
314 TLOG_DEBUG(
"CommandableInterface") <<
"Getting masks for name " << name << TLOG_ENDL;
315 std::ostringstream ss;
319 unsigned ee = traceControl_p->num_namLvlTblEnts;
320 for (ii = 0; ii < ee; ++ii)
322 if (traceNamLvls_p[ii].name[0])
323 ss << traceNamLvls_p[ii].name <<
" " << std::hex << std::showbase << traceNamLvls_p[ii].M <<
" " << traceNamLvls_p[ii].S <<
" " << traceNamLvls_p[ii].T <<
" " << std::endl;
329 unsigned ee = traceControl_p->num_namLvlTblEnts;
330 for (ii = 0; ii < ee; ++ii)
332 if (traceNamLvls_p[ii].name[0] && TMATCHCMP(name.c_str(), traceNamLvls_p[ii].name))
break;
334 if (ii == ee)
return "";
336 ss << std::hex << traceNamLvls_p[ii].M <<
" " << traceNamLvls_p[ii].S <<
" " << traceNamLvls_p[ii].T;
343 TLOG_DEBUG(
"CommandableInterface") <<
"Setting msk " << type <<
" for name " << name <<
" to " << std::hex << std::showbase << mask << TLOG_ENDL;
346 if (type.size() > 0) {
350 TRACE_CNTL(
"lvlmsknM", name.c_str(), mask);
353 TRACE_CNTL(
"lvlmsknS", name.c_str(), mask);
356 TRACE_CNTL(
"lvlmsknT", name.c_str(), mask);
362 TLOG_ERROR(
"CommandableInterface") <<
"Cannot set mask: no type specified!" << TLOG_ENDL;
367 if (type.size() > 0) {
371 TRACE_CNTL(
"lvlmskMg", mask);
374 TRACE_CNTL(
"lvlmskSg", mask);
377 TRACE_CNTL(
"lvlmskTg", mask);
383 TLOG_ERROR(
"CommandableInterface") <<
"Cannot set mask: no type specified!" << TLOG_ENDL;
391 TLOG_DEBUG(
"CommandableInterface") <<
"Meta-Command called: cmd=" << cmd <<
", arg=" << arg << TLOG_ENDL;
401 std::string fullStateName = (
const_cast<Commandable*
>(
this))->fsm_.getState().getName();
402 size_t pos = fullStateName.rfind(
"::");
403 if (pos != std::string::npos)
405 return fullStateName.substr(pos + 2);
409 return fullStateName;
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the initialize request.
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Commandable is the base class for all artdaq components which implement the artdaq state machine...
virtual void badTransition(const std::string &trans)
This function is called when an attempt is made to call an illegal transition.
virtual bool do_trace_set(std::string const &, std::string const &, uint64_t)
Set the given TRACE mask for the given trace name.
virtual void InRunExit()
Perform actions upon leaving the InRun state.
virtual std::string do_trace_get(std::string const &)
Get the TRACE mask for the given trace name.
virtual bool do_pause(uint64_t, uint64_t)
Perform the pause transition.
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the reinitialize request.
std::string current_state() const
Return the name of the current state.
virtual void BootedEnter()
Perform actions upon entering the Booted state.
std::string status() const
Returns the current state of the Commandable.
virtual bool do_shutdown(uint64_t)
Perform the shutdown transition.
virtual bool do_soft_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the soft_initialize transition.
bool resume(uint64_t timeout, uint64_t timestamp)
Processes the resume transition.
bool pause(uint64_t timeout, uint64_t timestamp)
Processes the pause transition.
virtual bool do_stop(uint64_t, uint64_t)
Perform the stop transition.
virtual bool do_meta_command(std::string const &, std::string const &)
Run a module-defined command with the given parameter string.
bool in_run_failure()
Actions taken when the in_run_failure state is set.
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the soft-initialize request.
virtual bool do_resume(uint64_t, uint64_t)
Perform the resume transition.
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
virtual bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the reinitialize transition.
bool stop(uint64_t timeout, uint64_t timestamp)
Processes the stop transition.
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
bool shutdown(uint64_t timeout)
Processes the shutdown transition.