artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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 
138  virtual bool reset_stats(std::string const& which)
139  {
140  std::lock_guard<std::mutex> lk(primary_mutex_);
141  if (which == "fail")
142  {
143  return false;
144  }
145  else
146  {
147  return true;
148  }
149  }
150 
157  virtual std::string register_monitor(fhicl::ParameterSet const&)
158  {
159  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";
160  }
161 
168  virtual std::string unregister_monitor(std::string const&)
169  {
170  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";
171  }
172 
177  std::vector<std::string> legal_commands() const;
178 
179  // these methods provide the operations that are used by the state machine
186  virtual bool do_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
187 
194  virtual bool do_start(art::RunID, uint64_t, uint64_t);
195 
202  virtual bool do_stop(uint64_t, uint64_t);
203 
210  virtual bool do_pause(uint64_t, uint64_t);
211 
218  virtual bool do_resume(uint64_t, uint64_t);
219 
226  virtual bool do_shutdown(uint64_t);
227 
234  virtual bool do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
235 
242  virtual bool do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t);
243 
248  virtual void badTransition(const std::string& trans);
249 
255  virtual void BootedEnter();
256 
262  virtual void InRunExit();
263 
264 protected:
269  std::string current_state() const;
270 
271  CommandableContext fsm_;
273  std::string report_string_;
274 
275 private:
276  // 06-May-2015, KAB: added a mutex to be used in avoiding problems when
277  // requests are sent to a Commandable object from different threads. The
278  // reason that we're doing this now is that we've added the in_run_failure()
279  // transition that will generally be called from inside the Application.
280  // Prior to this, the only way that transitions were requested was via
281  // external XMLRPC commands, and those were presumed to be called one
282  // at a time. The use of scoped locks based on the mutex will prevent
283  // the in_run_failure() transition from being called at the same time as
284  // an externally requested transition. We only lock the methods that
285  // are externally called.
286  mutable std::mutex primary_mutex_;
287 };
288 
289 #endif /* artdaq_Application_Commandable_hh */
bool initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the initialize request.
Definition: Commandable.cc:11
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:233
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 void badTransition(const std::string &trans)
This function is called when an attempt is made to call an illegal transition.
Definition: Commandable.cc:282
virtual void InRunExit()
Perform actions upon leaving the InRun state.
Definition: Commandable.cc:306
virtual std::string unregister_monitor(std::string const &)
Perform the unregister_monitor action.
Definition: Commandable.hh:168
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:272
virtual bool do_pause(uint64_t, uint64_t)
Perform the pause transition.
Definition: Commandable.cc:247
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the reinitialize request.
Definition: Commandable.cc:144
std::string current_state() const
Return the name of the current state.
Definition: Commandable.cc:315
virtual void BootedEnter()
Perform actions upon entering the Booted state.
Definition: Commandable.cc:301
std::string status() const
Returns the current state of the Commandable.
Definition: Commandable.cc:182
virtual bool do_shutdown(uint64_t)
Perform the shutdown transition.
Definition: Commandable.cc:261
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:275
virtual std::string register_monitor(fhicl::ParameterSet const &)
Perform the register_monitor action.
Definition: Commandable.hh:157
virtual bool reset_stats(std::string const &which)
Virutal function which resets statistics.
Definition: Commandable.hh:138
bool resume(uint64_t timeout, uint64_t timestamp)
Processes the resume transition.
Definition: Commandable.cc:87
CommandableContext fsm_
The generated State Machine (using smc_compiler)
Definition: Commandable.hh:271
bool pause(uint64_t timeout, uint64_t timestamp)
Processes the pause transition.
Definition: Commandable.cc:68
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:273
virtual bool do_stop(uint64_t, uint64_t)
Perform the stop transition.
Definition: Commandable.cc:240
bool in_run_failure()
Actions taken when the in_run_failure state is set.
Definition: Commandable.cc:163
std::vector< std::string > legal_commands() const
Get the legal transition commands from the current state.
Definition: Commandable.cc:194
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Processes the soft-initialize request.
Definition: Commandable.cc:125
virtual bool do_resume(uint64_t, uint64_t)
Perform the resume transition.
Definition: Commandable.cc:254
bool start(art::RunID id, uint64_t timeout, uint64_t timestamp)
Processes the start transition.
Definition: Commandable.cc:30
virtual bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the reinitialize transition.
Definition: Commandable.cc:268
bool stop(uint64_t timeout, uint64_t timestamp)
Processes the stop transition.
Definition: Commandable.cc:49
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:226
bool shutdown(uint64_t timeout)
Processes the shutdown transition.
Definition: Commandable.cc:106