artdaq  v3_00_01
DataLoggerApp.cc
1 #include "artdaq/Application/DataLoggerApp.hh"
2 #include "artdaq/Application/DataLoggerCore.hh"
3 #include "artdaq-core/Utilities/ExceptionHandler.hh"
4 
5 #include <iostream>
6 
7 artdaq::DataLoggerApp::DataLoggerApp(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::DataLoggerApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
17 {
18  report_string_ = "";
19 
20  //DataLogger_ptr_.reset(nullptr);
21  if (DataLogger_ptr_.get() == 0)
22  {
23  DataLogger_ptr_.reset(new DataLoggerCore(rank_, name_));
24  }
25  external_request_status_ = DataLogger_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::DataLoggerApp::do_start(art::RunID id, uint64_t, uint64_t)
37 {
38  report_string_ = "";
39  external_request_status_ = DataLogger_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::DataLoggerApp::do_stop(uint64_t, uint64_t)
53 {
54  report_string_ = "";
55  external_request_status_ = DataLogger_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::DataLoggerApp::do_pause(uint64_t, uint64_t)
66 {
67  report_string_ = "";
68  external_request_status_ = DataLogger_ptr_->pause();
69  if (!external_request_status_)
70  {
71  report_string_ = "Error pausing ";
72  report_string_.append(name_ + ".");
73  }
74 
75  return external_request_status_;
76 }
77 
78 bool artdaq::DataLoggerApp::do_resume(uint64_t, uint64_t)
79 {
80  report_string_ = "";
81  external_request_status_ = DataLogger_ptr_->resume();
82  if (!external_request_status_)
83  {
84  report_string_ = "Error resuming ";
85  report_string_.append(name_ + ".");
86  }
87 
88  return external_request_status_;
89 }
90 
92 {
93  report_string_ = "";
94  external_request_status_ = DataLogger_ptr_->shutdown();
95  if (!external_request_status_)
96  {
97  report_string_ = "Error shutting down ";
98  report_string_.append(name_ + ".");
99  }
100 
101  return external_request_status_;
102 }
103 
104 bool artdaq::DataLoggerApp::do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
105 {
106  return true;
107 }
108 
109 bool artdaq::DataLoggerApp::do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
110 {
111  return true;
112 }
113 
114 std::string artdaq::DataLoggerApp::report(std::string const& which) const
115 {
116  std::string resultString;
117 
118  // if all that is requested is the latest state change result, return it
119  if (which == "transition_status")
120  {
121  if (report_string_.length() > 0) { return report_string_; }
122  else { return "Success"; }
123  }
124 
127  //if (report_string_.length() > 0) {
128  // resultString.append("*** Overall status message:\r\n");
129  // resultString.append(report_string_ + "\r\n");
130  // resultString.append("*** Requested report response:\r\n");
131  //}
132 
133  // pass the request to the DataLoggerCore instance, if it's available
134  if (DataLogger_ptr_.get() != 0)
135  {
136  resultString.append(DataLogger_ptr_->report(which));
137  }
138  else
139  {
140  resultString.append("This DataLogger has not yet been initialized and ");
141  resultString.append("therefore can not provide reporting.");
142  }
143 
144  return resultString;
145 }
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Initialize the DataLoggerCore.
bool do_shutdown(uint64_t) override
Shutdown the DataLoggerCore.
bool do_soft_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Soft-initialize the DataLoggerCore. No-Op.
bool do_resume(uint64_t, uint64_t) override
Resume the DataLoggerCore.
bool do_pause(uint64_t, uint64_t) override
Pause the DataLoggerCore.
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_reinitialize(fhicl::ParameterSet const &, uint64_t, uint64_t) override
Reinitialize the DataLoggerCore. No-Op.
DataLoggerApp(int rank, std::string name)
DataLoggerApp Constructor.
Definition: DataLoggerApp.cc:7
bool do_start(art::RunID id, uint64_t, uint64_t) override
Start the DataLoggerCore.
bool do_stop(uint64_t, uint64_t) override
Stop the DataLoggerCore.
DataLoggerCore implements the state machine for the DataLogger artdaq application. DataLoggerCore processes incoming events in one of three roles: Data Logger, Online Monitor, or Dispatcher.