2 #define TRACE_NAME (app_name + "_CommandableInterface").c_str()
4 #include "artdaq/Application/Commandable.hh"
5 #include "artdaq/DAQdata/Globals.hh"
10 #define TLVL_INIT TLVL_TRACE
11 #define TLVL_STOP TLVL_TRACE
12 #define TLVL_STATUS TLVL_TRACE
13 #define TLVL_START TLVL_TRACE
14 #define TLVL_PAUSE TLVL_TRACE
15 #define TLVL_RESUME TLVL_TRACE
16 #define TLVL_SHUTDOWN TLVL_TRACE
17 #define TLVL_SOFT_INIT TLVL_TRACE
18 #define TLVL_REINIT TLVL_TRACE
19 #define TLVL_INRUN_FAILURE TLVL_TRACE
20 #define TLVL_LEGAL_COMMANDS TLVL_TRACE
31 std::lock_guard<std::mutex> lk(primary_mutex_);
32 external_request_status_ =
true;
33 report_string_ =
"All is OK.";
35 #if ART_HEX_VERSION >= 0x21100
36 SetMFModuleName(
"Initializing");
39 TLOG(TLVL_INIT) <<
"Initialize transition started";
40 auto start_time = std::chrono::steady_clock::now();
41 std::string initialState = fsm_.getState().getName();
42 fsm_.init(pset, timeout, timestamp);
43 if (external_request_status_)
45 std::string finalState = fsm_.getState().getName();
46 #if ART_HEX_VERSION >= 0x21100
47 SetMFModuleName(finalState);
50 <<
"States before and after an init transition: "
51 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
53 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
55 TLOG(TLVL_INIT) <<
"Initialize transition complete";
56 return (external_request_status_);
61 std::lock_guard<std::mutex> lk(primary_mutex_);
62 external_request_status_ =
true;
63 report_string_ =
"All is OK.";
64 #if ART_HEX_VERSION >= 0x21100
65 SetMFModuleName(
"Starting");
68 TLOG(TLVL_START) <<
"Start transition started";
69 auto start_time = std::chrono::steady_clock::now();
70 std::string initialState = fsm_.getState().getName();
71 fsm_.start(
id, timeout, timestamp);
72 if (external_request_status_)
74 std::string finalState = fsm_.getState().getName();
75 #if ART_HEX_VERSION >= 0x21100
76 SetMFModuleName(finalState);
79 <<
"States before and after a start transition: "
80 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
82 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
84 TLOG(TLVL_START) <<
"Start transition complete";
85 return (external_request_status_);
90 std::lock_guard<std::mutex> lk(primary_mutex_);
91 external_request_status_ =
true;
92 report_string_ =
"All is OK.";
93 #if ART_HEX_VERSION >= 0x21100
94 SetMFModuleName(
"Stopping");
97 TLOG(TLVL_STOP) <<
"Stop transition started";
98 auto start_time = std::chrono::steady_clock::now();
99 std::string initialState = fsm_.getState().getName();
100 fsm_.stop(timeout, timestamp);
101 if (external_request_status_)
103 std::string finalState = fsm_.getState().getName();
104 #if ART_HEX_VERSION >= 0x21100
105 SetMFModuleName(finalState);
108 <<
"States before and after a stop transition: "
109 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
111 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
113 TLOG(TLVL_STOP) <<
"Stop transition complete";
114 return (external_request_status_);
119 std::lock_guard<std::mutex> lk(primary_mutex_);
120 external_request_status_ =
true;
121 report_string_ =
"All is OK.";
122 #if ART_HEX_VERSION >= 0x21100
123 SetMFModuleName(
"Pausing");
126 TLOG(TLVL_PAUSE) <<
"Pause transition started";
127 auto start_time = std::chrono::steady_clock::now();
128 std::string initialState = fsm_.getState().getName();
129 fsm_.pause(timeout, timestamp);
130 if (external_request_status_)
132 std::string finalState = fsm_.getState().getName();
133 #if ART_HEX_VERSION >= 0x21100
134 SetMFModuleName(finalState);
137 <<
"States before and after a pause transition: "
138 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
140 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
142 TLOG(TLVL_PAUSE) <<
"Pause transition complete";
143 return (external_request_status_);
148 std::lock_guard<std::mutex> lk(primary_mutex_);
149 external_request_status_ =
true;
150 report_string_ =
"All is OK.";
151 #if ART_HEX_VERSION >= 0x21100
152 SetMFModuleName(
"Resuming");
155 TLOG(TLVL_RESUME) <<
"Resume transition started";
156 auto start_time = std::chrono::steady_clock::now();
157 std::string initialState = fsm_.getState().getName();
158 fsm_.resume(timeout, timestamp);
159 if (external_request_status_)
161 std::string finalState = fsm_.getState().getName();
162 #if ART_HEX_VERSION >= 0x21100
163 SetMFModuleName(finalState);
166 <<
"States before and after a resume transition: "
167 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
169 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
171 TLOG(TLVL_RESUME) <<
"Resume transition complete";
172 return (external_request_status_);
177 std::lock_guard<std::mutex> lk(primary_mutex_);
178 external_request_status_ =
true;
179 report_string_ =
"All is OK.";
180 #if ART_HEX_VERSION >= 0x21100
181 SetMFModuleName(
"Shutting Down");
184 TLOG(TLVL_SHUTDOWN) <<
"Shutdown transition started";
185 auto start_time = std::chrono::steady_clock::now();
186 std::string initialState = fsm_.getState().getName();
187 fsm_.shutdown(timeout);
188 if (external_request_status_)
190 std::string finalState = fsm_.getState().getName();
191 #if ART_HEX_VERSION >= 0x21100
192 SetMFModuleName(finalState);
195 <<
"States before and after a shutdown transition: "
196 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
198 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
200 TLOG(TLVL_SHUTDOWN) <<
"Shutdown transition complete";
201 return (external_request_status_);
206 std::lock_guard<std::mutex> lk(primary_mutex_);
207 external_request_status_ =
true;
208 report_string_ =
"All is OK.";
209 #if ART_HEX_VERSION >= 0x21100
210 SetMFModuleName(
"Soft_initializing");
213 TLOG(TLVL_SOFT_INIT) <<
"Soft_initialize transition started";
214 auto start_time = std::chrono::steady_clock::now();
215 std::string initialState = fsm_.getState().getName();
216 fsm_.soft_init(pset, timeout, timestamp);
217 if (external_request_status_)
219 std::string finalState = fsm_.getState().getName();
220 #if ART_HEX_VERSION >= 0x21100
221 SetMFModuleName(finalState);
224 <<
"States before and after a soft_init transition: "
225 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
227 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
229 TLOG(TLVL_SOFT_INIT) <<
"Soft_initialize transition complete";
230 return (external_request_status_);
235 std::lock_guard<std::mutex> lk(primary_mutex_);
236 external_request_status_ =
true;
237 report_string_ =
"All is OK.";
238 #if ART_HEX_VERSION >= 0x21100
239 SetMFModuleName(
"Reinitializing");
242 TLOG(TLVL_REINIT) <<
"Reinitialize transition started";
243 auto start_time = std::chrono::steady_clock::now();
244 std::string initialState = fsm_.getState().getName();
245 fsm_.reinit(pset, timeout, timestamp);
246 if (external_request_status_)
248 std::string finalState = fsm_.getState().getName();
249 #if ART_HEX_VERSION >= 0x21100
250 SetMFModuleName(finalState);
253 <<
"States before and after a reinit transition: "
254 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
256 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
258 TLOG(TLVL_REINIT) <<
"Reinitialize transition complete";
259 return (external_request_status_);
264 std::lock_guard<std::mutex> lk(primary_mutex_);
265 external_request_status_ =
true;
266 report_string_ =
"An error condition was reported while running.";
267 #if ART_HEX_VERSION >= 0x21100
268 SetMFModuleName(
"Failing");
271 TLOG(TLVL_INRUN_FAILURE) <<
"In_Run_Failure transition started";
272 auto start_time = std::chrono::steady_clock::now();
273 std::string initialState = fsm_.getState().getName();
274 fsm_.in_run_failure();
275 if (external_request_status_)
277 std::string finalState = fsm_.getState().getName();
278 #if ART_HEX_VERSION >= 0x21100
279 SetMFModuleName(finalState);
282 <<
"States before and after an in_run_failure transition: "
283 << initialState <<
" and " << finalState <<
". Transition Duration: " << TimeUtils::GetElapsedTime(start_time) <<
" s." ;
285 if (metricMan) metricMan->sendMetric(
"DAQ Transition Time", TimeUtils::GetElapsedTime(start_time),
"s", 4, artdaq::MetricMode::Accumulate);
287 TLOG(TLVL_INRUN_FAILURE) <<
"in_run_failure complete";
288 return (external_request_status_);
293 std::lock_guard<std::mutex> lk(primary_mutex_);
294 TLOG(TLVL_STATUS) <<
"Status command started";
295 std::string currentState = this->current_state();
296 if (currentState ==
"InRunError")
300 TLOG(TLVL_STATUS) <<
"Status command complete";
306 std::lock_guard<std::mutex> lk(primary_mutex_);
307 TLOG(TLVL_LEGAL_COMMANDS) <<
"legal_commands started";
308 std::string currentState = this->current_state();
310 if (currentState ==
"Ready")
312 return {
"init",
"soft_init",
"start",
"shutdown" };
314 if (currentState ==
"Running")
318 return {
"pause",
"stop" };
320 if (currentState ==
"Paused")
322 return {
"resume",
"stop" };
324 if (currentState ==
"InRunError")
326 return {
"pause",
"stop" };
330 TLOG(TLVL_LEGAL_COMMANDS) <<
"legal_commands complete";
331 return {
"init",
"shutdown" };
340 TLOG(TLVL_DEBUG) <<
"do_initialize called." ;
341 external_request_status_ =
true;
342 return external_request_status_;
347 TLOG(TLVL_DEBUG) <<
"do_start called." ;
348 external_request_status_ =
true;
349 return external_request_status_;
354 TLOG(TLVL_DEBUG) <<
"do_stop called." ;
355 external_request_status_ =
true;
356 return external_request_status_;
361 TLOG(TLVL_DEBUG) <<
"do_pause called." ;
362 external_request_status_ =
true;
363 return external_request_status_;
368 TLOG(TLVL_DEBUG) <<
"do_resume called." ;
369 external_request_status_ =
true;
370 return external_request_status_;
375 TLOG(TLVL_DEBUG) <<
"do_shutdown called." ;
376 external_request_status_ =
true;
377 return external_request_status_;
382 TLOG(TLVL_DEBUG) <<
"do_reinitialize called." ;
383 external_request_status_ =
true;
384 return external_request_status_;
389 TLOG(TLVL_DEBUG) <<
"do_soft_initialize called." ;
390 external_request_status_ =
true;
391 return external_request_status_;
396 std::string currentState = this->current_state();
397 if (currentState ==
"InRunError")
399 currentState =
"Error";
402 report_string_ =
"An invalid transition (";
403 report_string_.append(trans);
404 report_string_.append(
") was requested; transition not allowed from this process's current state of \"");
405 report_string_.append(currentState);
406 report_string_.append(
"\"");
408 TLOG(TLVL_WARNING) << report_string_ ;
410 external_request_status_ =
false;
415 TLOG(TLVL_DEBUG) <<
"BootedEnter called." ;
420 TLOG(TLVL_DEBUG) <<
"InRunExit called." ;
426 TLOG(TLVL_DEBUG) <<
"Getting masks for name " << name ;
427 std::ostringstream ss;
431 unsigned ee = traceControl_p->num_namLvlTblEnts;
432 for (ii = 0; ii < ee; ++ii)
434 if (traceNamLvls_p[ii].name[0])
435 ss << traceNamLvls_p[ii].name <<
" " << std::hex << std::showbase << traceNamLvls_p[ii].M <<
" " << traceNamLvls_p[ii].S <<
" " << traceNamLvls_p[ii].T <<
" " << std::endl;
441 unsigned ee = traceControl_p->num_namLvlTblEnts;
442 for (ii = 0; ii < ee; ++ii)
444 if (traceNamLvls_p[ii].name[0] && TMATCHCMP(name.c_str(), traceNamLvls_p[ii].name))
break;
446 if (ii == ee)
return "";
448 ss << std::hex << traceNamLvls_p[ii].M <<
" " << traceNamLvls_p[ii].S <<
" " << traceNamLvls_p[ii].T;
455 TLOG(TLVL_DEBUG) <<
"Setting msk " << type <<
" for name " << name <<
" to " << std::hex << std::showbase << mask ;
458 if (type.size() > 0) {
462 TRACE_CNTL(
"lvlmsknM", name.c_str(), mask);
465 TRACE_CNTL(
"lvlmsknS", name.c_str(), mask);
468 TRACE_CNTL(
"lvlmsknT", name.c_str(), mask);
474 TLOG(TLVL_ERROR) <<
"Cannot set mask: no type specified!" ;
479 if (type.size() > 0) {
483 TRACE_CNTL(
"lvlmskMg", mask);
486 TRACE_CNTL(
"lvlmskSg", mask);
489 TRACE_CNTL(
"lvlmskTg", mask);
495 TLOG(TLVL_ERROR) <<
"Cannot set mask: no type specified!" ;
503 TLOG(TLVL_DEBUG) <<
"Meta-Command called: cmd=" << cmd <<
", arg=" << arg ;
513 std::string fullStateName = (
const_cast<Commandable*
>(
this))->fsm_.getState().getName();
514 size_t pos = fullStateName.rfind(
"::");
515 if (pos != std::string::npos)
517 return fullStateName.substr(pos + 2);
521 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.