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