artdaq  v3_09_01
DispatcherApp.cc
1 #define TRACE_NAME "DispatcherApp"
2 
3 #include "artdaq/Application/DispatcherApp.hh"
4 #include "artdaq-core/Utilities/ExceptionHandler.hh"
5 #include "artdaq/Application/DispatcherCore.hh"
6 
7 #include <iostream>
8 #include <memory>
9 
11 
12 // *******************************************************************
13 // *** The following methods implement the state machine operations.
14 // *******************************************************************
15 
16 bool artdaq::DispatcherApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t /*unused*/, uint64_t /*unused*/)
17 {
18  report_string_ = "";
19 
20  //Dispatcher_ptr_.reset(nullptr);
21  if (Dispatcher_ptr_ == nullptr)
22  {
23  Dispatcher_ptr_ = std::make_unique<DispatcherCore>();
24  }
25  external_request_status_ = Dispatcher_ptr_->initialize(pset);
27  {
28  report_string_ = "Error initializing ";
29  report_string_.append(app_name + " ");
30  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
31  }
32 
34 }
35 
36 bool artdaq::DispatcherApp::do_start(art::RunID id, uint64_t /*unused*/, uint64_t /*unused*/)
37 {
38  report_string_ = "";
39  external_request_status_ = Dispatcher_ptr_->start(id);
40  if (!external_request_status_)
41  {
42  report_string_ = "Error starting ";
43  report_string_.append(app_name + " ");
44  report_string_.append("for run number ");
45  report_string_.append(boost::lexical_cast<std::string>(id.run()));
46  report_string_.append(".");
47  }
48 
49  return external_request_status_;
50 }
51 
52 bool artdaq::DispatcherApp::do_stop(uint64_t /*unused*/, uint64_t /*unused*/)
53 {
54  report_string_ = "";
55  external_request_status_ = Dispatcher_ptr_->stop();
56  if (!external_request_status_)
57  {
58  report_string_ = "Error stopping ";
59  report_string_.append(app_name + ".");
60  }
61 
62  return external_request_status_;
63 }
64 
65 bool artdaq::DispatcherApp::do_pause(uint64_t /*unused*/, uint64_t /*unused*/)
66 {
67  report_string_ = "";
68  external_request_status_ = Dispatcher_ptr_->pause();
69  if (!external_request_status_)
70  {
71  report_string_ = "Error pausing ";
72  report_string_.append(app_name + ".");
73  }
74  return external_request_status_;
75 }
76 
77 bool artdaq::DispatcherApp::do_resume(uint64_t /*unused*/, uint64_t /*unused*/)
78 {
79  report_string_ = "";
80  external_request_status_ = Dispatcher_ptr_->resume();
81  if (!external_request_status_)
82  {
83  report_string_ = "Error resuming ";
84  report_string_.append(app_name + ".");
85  }
86 
87  return external_request_status_;
88 }
89 
90 bool artdaq::DispatcherApp::do_shutdown(uint64_t /*unused*/)
91 {
92  report_string_ = "";
93  external_request_status_ = Dispatcher_ptr_->shutdown();
94  if (!external_request_status_)
95  {
96  report_string_ = "Error shutting down ";
97  report_string_.append(app_name + ".");
98  }
99 
100  return external_request_status_;
101 }
102 
103 bool artdaq::DispatcherApp::do_soft_initialize(fhicl::ParameterSet const& /*unused*/, uint64_t /*unused*/, uint64_t /*unused*/)
104 {
105  return true;
106 }
107 
108 bool artdaq::DispatcherApp::do_reinitialize(fhicl::ParameterSet const& /*unused*/, uint64_t /*unused*/, uint64_t /*unused*/)
109 {
110  return true;
111 }
112 
113 std::string artdaq::DispatcherApp::report(std::string const& which) const
114 {
115  std::string resultString;
116 
117  // if all that is requested is the latest state change result, return it
118  if (which == "transition_status")
119  {
120  if (report_string_.length() > 0) { return report_string_; }
121 
122  return "Success";
123  }
124 
127  //if (report_string_.length() > 0) {
128  // resultString.append("*** Overall status message:\r\n");
129  // resultString.append(report_string_ + "\r\n");
130  // resultString.append("*** Requested report response:\r\n");
131  //}
132 
133  // pass the request to the DispatcherCore instance, if it's available
134  if (Dispatcher_ptr_ != nullptr)
135  {
136  resultString.append(Dispatcher_ptr_->report(which));
137  }
138  else
139  {
140  resultString.append("This Dispatcher has not yet been initialized and ");
141  resultString.append("therefore can not provide reporting.");
142  }
143 
144  return resultString;
145 }
146 
147 std::string artdaq::DispatcherApp::register_monitor(fhicl::ParameterSet const& info)
148 {
149  TLOG(TLVL_DEBUG) << "DispatcherApp::register_monitor called with argument \"" << info.to_string() << "\"";
150 
151  if (Dispatcher_ptr_)
152  {
153  try
154  {
155  return Dispatcher_ptr_->register_monitor(info);
156  }
157  catch (...)
158  {
159  ExceptionHandler(ExceptionHandlerRethrow::no,
160  "Error in call to DispatcherCore's register_monitor function");
161 
162  return "Error in artdaq::DispatcherApp::register_monitor: an exception was thrown in the call to DispatcherCore::register_monitor, possibly due to a problem with the argument";
163  }
164  }
165  else
166  {
167  return "Error in artdaq::DispatcherApp::register_monitor: DispatcherCore object wasn't initialized";
168  }
169 }
170 
171 std::string artdaq::DispatcherApp::unregister_monitor(std::string const& label)
172 {
173  TLOG(TLVL_DEBUG) << "DispatcherApp::unregister_monitor called with argument \"" << label << "\"";
174 
175  if (Dispatcher_ptr_)
176  {
177  try
178  {
179  return Dispatcher_ptr_->unregister_monitor(label);
180  }
181  catch (...)
182  {
183  ExceptionHandler(ExceptionHandlerRethrow::no,
184  "Error in call to DispatcherCore's unregister_monitor function");
185 
186  return "Error in artdaq::DispatcherApp::unregister_monitor: an exception was thrown in the call to DispatcherCore::unregister_monitor, possibly due to a problem with the argument";
187  }
188  }
189  else
190  {
191  return "Error in artdaq::DispatcherApp::unregister_monitor: DispatcherCore object wasn't initialized";
192  }
193 }
bool do_start(art::RunID id, uint64_t, uint64_t) override
Start the DispatcherCore.
bool do_pause(uint64_t, uint64_t) override
Pause the DispatcherCore.
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:312
bool do_resume(uint64_t, uint64_t) override
Resume the DispatcherCore.
std::string unregister_monitor(std::string const &label) override
Remove an art Online Monitor from the DispatcherCore.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Initialize the DispatcherCore.
DispatcherApp()
DispatcherApp Constructor.
bool do_stop(uint64_t, uint64_t) override
Stop the DispatcherCore.
bool do_soft_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Soft-initialize the DispatcherCore. No-Op.
bool do_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Reinitialize the DispatcherCore. No-Op.
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:313
std::string register_monitor(fhicl::ParameterSet const &info) override
Register an art Online Monitor to the DispatcherCore.
std::string report(std::string const &which) const override
If which is &quot;transition_status&quot;, report the status of the last transition. Otherwise pass through to ...
bool do_shutdown(uint64_t) override
Shutdown the DispatcherCore.