artdaq  v3_09_01
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 #include "fhiclcpp/ParameterSet.h"
10 
11 #include "artdaq/Application/Commandable_sm.h" // must be included after others
12 
13 namespace artdaq {
14 class Commandable;
15 }
16 
21 {
22 public:
26  Commandable();
27 
31  Commandable(Commandable const&) = delete;
32 
36  virtual ~Commandable() = default;
37 
42  Commandable& operator=(Commandable const&) = delete;
43 
44  Commandable(Commandable&&) = delete;
45  Commandable& operator=(Commandable&&) = delete;
46 
54  bool initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
55 
63  bool start(art::RunID id, uint64_t timeout, uint64_t timestamp);
64 
71  bool stop(uint64_t timeout, uint64_t timestamp);
72 
79  bool pause(uint64_t timeout, uint64_t timestamp);
80 
87  bool resume(uint64_t timeout, uint64_t timestamp);
88 
94  bool shutdown(uint64_t timeout);
95 
103  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
104 
112  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
113 
118  bool in_run_failure();
119 
124  virtual std::string report(std::string const&) const
125  {
126  std::lock_guard<std::mutex> lk(primary_mutex_);
127  return report_string_;
128  }
129 
134  std::string status() const;
135 
142  virtual std::string register_monitor(fhicl::ParameterSet const&)
143  {
144  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";
145  }
146 
153  virtual std::string unregister_monitor(std::string const&)
154  {
155  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";
156  }
157 
162  std::vector<std::string> legal_commands() const;
163 
164  // these methods provide the operations that are used by the state machine
171  virtual bool do_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
172 
179  virtual bool do_start(art::RunID, uint64_t, uint64_t);
180 
187  virtual bool do_stop(uint64_t, uint64_t);
188 
195  virtual bool do_pause(uint64_t, uint64_t);
196 
203  virtual bool do_resume(uint64_t, uint64_t);
204 
211  virtual bool do_shutdown(uint64_t);
212 
219  virtual bool do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
220 
227  virtual bool do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
228 
235  virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum);
236 
241  virtual void badTransition(const std::string& trans);
242 
248  virtual void BootedEnter();
249 
255  virtual void InRunExit();
256 
265  virtual std::string do_trace_get(std::string const& name);
266 
276  virtual bool do_trace_set(std::string const& name, std::string const& type, std::string const& mask_in_string_form);
277 
286  virtual bool do_meta_command(std::string const& cmd, std::string const& args);
287 
294  virtual bool do_add_config_archive_entry(std::string const&, std::string const&);
295 
302  virtual bool do_clear_config_archive();
303 
304 protected:
309  std::string current_state() const;
310 
311  CommandableContext fsm_;
313  std::string report_string_;
314 
315 private:
316  // 06-May-2015, KAB: added a mutex to be used in avoiding problems when
317  // requests are sent to a Commandable object from different threads. The
318  // reason that we're doing this now is that we've added the in_run_failure()
319  // transition that will generally be called from inside the Application.
320  // Prior to this, the only way that transitions were requested was via
321  // external XMLRPC commands, and those were presumed to be called one
322  // at a time. The use of scoped locks based on the mutex will prevent
323  // the in_run_failure() transition from being called at the same time as
324  // an externally requested transition. We only lock the methods that
325  // are externally called.
326  mutable std::mutex primary_mutex_;
327 };
328 
329 #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:534
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the initialize request.
Definition: Commandable.cc:32
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:353
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:124
Commandable is the base class for all artdaq components which implement the artdaq state machine...
Definition: Commandable.hh:20
virtual bool do_clear_config_archive()
Clears the configuration archive list.
Definition: Commandable.cc:540
virtual void badTransition(const std::string &trans)
This function is called when an attempt is made to call an illegal transition.
Definition: Commandable.cc:402
virtual void InRunExit()
Perform actions upon leaving the InRun state.
Definition: Commandable.cc:426
virtual std::string unregister_monitor(std::string const &)
Perform the unregister_monitor action.
Definition: Commandable.hh:153
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:312
virtual bool do_pause(uint64_t, uint64_t)
Perform the pause transition.
Definition: Commandable.cc:367
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the reinitialize request.
Definition: Commandable.cc:239
std::string current_state() const
Return the name of the current state.
Definition: Commandable.cc:551
virtual void BootedEnter()
Perform actions upon entering the Booted state.
Definition: Commandable.cc:421
std::string status() const
Returns the current state of the Commandable.
Definition: Commandable.cc:299
virtual bool do_shutdown(uint64_t)
Perform the shutdown transition.
Definition: Commandable.cc:381
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:395
virtual std::string register_monitor(fhicl::ParameterSet const &)
Perform the register_monitor action.
Definition: Commandable.hh:142
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:468
bool resume(uint64_t timeout, uint64_t timestamp)
Processes the resume transition.
Definition: Commandable.cc:152
CommandableContext fsm_
The generated State Machine (using smc_compiler)
Definition: Commandable.hh:311
bool pause(uint64_t timeout, uint64_t timestamp)
Processes the pause transition.
Definition: Commandable.cc:122
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:313
virtual bool do_stop(uint64_t, uint64_t)
Perform the stop transition.
Definition: Commandable.cc:360
bool in_run_failure()
Actions taken when the in_run_failure state is set.
Definition: Commandable.cc:269
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
Definition: Commandable.cc:312
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the soft-initialize request.
Definition: Commandable.cc:209
virtual bool do_resume(uint64_t, uint64_t)
Perform the resume transition.
Definition: Commandable.cc:374
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
Definition: Commandable.cc:62
virtual bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the reinitialize transition.
Definition: Commandable.cc:388
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:431
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:521
bool stop(uint64_t timeout, uint64_t timestamp)
Processes the stop transition.
Definition: Commandable.cc:92
virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum)
Perform the rollover_subrun transition.
Definition: Commandable.cc:527
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:346
bool shutdown(uint64_t timeout)
Processes the shutdown transition.
Definition: Commandable.cc:181