artdaq  v3_04_00
Commandable.hh
1 #ifndef artdaq_Application_Commandable_hh
2 #define artdaq_Application_Commandable_hh
3 
4 #include <string>
5 #include <vector>
6 #include <mutex>
7 
8 #include "fhiclcpp/ParameterSet.h"
9 #include "canvas/Persistency/Provenance/RunID.h"
10 #include "artdaq/Application/Commandable_sm.h" // must be included after others
11 
12 namespace artdaq
13 {
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 
51  bool initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
52 
60  bool start(art::RunID id, uint64_t timeout, uint64_t timestamp);
61 
68  bool stop(uint64_t timeout, uint64_t timestamp);
69 
76  bool pause(uint64_t timeout, uint64_t timestamp);
77 
84  bool resume(uint64_t timeout, uint64_t timestamp);
85 
91  bool shutdown(uint64_t timeout);
92 
100  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
101 
109  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
110 
115  bool in_run_failure();
116 
121  virtual std::string report(std::string const&) const
122  {
123  std::lock_guard<std::mutex> lk(primary_mutex_);
124  return report_string_;
125  }
126 
131  std::string status() const;
132 
139  virtual std::string register_monitor(fhicl::ParameterSet const&)
140  {
141  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";
142  }
143 
150  virtual std::string unregister_monitor(std::string const&)
151  {
152  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";
153  }
154 
159  std::vector<std::string> legal_commands() const;
160 
161  // these methods provide the operations that are used by the state machine
168  virtual bool do_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
169 
176  virtual bool do_start(art::RunID, uint64_t, uint64_t);
177 
184  virtual bool do_stop(uint64_t, uint64_t);
185 
192  virtual bool do_pause(uint64_t, uint64_t);
193 
200  virtual bool do_resume(uint64_t, uint64_t);
201 
208  virtual bool do_shutdown(uint64_t);
209 
216  virtual bool do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
217 
224  virtual bool do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
225 
232  virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum);
233 
238  virtual void badTransition(const std::string& trans);
239 
245  virtual void BootedEnter();
246 
252  virtual void InRunExit();
253 
262  virtual std::string do_trace_get(std::string const& name);
263 
273  virtual bool do_trace_set(std::string const& type, std::string const& name, uint64_t mask);
274 
283  virtual bool do_meta_command(std::string const& command, std::string const& args);
284 
290  virtual bool do_add_config_archive_entry(std::string const&, std::string const&);
291 
297  virtual bool do_clear_config_archive();
298 
299 protected:
304  std::string current_state() const;
305 
306  CommandableContext fsm_;
308  std::string report_string_;
309 
310 private:
311  // 06-May-2015, KAB: added a mutex to be used in avoiding problems when
312  // requests are sent to a Commandable object from different threads. The
313  // reason that we're doing this now is that we've added the in_run_failure()
314  // transition that will generally be called from inside the Application.
315  // Prior to this, the only way that transitions were requested was via
316  // external XMLRPC commands, and those were presumed to be called one
317  // at a time. The use of scoped locks based on the mutex will prevent
318  // the in_run_failure() transition from being called at the same time as
319  // an externally requested transition. We only lock the methods that
320  // are externally called.
321  mutable std::mutex primary_mutex_;
322 };
323 
324 #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:497
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the initialize request.
Definition: Commandable.cc:31
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:326
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:121
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:503
virtual void badTransition(const std::string &trans)
This function is called when an attempt is made to call an illegal transition.
Definition: Commandable.cc:375
virtual void InRunExit()
Perform actions upon leaving the InRun state.
Definition: Commandable.cc:399
virtual std::string unregister_monitor(std::string const &)
Perform the unregister_monitor action.
Definition: Commandable.hh:150
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:307
virtual bool do_pause(uint64_t, uint64_t)
Perform the pause transition.
Definition: Commandable.cc:340
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the reinitialize request.
Definition: Commandable.cc:218
std::string current_state() const
Return the name of the current state.
Definition: Commandable.cc:514
virtual void BootedEnter()
Perform actions upon entering the Booted state.
Definition: Commandable.cc:394
std::string status() const
Returns the current state of the Commandable.
Definition: Commandable.cc:272
virtual bool do_shutdown(uint64_t)
Perform the shutdown transition.
Definition: Commandable.cc:354
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:368
virtual bool do_trace_set(std::string const &type, std::string const &name, uint64_t mask)
Set the given TRACE mask for the given TRACE name.
Definition: Commandable.cc:434
virtual std::string register_monitor(fhicl::ParameterSet const &)
Perform the register_monitor action.
Definition: Commandable.hh:139
virtual bool do_meta_command(std::string const &command, std::string const &args)
Run a module-defined command with the given parameter string.
Definition: Commandable.cc:484
bool resume(uint64_t timeout, uint64_t timestamp)
Processes the resume transition.
Definition: Commandable.cc:140
CommandableContext fsm_
The generated State Machine (using smc_compiler)
Definition: Commandable.hh:306
bool pause(uint64_t timeout, uint64_t timestamp)
Processes the pause transition.
Definition: Commandable.cc:113
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:308
virtual bool do_stop(uint64_t, uint64_t)
Perform the stop transition.
Definition: Commandable.cc:333
bool in_run_failure()
Actions taken when the in_run_failure state is set.
Definition: Commandable.cc:245
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
Definition: Commandable.cc:285
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the soft-initialize request.
Definition: Commandable.cc:191
virtual bool do_resume(uint64_t, uint64_t)
Perform the resume transition.
Definition: Commandable.cc:347
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
Definition: Commandable.cc:59
virtual bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the reinitialize transition.
Definition: Commandable.cc:361
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:405
bool stop(uint64_t timeout, uint64_t timestamp)
Processes the stop transition.
Definition: Commandable.cc:86
virtual bool do_rollover_subrun(uint64_t eventNum, uint32_t subrunNum)
Perform the rollover_subrun transition.
Definition: Commandable.cc:490
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:319
bool shutdown(uint64_t timeout)
Processes the shutdown transition.
Definition: Commandable.cc:166