artdaq  v3_00_01
BoardReaderApp.cc
1 #define TRACE_NAME "BoardReaderApp"
2 #include "tracemf.h"
3 #include "artdaq/Application/BoardReaderApp.hh"
4 
5 artdaq::BoardReaderApp::BoardReaderApp(int rank, std::string name)
6  : fragment_receiver_ptr_(nullptr)
7  , rank_(rank)
8  , name_(name)
9 {}
10 
11 // *******************************************************************
12 // *** The following methods implement the state machine operations.
13 // *******************************************************************
14 
15 bool artdaq::BoardReaderApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
16 {
17  report_string_ = "";
18  external_request_status_ = true;
19 
20  // in the following block, we first destroy the existing BoardReader
21  // instance, then create a new one. Doing it in one step does not
22  // produce the desired result since that creates a new instance and
23  // then deletes the old one, and we need the opposite order.
24  TLOG_DEBUG(name_ + "App") << "Initializing first deleting old instance " << (void*)fragment_receiver_ptr_.get() << TLOG_ENDL;
25  fragment_receiver_ptr_.reset(nullptr);
26  fragment_receiver_ptr_.reset(new BoardReaderCore(*this, rank_, name_));
27  TLOG_DEBUG(name_ + "App") << "Initializing new BoardReaderCore at " << (void*)fragment_receiver_ptr_.get() << " with pset " << pset.to_string() << TLOG_ENDL;
28  external_request_status_ = fragment_receiver_ptr_->initialize(pset, timeout, timestamp);
29  if (! external_request_status_)
30  {
31  report_string_ = "Error initializing ";
32  report_string_.append(name_ + " ");
33  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
34  }
35 
36  TLOG_DEBUG(name_ + "App") << "do_initialize(fhicl::ParameterSet, uint64_t, uint64_t): "
37  << "Done initializing." << TLOG_ENDL;
38  return external_request_status_;
39 }
40 
41 bool artdaq::BoardReaderApp::do_start(art::RunID id, uint64_t timeout, uint64_t timestamp)
42 {
43  report_string_ = "";
44  external_request_status_ = fragment_receiver_ptr_->start(id, timeout, timestamp);
45  if (! external_request_status_)
46  {
47  report_string_ = "Error starting ";
48  report_string_.append(name_ + " ");
49  report_string_.append("for run number ");
50  report_string_.append(boost::lexical_cast<std::string>(id.run()));
51  report_string_.append(", timeout ");
52  report_string_.append(boost::lexical_cast<std::string>(timeout));
53  report_string_.append(", timestamp ");
54  report_string_.append(boost::lexical_cast<std::string>(timestamp));
55  report_string_.append(".");
56  }
57 
58  boost::thread::attributes attrs;
59  attrs.set_stack_size(4096 * 2000); // 8 MB
60  fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
61  /*
62  fragment_processing_future_ =
63  std::async(std::launch::async, &BoardReaderCore::process_fragments,
64  fragment_receiver_ptr_.get());*/
65 
66  return external_request_status_;
67 }
68 
69 bool artdaq::BoardReaderApp::do_stop(uint64_t timeout, uint64_t timestamp)
70 {
71  report_string_ = "";
72  external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
73  if (! external_request_status_)
74  {
75  report_string_ = "Error stopping ";
76  report_string_.append(name_ + ".");
77  return false;
78  }
79 
80  int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
81  TLOG_DEBUG(name_ + "App") << "do_stop(uint64_t, uint64_t): "
82  << "Number of fragments sent = " << number_of_fragments_sent
83  << "." << TLOG_ENDL;
84 
85  return external_request_status_;
86 }
87 
88 bool artdaq::BoardReaderApp::do_pause(uint64_t timeout, uint64_t timestamp)
89 {
90  report_string_ = "";
91  external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
92  if (! external_request_status_)
93  {
94  report_string_ = "Error pausing ";
95  report_string_.append(name_ + ".");
96  }
97 
98  int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
99  TLOG_DEBUG(name_ + "App") << "do_pause(uint64_t, uint64_t): "
100  << "Number of fragments sent = " << number_of_fragments_sent
101  << "." << TLOG_ENDL;
102 
103  return external_request_status_;
104 }
105 
106 bool artdaq::BoardReaderApp::do_resume(uint64_t timeout, uint64_t timestamp)
107 {
108  report_string_ = "";
109  external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
110  if (! external_request_status_)
111  {
112  report_string_ = "Error resuming ";
113  report_string_.append(name_ + ".");
114  }
115 
116  boost::thread::attributes attrs;
117  attrs.set_stack_size(4096 * 2000); // 8 MB
118  fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
119 /*
120  fragment_processing_future_ =
121  std::async(std::launch::async, &BoardReaderCore::process_fragments,
122  fragment_receiver_ptr_.get());*/
123 
124  return external_request_status_;
125 }
126 
128 {
129  report_string_ = "";
130  external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
131  if (! external_request_status_)
132  {
133  report_string_ = "Error shutting down ";
134  report_string_.append(name_ + ".");
135  }
136  return external_request_status_;
137 }
138 
139 bool artdaq::BoardReaderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
140 {
141  report_string_ = "";
142  external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
143  if (! external_request_status_)
144  {
145  report_string_ = "Error soft-initializing ";
146  report_string_.append(name_ + " ");
147  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
148  }
149  return external_request_status_;
150 }
151 
152 bool artdaq::BoardReaderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
153 {
154  external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
155  if (! external_request_status_)
156  {
157  report_string_ = "Error reinitializing ";
158  report_string_.append(name_ + " ");
159  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
160  }
161  return external_request_status_;
162 }
163 
165 {
166  TLOG_DEBUG(name_ + "App") << "Booted state entry action called." << TLOG_ENDL;
167 
168  // the destruction of any existing BoardReaderCore has to happen in the
169  // Booted Entry action rather than the Initialized Exit action because the
170  // Initialized Exit action is only called after the "init" transition guard
171  // condition is executed.
172  fragment_receiver_ptr_.reset(nullptr);
173 }
174 
175 std::string artdaq::BoardReaderApp::report(std::string const& which) const
176 {
177  std::string resultString;
178 
179  // if all that is requested is the latest state change result, return it
180  if (which == "transition_status")
181  {
182  if (report_string_.length() > 0) { return report_string_; }
183  else { return "Success"; }
184  }
185 
188  //if (report_string_.length() > 0) {
189  // resultString.append("*** Overall status message:\r\n");
190  // resultString.append(report_string_ + "\r\n");
191  // resultString.append("*** Requested report response:\r\n");
192  //}
193 
194  // pass the request to the BoardReaderCore instance, if it's available
195  if (fragment_receiver_ptr_.get() != 0)
196  {
197  resultString.append(fragment_receiver_ptr_->report(which));
198  }
199  else
200  {
201  resultString.append("This BoardReader has not yet been initialized and ");
202  resultString.append("therefore can not provide reporting.");
203  }
204 
205  return resultString;
206 }
bool do_soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Soft-Initialize the BoardReaderCore.
bool do_resume(uint64_t timeout, uint64_t timestamp) override
Resume the BoardReaderCore.
bool do_stop(uint64_t timeout, uint64_t timestamp) override
Stop the BoardReaderCore.
BoardReaderCore implements the state machine for the BoardReader artdaq application. It contains a CommandableFragmentGenerator, which generates Fragments which are then sent to a DataSenderManager by BoardReaderCore.
bool do_shutdown(uint64_t timeout) override
Shutdown the BoardReaderCore.
bool do_reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Reinitialize the BoardReaderCore.
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 ...
void BootedEnter() override
Action taken upon entering the &quot;Booted&quot; state.
void process_fragments()
Main working loop of the BoardReaderCore.
bool do_start(art::RunID id, uint64_t timeout, uint64_t timestamp) override
Start the BoardReaderCore.
BoardReaderApp(int rank, std::string name)
BoardReaderApp Constructor.
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp) override
Initialize the BoardReaderCore.
bool do_pause(uint64_t timeout, uint64_t timestamp) override
Pause the BoardReaderCore.