artdaq  v3_09_00
RoutingManagerApp.cc
1 #define TRACE_NAME "RoutingManagerApp"
2 
3 #include <memory>
4 
5 #include "artdaq/Application/RoutingManagerApp.hh"
6 
11 
12 // *******************************************************************
13 // *** The following methods implement the state machine operations.
14 // *******************************************************************
15 
16 bool artdaq::RoutingManagerApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
17 {
18  report_string_ = "";
20 
21  // in the following block, we first destroy the existing RoutingManager
22  // instance, then create a new one. Doing it in one step does not
23  // produce the desired result since that creates a new instance and
24  // then deletes the old one, and we need the opposite order.
25  routing_manager_ptr_.reset(nullptr);
26  routing_manager_ptr_ = std::make_unique<RoutingManagerCore>();
27  external_request_status_ = routing_manager_ptr_->initialize(pset, timeout, timestamp);
28  if (!external_request_status_)
29  {
30  report_string_ = "Error initializing ";
31  report_string_.append(app_name + " ");
32  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
33  }
34 
36 }
37 
38 bool artdaq::RoutingManagerApp::do_start(art::RunID id, uint64_t timeout, uint64_t timestamp)
39 {
40  report_string_ = "";
41  external_request_status_ = routing_manager_ptr_->start(id, timeout, timestamp);
42  if (!external_request_status_)
43  {
44  report_string_ = "Error starting ";
45  report_string_.append(app_name + " ");
46  report_string_.append("for run number ");
47  report_string_.append(boost::lexical_cast<std::string>(id.run()));
48  report_string_.append(", timeout ");
49  report_string_.append(boost::lexical_cast<std::string>(timeout));
50  report_string_.append(", timestamp ");
51  report_string_.append(boost::lexical_cast<std::string>(timestamp));
52  report_string_.append(".");
53  }
54 
55  boost::thread::attributes attrs;
56  attrs.set_stack_size(4096 * 2000); // 8 MB
57  try
58  {
59  routing_manager_thread_ = boost::thread(attrs, boost::bind(&RoutingManagerCore::process_event_table, routing_manager_ptr_.get()));
60  }
61  catch (const boost::exception& e)
62  {
63  TLOG(TLVL_ERROR) << "Caught boost::exception starting RoutingManagerCore thread: " << boost::diagnostic_information(e) << ", errno=" << errno;
64  std::cerr << "Caught boost::exception starting RoutingManagerCore thread: " << boost::diagnostic_information(e) << ", errno=" << errno << std::endl;
65  exit(5);
66  }
67 
68  return external_request_status_;
69 }
70 
71 bool artdaq::RoutingManagerApp::do_stop(uint64_t timeout, uint64_t timestamp)
72 {
73  report_string_ = "";
74  external_request_status_ = routing_manager_ptr_->stop(timeout, timestamp);
75  if (!external_request_status_)
76  {
77  report_string_ = "Error stopping ";
78  report_string_.append(app_name + ".");
79  return false;
80  }
81 
82  if (routing_manager_thread_.joinable())
83  {
84  routing_manager_thread_.join();
85  }
86 
87  TLOG_DEBUG(app_name + "App") << "do_stop(uint64_t, uint64_t): "
88  << "Number of table entries sent = " << routing_manager_ptr_->get_update_count()
89  << ".";
90 
91  return external_request_status_;
92 }
93 
94 bool artdaq::RoutingManagerApp::do_pause(uint64_t timeout, uint64_t timestamp)
95 {
96  report_string_ = "";
97  external_request_status_ = routing_manager_ptr_->pause(timeout, timestamp);
98  if (!external_request_status_)
99  {
100  report_string_ = "Error pausing ";
101  report_string_.append(app_name + ".");
102  }
103  if (routing_manager_thread_.joinable())
104  {
105  routing_manager_thread_.join();
106  }
107 
108  TLOG_DEBUG(app_name + "App") << "do_pause(uint64_t, uint64_t): "
109  << "Number of table entries sent = " << routing_manager_ptr_->get_update_count()
110  << ".";
111 
112  return external_request_status_;
113 }
114 
115 bool artdaq::RoutingManagerApp::do_resume(uint64_t timeout, uint64_t timestamp)
116 {
117  report_string_ = "";
118  external_request_status_ = routing_manager_ptr_->resume(timeout, timestamp);
119  if (!external_request_status_)
120  {
121  report_string_ = "Error resuming ";
122  report_string_.append(app_name + ".");
123  }
124 
125  boost::thread::attributes attrs;
126  attrs.set_stack_size(4096 * 2000); // 8000 KB
127 
128  TLOG(TLVL_INFO) << "Starting Routing Manager thread";
129  try
130  {
131  routing_manager_thread_ = boost::thread(attrs, boost::bind(&RoutingManagerCore::process_event_table, routing_manager_ptr_.get()));
132  }
133  catch (boost::exception const& e)
134  {
135  std::cerr << "Exception encountered starting Routing Manager thread: " << boost::diagnostic_information(e) << ", errno=" << errno << std::endl;
136  exit(3);
137  }
138  TLOG(TLVL_INFO) << "Started Routing Manager thread";
139 
140  return external_request_status_;
141 }
142 
144 {
145  report_string_ = "";
146  external_request_status_ = routing_manager_ptr_->shutdown(timeout);
147  if (!external_request_status_)
148  {
149  report_string_ = "Error shutting down ";
150  report_string_.append(app_name + ".");
151  }
152  return external_request_status_;
153 }
154 
155 bool artdaq::RoutingManagerApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
156 {
157  report_string_ = "";
158  external_request_status_ = routing_manager_ptr_->soft_initialize(pset, timeout, timestamp);
159  if (!external_request_status_)
160  {
161  report_string_ = "Error soft-initializing ";
162  report_string_.append(app_name + " ");
163  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
164  }
165  return external_request_status_;
166 }
167 
168 bool artdaq::RoutingManagerApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
169 {
170  external_request_status_ = routing_manager_ptr_->reinitialize(pset, timeout, timestamp);
171  if (!external_request_status_)
172  {
173  report_string_ = "Error reinitializing ";
174  report_string_.append(app_name + " ");
175  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
176  }
177  return external_request_status_;
178 }
179 
181 {
182  TLOG_DEBUG(app_name + "App") << "Booted state entry action called.";
183 
184  // the destruction of any existing RoutingManagerCore has to happen in the
185  // Booted Entry action rather than the Initialized Exit action because the
186  // Initialized Exit action is only called after the "init" transition guard
187  // condition is executed.
188  routing_manager_ptr_.reset(nullptr);
189 }
190 
191 std::string artdaq::RoutingManagerApp::report(std::string const& which) const
192 {
193  std::string resultString;
194 
195  // if all that is requested is the latest state change result, return it
196  if (which == "transition_status")
197  {
198  if (report_string_.length() > 0) { return report_string_; }
199 
200  return "Success";
201  }
202 
205  //if (report_string_.length() > 0) {
206  // resultString.append("*** Overall status message:\r\n");
207  // resultString.append(report_string_ + "\r\n");
208  // resultString.append("*** Requested report response:\r\n");
209  //}
210 
211  // pass the request to the RoutingManagerCore instance, if it's available
212  if (routing_manager_ptr_ != nullptr)
213  {
214  resultString.append(routing_manager_ptr_->report(which));
215  }
216  else
217  {
218  resultString.append("This RoutingManager has not yet been initialized and ");
219  resultString.append("therefore can not provide reporting.");
220  }
221 
222  return resultString;
223 }
bool do_resume(uint64_t timeout, uint64_t timestamp) override
Resume the RoutingManagerCore.
bool do_shutdown(uint64_t timeout) override
Shutdown the RoutingManagerCore.
bool do_stop(uint64_t timeout, uint64_t timestamp) override
Stop the RoutingManagerCore.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Initialize the RoutingManagerCore.
bool external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:312
bool do_soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Soft-Initialize the RoutingManagerCore.
bool do_start(art::RunID id, uint64_t timeout, uint64_t timestamp) override
Start the RoutingManagerCore.
void BootedEnter() override
Action taken upon entering the &quot;Booted&quot; state.
std::string report(std::string const &) const override
If which is &quot;transition_status&quot;, report the status of the last transition. Otherwise pass through to ...
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:313
bool do_pause(uint64_t timeout, uint64_t timestamp) override
Pause the RoutingManagerCore.
void process_event_table()
Main loop of the RoutingManagerCore. Determines when to send the next table update, asks the RoutingManagerPolicy for the table to send, and sends it.
RoutingManagerApp()
RoutingManagerApp Constructor.
bool do_reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Reinitialize the RoutingManagerCore.