1 #include "TRACE/tracemf.h"
2 #include "artdaq/DAQdata/Globals.hh"
3 #define TRACE_NAME "RoutingManagerApp"
5 #include "artdaq/Application/RoutingManagerApp.hh"
7 #include <boost/bind.hpp>
8 #include <boost/exception/all.hpp>
9 #include <boost/lexical_cast.hpp>
10 #include <boost/thread.hpp>
32 routing_manager_ptr_.reset(
nullptr);
33 routing_manager_ptr_ = std::make_unique<RoutingManagerCore>();
35 if (!external_request_status_)
39 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
48 external_request_status_ = routing_manager_ptr_->start(
id, timeout, timestamp);
49 if (!external_request_status_)
51 report_string_ =
"Error starting ";
52 report_string_.append(app_name +
" ");
53 report_string_.append(
"for run number ");
54 report_string_.append(boost::lexical_cast<std::string>(
id.run()));
55 report_string_.append(
", timeout ");
56 report_string_.append(boost::lexical_cast<std::string>(timeout));
57 report_string_.append(
", timestamp ");
58 report_string_.append(boost::lexical_cast<std::string>(timestamp));
59 report_string_.append(
".");
62 boost::thread::attributes attrs;
63 attrs.set_stack_size(4096 * 2000);
68 snprintf(tname,
sizeof(tname) - 1,
"%d-Routing", my_rank);
69 tname[
sizeof(tname) - 1] =
'\0';
70 auto handle = routing_manager_thread_.native_handle();
71 pthread_setname_np(handle, tname);
73 catch (
const boost::exception& e)
75 TLOG(TLVL_ERROR) <<
"Caught boost::exception starting RoutingManagerCore thread: " << boost::diagnostic_information(e) <<
", errno=" << errno;
76 std::cerr <<
"Caught boost::exception starting RoutingManagerCore thread: " << boost::diagnostic_information(e) <<
", errno=" << errno << std::endl;
80 return external_request_status_;
86 external_request_status_ = routing_manager_ptr_->stop(timeout, timestamp);
87 if (!external_request_status_)
89 report_string_ =
"Error stopping ";
90 report_string_.append(app_name +
".");
94 if (routing_manager_thread_.joinable())
96 routing_manager_thread_.join();
99 TLOG(TLVL_DEBUG + 32, app_name +
"App") <<
"do_stop(uint64_t, uint64_t): "
100 <<
"Number of table entries sent = " << routing_manager_ptr_->get_update_count()
103 return external_request_status_;
109 external_request_status_ = routing_manager_ptr_->pause(timeout, timestamp);
110 if (!external_request_status_)
112 report_string_ =
"Error pausing ";
113 report_string_.append(app_name +
".");
115 if (routing_manager_thread_.joinable())
117 routing_manager_thread_.join();
120 TLOG(TLVL_DEBUG + 32, app_name +
"App") <<
"do_pause(uint64_t, uint64_t): "
121 <<
"Number of table entries sent = " << routing_manager_ptr_->get_update_count()
124 return external_request_status_;
130 external_request_status_ = routing_manager_ptr_->resume(timeout, timestamp);
131 if (!external_request_status_)
133 report_string_ =
"Error resuming ";
134 report_string_.append(app_name +
".");
137 boost::thread::attributes attrs;
138 attrs.set_stack_size(4096 * 2000);
140 TLOG(TLVL_INFO) <<
"Starting Routing Manager thread";
145 snprintf(tname,
sizeof(tname) - 1,
"%d-Routing", my_rank);
146 tname[
sizeof(tname) - 1] =
'\0';
147 auto handle = routing_manager_thread_.native_handle();
148 pthread_setname_np(handle, tname);
150 catch (boost::exception
const& e)
152 TLOG(TLVL_ERROR) <<
"Exception encountered starting Routing Manager thread: " << boost::diagnostic_information(e) <<
", errno=" << errno;
153 std::cerr <<
"Exception encountered starting Routing Manager thread: " << boost::diagnostic_information(e) <<
", errno=" << errno << std::endl;
156 TLOG(TLVL_INFO) <<
"Started Routing Manager thread";
158 return external_request_status_;
164 external_request_status_ = routing_manager_ptr_->shutdown(timeout);
165 if (!external_request_status_)
167 report_string_ =
"Error shutting down ";
168 report_string_.append(app_name +
".");
170 return external_request_status_;
176 external_request_status_ = routing_manager_ptr_->soft_initialize(pset, timeout, timestamp);
177 if (!external_request_status_)
179 report_string_ =
"Error soft-initializing ";
180 report_string_.append(app_name +
" ");
181 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
183 return external_request_status_;
188 external_request_status_ = routing_manager_ptr_->reinitialize(pset, timeout, timestamp);
189 if (!external_request_status_)
191 report_string_ =
"Error reinitializing ";
192 report_string_.append(app_name +
" ");
193 report_string_.append(
"with ParameterSet = \"" + pset.to_string() +
"\".");
195 return external_request_status_;
200 TLOG(TLVL_DEBUG + 32, app_name +
"App") <<
"Booted state entry action called.";
206 routing_manager_ptr_.reset(
nullptr);
211 std::string resultString;
214 if (which ==
"transition_status")
216 if (report_string_.length() > 0) {
return report_string_; }
230 if (routing_manager_ptr_ !=
nullptr)
232 resultString.append(routing_manager_ptr_->report(which));
236 resultString.append(
"This RoutingManager has not yet been initialized and ");
237 resultString.append(
"therefore can not provide reporting.");
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.
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 "Booted" state.
std::string report(std::string const &) const override
If which is "transition_status", report the status of the last transition. Otherwise pass through to ...
std::string report_string_
Status information about the last command.
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.