otsdaq  v2_03_00
ARTDAQCommandable.cc
1 #include "otsdaq-core/GatewaySupervisor/ARTDAQCommandable.h"
2 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
3 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
4 
5 ots::ARTDAQCommandable::ARTDAQCommandable(GatewaySupervisor* super)
6  : artdaq::Commandable(), theSupervisor_(super), theCommander_(nullptr)
7 {
8 }
9 
10 ots::ARTDAQCommandable::~ARTDAQCommandable()
11 {
12  if(theCommander_ != nullptr)
13  {
14  theCommander_->send_shutdown(0);
15  if(commanderThread_.joinable())
16  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(
30  attrs, boost::bind(&artdaq::CommanderInterface::run_server, theCommander_.get()));
31 }
32 
33 bool ots::ARTDAQCommandable::do_initialize(fhicl::ParameterSet const& ps,
34  uint64_t,
35  uint64_t)
36 {
37  std::vector<std::string> parameters;
38  parameters.push_back(ps.get<std::string>("config_name"));
39 
40  auto ret = theSupervisor_->attemptStateMachineTransition(
41  nullptr,
42  nullptr,
43  "Initialize",
44  theSupervisor_->activeStateMachineName_,
45  theSupervisor_->activeStateMachineWindowName_,
46  "ARTDAQCommandable",
47  parameters);
48  if(ret == "")
49  ret = theSupervisor_->attemptStateMachineTransition(
50  nullptr,
51  nullptr,
52  "Configure",
53  theSupervisor_->activeStateMachineName_,
54  theSupervisor_->activeStateMachineWindowName_,
55  "ARTDAQCommandable",
56  parameters);
57  report_string_ = ret;
58  return ret == "";
59 }
60 
61 bool ots::ARTDAQCommandable::do_start(art::RunID, uint64_t, uint64_t)
62 {
63  std::vector<std::string> parameters;
64  auto ret = theSupervisor_->attemptStateMachineTransition(
65  nullptr,
66  nullptr,
67  "Start",
68  theSupervisor_->activeStateMachineName_,
69  theSupervisor_->activeStateMachineWindowName_,
70  "ARTDAQCommandable",
71  parameters);
72  report_string_ = ret;
73  return ret == "";
74 }
75 
76 bool ots::ARTDAQCommandable::do_stop(uint64_t, uint64_t)
77 {
78  std::vector<std::string> parameters;
79  auto ret = theSupervisor_->attemptStateMachineTransition(
80  nullptr,
81  nullptr,
82  "Stop",
83  theSupervisor_->activeStateMachineName_,
84  theSupervisor_->activeStateMachineWindowName_,
85  "ARTDAQCommandable",
86  parameters);
87  report_string_ = ret;
88  return ret == "";
89 }
90 
91 bool ots::ARTDAQCommandable::do_pause(uint64_t, uint64_t)
92 {
93  std::vector<std::string> parameters;
94  auto ret = theSupervisor_->attemptStateMachineTransition(
95  nullptr,
96  nullptr,
97  "Pause",
98  theSupervisor_->activeStateMachineName_,
99  theSupervisor_->activeStateMachineWindowName_,
100  "ARTDAQCommandable",
101  parameters);
102  report_string_ = ret;
103  return ret == "";
104 }
105 
106 bool ots::ARTDAQCommandable::do_resume(uint64_t, uint64_t)
107 {
108  std::vector<std::string> parameters;
109  auto ret = theSupervisor_->attemptStateMachineTransition(
110  nullptr,
111  nullptr,
112  "Resume",
113  theSupervisor_->activeStateMachineName_,
114  theSupervisor_->activeStateMachineWindowName_,
115  "ARTDAQCommandable",
116  parameters);
117  report_string_ = ret;
118  return ret == "";
119 }
120 
122 {
123  std::vector<std::string> parameters;
124  auto ret = theSupervisor_->attemptStateMachineTransition(
125  nullptr,
126  nullptr,
127  "Halt",
128  theSupervisor_->activeStateMachineName_,
129  theSupervisor_->activeStateMachineWindowName_,
130  "ARTDAQCommandable",
131  parameters);
132  if(ret == "")
133  ret = theSupervisor_->attemptStateMachineTransition(
134  nullptr,
135  nullptr,
136  "Shutdown",
137  theSupervisor_->activeStateMachineName_,
138  theSupervisor_->activeStateMachineWindowName_,
139  "ARTDAQCommandable",
140  parameters);
141  report_string_ = ret;
142  return ret == "";
143 }
144 
145 bool ots::ARTDAQCommandable::do_meta_command(std::string const& command,
146  std::string const& args)
147 {
148  std::vector<std::string> parameters;
149  parameters.push_back(args);
150  auto ret = theSupervisor_->attemptStateMachineTransition(
151  nullptr,
152  nullptr,
153  command,
154  theSupervisor_->activeStateMachineName_,
155  theSupervisor_->activeStateMachineWindowName_,
156  "ARTDAQCommandable",
157  parameters);
158  report_string_ = ret;
159  return ret == "";
160 }
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.