otsdaq  v2_01_00
ARTDAQCommandable.cc
1 #include "otsdaq-core/GatewaySupervisor/ARTDAQCommandable.h"
2 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
3 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
4 
5 ots::ARTDAQCommandable::ARTDAQCommandable(GatewaySupervisor * super)
6  : artdaq::Commandable()
7  , theSupervisor_(super)
8  , theCommander_(nullptr)
9 {}
10 
11 ots::ARTDAQCommandable::~ARTDAQCommandable()
12 {
13  if (theCommander_ != nullptr)
14  {
15  theCommander_->send_shutdown(0);
16  if (commanderThread_.joinable()) commanderThread_.join();
17  }
18 }
19 
20 void ots::ARTDAQCommandable::init(int commanderId, std::string commanderType)
21 {
22  fhicl::ParameterSet ps;
23  ps.put<int>("id", commanderId);
24  ps.put<std::string>("commanderPluginType", commanderType);
25 
26  theCommander_ = artdaq::MakeCommanderPlugin(ps, *this);
27  boost::thread::attributes attrs;
28  attrs.set_stack_size(4096 * 2000); // 8 MB
29  commanderThread_ = boost::thread(attrs, boost::bind(&artdaq::CommanderInterface::run_server, theCommander_.get()));
30 }
31 
32 bool ots::ARTDAQCommandable::do_initialize(fhicl::ParameterSet const & ps, uint64_t, uint64_t)
33 {
34  std::vector<std::string> parameters;
35  parameters.push_back(ps.get<std::string>("config_name"));
36 
37  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Initialize",
38  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
39  "ARTDAQCommandable", parameters);
40  if (ret == "")
41  ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Configure",
42  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
43  "ARTDAQCommandable", parameters);
44  report_string_ = ret;
45  return ret == "";
46 }
47 
48 bool ots::ARTDAQCommandable::do_start(art::RunID, uint64_t, uint64_t)
49 {
50  std::vector<std::string> parameters;
51  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Start",
52  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
53  "ARTDAQCommandable", parameters);
54  report_string_ = ret;
55  return ret == "";
56 }
57 
58 bool ots::ARTDAQCommandable::do_stop(uint64_t, uint64_t)
59 {
60  std::vector<std::string> parameters;
61  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Stop",
62  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
63  "ARTDAQCommandable", parameters);
64  report_string_ = ret;
65  return ret == "";
66 }
67 
68 bool ots::ARTDAQCommandable::do_pause(uint64_t, uint64_t)
69 {
70  std::vector<std::string> parameters;
71  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Pause",
72  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
73  "ARTDAQCommandable", parameters);
74  report_string_ = ret;
75  return ret == "";
76 }
77 
78 bool ots::ARTDAQCommandable::do_resume(uint64_t, uint64_t)
79 {
80  std::vector<std::string> parameters;
81  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Resume",
82  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
83  "ARTDAQCommandable", parameters);
84  report_string_ = ret;
85  return ret == "";
86 }
87 
89 {
90  std::vector<std::string> parameters;
91  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Halt",
92  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
93  "ARTDAQCommandable", parameters);
94  if (ret == "")
95  ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Shutdown",
96  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
97  "ARTDAQCommandable", parameters);
98  report_string_ = ret;
99  return ret == "";
100 }
101 
102 bool ots::ARTDAQCommandable::do_meta_command(std::string const & command, std::string const & args)
103 {
104  std::vector<std::string> parameters;
105  parameters.push_back(args);
106  auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, command,
107  theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
108  "ARTDAQCommandable", parameters);
109  report_string_ = ret;
110  return ret == "";
111 }
112 
bool do_shutdown(uint64_t) override
Perform the shutdown transition.
bool do_meta_command(std::string const &, std::string const &) override
Run a module-defined command with the given parameter string.
bool do_stop(uint64_t, uint64_t) override
Perform the stop transition.
bool do_start(art::RunID, uint64_t, uint64_t) override
Perform the start transition.
bool do_resume(uint64_t, uint64_t) override
Perform the resume transition.
bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Perform the initialize transition.
bool do_pause(uint64_t, uint64_t) override
Perform the pause transition.