artdaq  v3_00_01
DispatcherApp.cc
1 #include "artdaq/Application/DispatcherApp.hh"
2 #include "artdaq/Application/DispatcherCore.hh"
3 #include "artdaq-core/Utilities/ExceptionHandler.hh"
4 
5 #include <iostream>
6 
7 artdaq::DispatcherApp::DispatcherApp(int rank, std::string name) :
8  rank_(rank)
9  , name_(name)
10 {}
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, uint64_t)
17 {
18  report_string_ = "";
19 
20  //Dispatcher_ptr_.reset(nullptr);
21  if (Dispatcher_ptr_.get() == 0)
22  {
23  Dispatcher_ptr_.reset(new DispatcherCore(rank_, name_));
24  }
25  external_request_status_ = Dispatcher_ptr_->initialize(pset);
26  if (!external_request_status_)
27  {
28  report_string_ = "Error initializing ";
29  report_string_.append(name_ + " ");
30  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
31  }
32 
33  return external_request_status_;
34 }
35 
36 bool artdaq::DispatcherApp::do_start(art::RunID id, uint64_t, uint64_t)
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(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, uint64_t)
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(name_ + ".");
60  }
61 
62  return external_request_status_;
63 }
64 
65 bool artdaq::DispatcherApp::do_pause(uint64_t, uint64_t)
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(name_ + ".");
73  }
74  return external_request_status_;
75 }
76 
77 bool artdaq::DispatcherApp::do_resume(uint64_t, uint64_t)
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(name_ + ".");
85  }
86 
87  return external_request_status_;
88 }
89 
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(name_ + ".");
98  }
99 
100  return external_request_status_;
101 }
102 
103 bool artdaq::DispatcherApp::do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
104 {
105  return true;
106 }
107 
108 bool artdaq::DispatcherApp::do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
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  else { return "Success"; }
122  }
123 
126  //if (report_string_.length() > 0) {
127  // resultString.append("*** Overall status message:\r\n");
128  // resultString.append(report_string_ + "\r\n");
129  // resultString.append("*** Requested report response:\r\n");
130  //}
131 
132  // pass the request to the DispatcherCore instance, if it's available
133  if (Dispatcher_ptr_.get() != 0)
134  {
135  resultString.append(Dispatcher_ptr_->report(which));
136  }
137  else
138  {
139  resultString.append("This Dispatcher has not yet been initialized and ");
140  resultString.append("therefore can not provide reporting.");
141  }
142 
143  return resultString;
144 }
145 
146 std::string artdaq::DispatcherApp::register_monitor(fhicl::ParameterSet const& info)
147 {
148  TLOG_DEBUG(name_) << "DispatcherApp::register_monitor called with argument \"" << info.to_string() << "\"" << TLOG_ENDL;
149 
150  if (Dispatcher_ptr_)
151  {
152  try
153  {
154  return Dispatcher_ptr_->register_monitor(info);
155  }
156  catch (...)
157  {
158  ExceptionHandler(ExceptionHandlerRethrow::no,
159  "Error in call to DispatcherCore's register_monitor function");
160 
161  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";
162  }
163  }
164  else
165  {
166  return "Error in artdaq::DispatcherApp::register_monitor: DispatcherCore object wasn't initialized";
167  }
168 }
169 
170 
171 std::string artdaq::DispatcherApp::unregister_monitor(std::string const& label)
172 {
173  TLOG_DEBUG(name_) << "DispatcherApp::unregister_monitor called with argument \"" << label << "\"" << TLOG_ENDL;
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.
DispatcherCore implements the state machine for the Dispatcher artdaq application. DispatcherCore processes incoming events in one of three roles: Data Logger, Online Monitor, or Dispatcher.
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(int rank, std::string name)
DispatcherApp Constructor.
Definition: DispatcherApp.cc:7
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 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.