artdaq  v3_12_02
Commandable.hh
1 #ifndef artdaq_Application_Commandable_hh
2 #define artdaq_Application_Commandable_hh
3 
4 #include <mutex>
5 #include <string>
6 #include <vector>
7 
8 #include "canvas/Persistency/Provenance/RunID.h"
9 namespace fhicl {
10 class ParameterSet;
11 }
12 
13 #include "artdaq/Application/detail/Commandable_sm.h" // must be included after others
14 
15 namespace artdaq {
16 class Commandable;
17 }
18 
23 {
24 public:
28  Commandable();
29 
33  Commandable(Commandable const&) = delete;
34 
38  virtual ~Commandable() = default;
39 
44  Commandable& operator=(Commandable const&) = delete;
45 
46  Commandable(Commandable&&) = delete;
47  Commandable& operator=(Commandable&&) = delete;
48 
56  bool initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
57 
65  bool start(art::RunID id, uint64_t timeout, uint64_t timestamp);
66 
73  bool stop(uint64_t timeout, uint64_t timestamp);
74 
81  bool pause(uint64_t timeout, uint64_t timestamp);
82 
89  bool resume(uint64_t timeout, uint64_t timestamp);
90 
96  bool shutdown(uint64_t timeout);
97 
105  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
106 
114  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
115 
120  bool in_run_failure();
121 
126  virtual std::string report(std::string const&) const
127  {
128  std::lock_guard<std::mutex> lk(primary_mutex_);
129  return report_string_;
130  }
131 
136  std::string status() const;
137 
144  virtual std::string register_monitor(fhicl::ParameterSet const&)
145  {
146  return "This string is returned from Commandable::register_monitor; register_monitor should either be overridden in a derived class or this process should not have been sent the register_monitor call";
147  }
148 
155  virtual std::string unregister_monitor(std::string const&)
156  {
157  return "This string is returned from Commandable::unregister_monitor; unregister_monitor should either be overridden in a derived class or this process should not have been sent the unregister_monitor call";
158  }
159 
164  std::vector<std::string> legal_commands() const;
165 
166  // these methods provide the operations that are used by the state machine
173  virtual bool do_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
174 
181  virtual bool do_start(art::RunID, uint64_t, uint64_t);
182 
189  virtual bool do_stop(uint64_t, uint64_t);
190 
197  virtual bool do_pause(uint64_t, uint64_t);
198 
205  virtual bool do_resume(uint64_t, uint64_t);
206 
213  virtual bool do_shutdown(uint64_t);
214 
221  virtual bool do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
222 
229  virtual bool do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
230 
237  virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum);
238 
243  virtual void badTransition(const std::string& trans);
244 
250  virtual void BootedEnter();
251 
257  virtual void InRunExit();
258 
267  virtual std::string do_trace_get(std::string const& name);
268 
278  virtual bool do_trace_set(std::string const& name, std::string const& type, std::string const& mask_in_string_form);
279 
288  virtual bool do_meta_command(std::string const& cmd, std::string const& args);
289 
296  virtual bool do_add_config_archive_entry(std::string const&, std::string const&);
297 
304  virtual bool do_clear_config_archive();
305 
306 protected:
311  std::string current_state() const;
312 
313  CommandableContext fsm_;
315  std::string report_string_;
316 
317 private:
318  // 06-May-2015, KAB: added a mutex to be used in avoiding problems when
319  // requests are sent to a Commandable object from different threads. The
320  // reason that we're doing this now is that we've added the in_run_failure()
321  // transition that will generally be called from inside the Application.
322  // Prior to this, the only way that transitions were requested was via
323  // external XMLRPC commands, and those were presumed to be called one
324  // at a time. The use of scoped locks based on the mutex will prevent
325  // the in_run_failure() transition from being called at the same time as
326  // an externally requested transition. We only lock the methods that
327  // are externally called.
328  mutable std::mutex primary_mutex_;
329 };
330 
331 #endif /* artdaq_Application_Commandable_hh */
virtual bool do_add_config_archive_entry(std::string const &, std::string const &)
Add the specified key-value pair to the configuration archive list.
Definition: Commandable.cc:539
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the initialize request.
Definition: Commandable.cc:33
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:354
Commandable & operator=(Commandable const &)=delete
Copy Assignment operator is deleted.
virtual std::string report(std::string const &) const
Default report implementation returns current report_string.
Definition: Commandable.hh:126
Commandable is the base class for all artdaq components which implement the artdaq state machine...
Definition: Commandable.hh:22
virtual bool do_clear_config_archive()
Clears the configuration archive list.
Definition: Commandable.cc:545
virtual void badTransition(const std::string &trans)
This function is called when an attempt is made to call an illegal transition.
Definition: Commandable.cc:403
virtual void InRunExit()
Perform actions upon leaving the InRun state.
Definition: Commandable.cc:427
virtual std::string unregister_monitor(std::string const &)
Perform the unregister_monitor action.
Definition: Commandable.hh:155
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:314
virtual bool do_pause(uint64_t, uint64_t)
Perform the pause transition.
Definition: Commandable.cc:368
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the reinitialize request.
Definition: Commandable.cc:240
std::string current_state() const
Return the name of the current state.
Definition: Commandable.cc:556
virtual void BootedEnter()
Perform actions upon entering the Booted state.
Definition: Commandable.cc:422
std::string status() const
Returns the current state of the Commandable.
Definition: Commandable.cc:300
virtual bool do_shutdown(uint64_t)
Perform the shutdown transition.
Definition: Commandable.cc:382
virtual ~Commandable()=default
Default Destructor.
virtual bool do_soft_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the soft_initialize transition.
Definition: Commandable.cc:396
virtual std::string register_monitor(fhicl::ParameterSet const &)
Perform the register_monitor action.
Definition: Commandable.hh:144
virtual bool do_trace_set(std::string const &name, std::string const &type, std::string const &mask_in_string_form)
Set the given TRACE mask for the given TRACE name.
Definition: Commandable.cc:473
bool resume(uint64_t timeout, uint64_t timestamp)
Processes the resume transition.
Definition: Commandable.cc:153
CommandableContext fsm_
The generated State Machine (using smc_compiler)
Definition: Commandable.hh:313
bool pause(uint64_t timeout, uint64_t timestamp)
Processes the pause transition.
Definition: Commandable.cc:123
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:315
virtual bool do_stop(uint64_t, uint64_t)
Perform the stop transition.
Definition: Commandable.cc:361
bool in_run_failure()
Actions taken when the in_run_failure state is set.
Definition: Commandable.cc:270
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
Definition: Commandable.cc:313
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the soft-initialize request.
Definition: Commandable.cc:210
virtual bool do_resume(uint64_t, uint64_t)
Perform the resume transition.
Definition: Commandable.cc:375
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
Definition: Commandable.cc:63
virtual bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the reinitialize transition.
Definition: Commandable.cc:389
virtual std::string do_trace_get(std::string const &name)
Get the TRACE mask for the given TRACE name If name is &quot;ALL&quot;, then all TRACE masks will be printed...
Definition: Commandable.cc:436
virtual bool do_meta_command(std::string const &cmd, std::string const &args)
Run a module-defined command with the given parameter string.
Definition: Commandable.cc:526
bool stop(uint64_t timeout, uint64_t timestamp)
Processes the stop transition.
Definition: Commandable.cc:93
virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum)
Perform the rollover_subrun transition.
Definition: Commandable.cc:532
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:347
bool shutdown(uint64_t timeout)
Processes the shutdown transition.
Definition: Commandable.cc:182