artdaq  v3_00_03
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 {
8  my_rank = rank;
9  app_name = name;
10 }
11 
12 // *******************************************************************
13 // *** The following methods implement the state machine operations.
14 // *******************************************************************
15 
16 bool artdaq::BoardReaderApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
17 {
18  report_string_ = "";
19  external_request_status_ = true;
20 
21  // in the following block, we first destroy the existing BoardReader
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  TLOG_DEBUG(app_name + "App") << "Initializing first deleting old instance " << (void*)fragment_receiver_ptr_.get() << TLOG_ENDL;
26  fragment_receiver_ptr_.reset(nullptr);
27  fragment_receiver_ptr_.reset(new BoardReaderCore(*this));
28  TLOG_DEBUG(app_name + "App") << "Initializing new BoardReaderCore at " << (void*)fragment_receiver_ptr_.get() << " with pset " << pset.to_string() << TLOG_ENDL;
29  external_request_status_ = fragment_receiver_ptr_->initialize(pset, timeout, timestamp);
30  if (! external_request_status_)
31  {
32  report_string_ = "Error initializing ";
33  report_string_.append(app_name + " ");
34  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
35  }
36 
37  TLOG_DEBUG(app_name + "App") << "do_initialize(fhicl::ParameterSet, uint64_t, uint64_t): "
38  << "Done initializing." << TLOG_ENDL;
39  return external_request_status_;
40 }
41 
42 bool artdaq::BoardReaderApp::do_start(art::RunID id, uint64_t timeout, uint64_t timestamp)
43 {
44  report_string_ = "";
45  external_request_status_ = fragment_receiver_ptr_->start(id, timeout, timestamp);
46  if (! external_request_status_)
47  {
48  report_string_ = "Error starting ";
49  report_string_.append(app_name + " ");
50  report_string_.append("for run number ");
51  report_string_.append(boost::lexical_cast<std::string>(id.run()));
52  report_string_.append(", timeout ");
53  report_string_.append(boost::lexical_cast<std::string>(timeout));
54  report_string_.append(", timestamp ");
55  report_string_.append(boost::lexical_cast<std::string>(timestamp));
56  report_string_.append(".");
57  }
58 
59  boost::thread::attributes attrs;
60  attrs.set_stack_size(4096 * 2000); // 8 MB
61  fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
62  /*
63  fragment_processing_future_ =
64  std::async(std::launch::async, &BoardReaderCore::process_fragments,
65  fragment_receiver_ptr_.get());*/
66 
67  return external_request_status_;
68 }
69 
70 bool artdaq::BoardReaderApp::do_stop(uint64_t timeout, uint64_t timestamp)
71 {
72  report_string_ = "";
73  external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
74  if (! external_request_status_)
75  {
76  report_string_ = "Error stopping ";
77  report_string_.append(app_name + ".");
78  return false;
79  }
80 
81  int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
82  TLOG_DEBUG(app_name + "App") << "do_stop(uint64_t, uint64_t): "
83  << "Number of fragments sent = " << number_of_fragments_sent
84  << "." << TLOG_ENDL;
85 
86  return external_request_status_;
87 }
88 
89 bool artdaq::BoardReaderApp::do_pause(uint64_t timeout, uint64_t timestamp)
90 {
91  report_string_ = "";
92  external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
93  if (! external_request_status_)
94  {
95  report_string_ = "Error pausing ";
96  report_string_.append(app_name + ".");
97  }
98 
99  int number_of_fragments_sent = fragment_receiver_ptr_->GetFragmentsProcessed();
100  TLOG_DEBUG(app_name + "App") << "do_pause(uint64_t, uint64_t): "
101  << "Number of fragments sent = " << number_of_fragments_sent
102  << "." << TLOG_ENDL;
103 
104  return external_request_status_;
105 }
106 
107 bool artdaq::BoardReaderApp::do_resume(uint64_t timeout, uint64_t timestamp)
108 {
109  report_string_ = "";
110  external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
111  if (! external_request_status_)
112  {
113  report_string_ = "Error resuming ";
114  report_string_.append(app_name + ".");
115  }
116 
117  boost::thread::attributes attrs;
118  attrs.set_stack_size(4096 * 2000); // 8 MB
119  fragment_processing_thread_ = boost::thread(attrs, boost::bind(&BoardReaderCore::process_fragments, fragment_receiver_ptr_.get()));
120 /*
121  fragment_processing_future_ =
122  std::async(std::launch::async, &BoardReaderCore::process_fragments,
123  fragment_receiver_ptr_.get());*/
124 
125  return external_request_status_;
126 }
127 
129 {
130  report_string_ = "";
131  external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
132  if (! external_request_status_)
133  {
134  report_string_ = "Error shutting down ";
135  report_string_.append(app_name + ".");
136  }
137  return external_request_status_;
138 }
139 
140 bool artdaq::BoardReaderApp::do_soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
141 {
142  report_string_ = "";
143  external_request_status_ = fragment_receiver_ptr_->soft_initialize(pset, timeout, timestamp);
144  if (! external_request_status_)
145  {
146  report_string_ = "Error soft-initializing ";
147  report_string_.append(app_name + " ");
148  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
149  }
150  return external_request_status_;
151 }
152 
153 bool artdaq::BoardReaderApp::do_reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp)
154 {
155  external_request_status_ = fragment_receiver_ptr_->reinitialize(pset, timeout, timestamp);
156  if (! external_request_status_)
157  {
158  report_string_ = "Error reinitializing ";
159  report_string_.append(app_name + " ");
160  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
161  }
162  return external_request_status_;
163 }
164 
166 {
167  TLOG_DEBUG(app_name + "App") << "Booted state entry action called." << TLOG_ENDL;
168 
169  // the destruction of any existing BoardReaderCore has to happen in the
170  // Booted Entry action rather than the Initialized Exit action because the
171  // Initialized Exit action is only called after the "init" transition guard
172  // condition is executed.
173  fragment_receiver_ptr_.reset(nullptr);
174 }
175 
176 bool artdaq::BoardReaderApp::do_meta_command(std::string const& command, std::string const& arg)
177 {
178  external_request_status_ = fragment_receiver_ptr_->metaCommand(command, arg);
179  if (!external_request_status_)
180  {
181  report_string_ = "Error running meta-command on ";
182  report_string_.append(app_name + " ");
183  report_string_.append("with command = \"" + command + "\", arg = \"" + arg + "\".");
184  }
185  return external_request_status_;
186 }
187 
188 std::string artdaq::BoardReaderApp::report(std::string const& which) const
189 {
190  std::string resultString;
191 
192  // if all that is requested is the latest state change result, return it
193  if (which == "transition_status")
194  {
195  if (report_string_.length() > 0) { return report_string_; }
196  else { return "Success"; }
197  }
198 
201  //if (report_string_.length() > 0) {
202  // resultString.append("*** Overall status message:\r\n");
203  // resultString.append(report_string_ + "\r\n");
204  // resultString.append("*** Requested report response:\r\n");
205  //}
206 
207  // pass the request to the BoardReaderCore instance, if it's available
208  if (fragment_receiver_ptr_.get() != 0)
209  {
210  resultString.append(fragment_receiver_ptr_->report(which));
211  }
212  else
213  {
214  resultString.append("This BoardReader has not yet been initialized and ");
215  resultString.append("therefore can not provide reporting.");
216  }
217 
218  return resultString;
219 }
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_meta_command(std::string const &command, std::string const &arg) override
Perform a user-defined command (passed to CommandableFragmentGenerator)
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.