artdaq  v3_07_01
DataLoggerApp.cc
1 #include "artdaq/DAQdata/Globals.hh" // include these 2 first -
2 #define TRACE_NAME (app_name + "_DataLoggerApp").c_str()
3 
4 #include "artdaq-core/Utilities/ExceptionHandler.hh"
5 #include "artdaq/Application/DataLoggerApp.hh"
6 #include "artdaq/Application/DataLoggerCore.hh"
7 
8 #include <iostream>
9 
11 {
12 }
13 
14 // *******************************************************************
15 // *** The following methods implement the state machine operations.
16 // *******************************************************************
17 
18 bool artdaq::DataLoggerApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t)
19 {
20  report_string_ = "";
21 
22  //DataLogger_ptr_.reset(nullptr);
23  if (DataLogger_ptr_.get() == 0)
24  {
25  DataLogger_ptr_.reset(new DataLoggerCore());
26  }
27  external_request_status_ = DataLogger_ptr_->initialize(pset);
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 
35  return external_request_status_;
36 }
37 
38 bool artdaq::DataLoggerApp::do_start(art::RunID id, uint64_t, uint64_t)
39 {
40  report_string_ = "";
41  external_request_status_ = DataLogger_ptr_->start(id);
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(".");
49  }
50 
51  return external_request_status_;
52 }
53 
54 bool artdaq::DataLoggerApp::do_stop(uint64_t, uint64_t)
55 {
56  report_string_ = "";
57  external_request_status_ = DataLogger_ptr_->stop();
58  if (!external_request_status_)
59  {
60  report_string_ = "Error stopping ";
61  report_string_.append(app_name + ".");
62  }
63 
64  return external_request_status_;
65 }
66 
67 bool artdaq::DataLoggerApp::do_pause(uint64_t, uint64_t)
68 {
69  report_string_ = "";
70  external_request_status_ = DataLogger_ptr_->pause();
71  if (!external_request_status_)
72  {
73  report_string_ = "Error pausing ";
74  report_string_.append(app_name + ".");
75  }
76 
77  return external_request_status_;
78 }
79 
80 bool artdaq::DataLoggerApp::do_resume(uint64_t, uint64_t)
81 {
82  report_string_ = "";
83  external_request_status_ = DataLogger_ptr_->resume();
84  if (!external_request_status_)
85  {
86  report_string_ = "Error resuming ";
87  report_string_.append(app_name + ".");
88  }
89 
90  return external_request_status_;
91 }
92 
94 {
95  report_string_ = "";
96  external_request_status_ = DataLogger_ptr_->shutdown();
97  if (!external_request_status_)
98  {
99  report_string_ = "Error shutting down ";
100  report_string_.append(app_name + ".");
101  }
102 
103  return external_request_status_;
104 }
105 
106 bool artdaq::DataLoggerApp::do_soft_initialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
107 {
108  return true;
109 }
110 
111 bool artdaq::DataLoggerApp::do_reinitialize(fhicl::ParameterSet const&, uint64_t, uint64_t)
112 {
113  return true;
114 }
115 
116 std::string artdaq::DataLoggerApp::report(std::string const& which) const
117 {
118  std::string resultString;
119 
120  // if all that is requested is the latest state change result, return it
121  if (which == "transition_status")
122  {
123  if (report_string_.length() > 0) { return report_string_; }
124  else
125  {
126  return "Success";
127  }
128  }
129 
132  //if (report_string_.length() > 0) {
133  // resultString.append("*** Overall status message:\r\n");
134  // resultString.append(report_string_ + "\r\n");
135  // resultString.append("*** Requested report response:\r\n");
136  //}
137 
138  // pass the request to the DataLoggerCore instance, if it's available
139  if (DataLogger_ptr_.get() != 0)
140  {
141  resultString.append(DataLogger_ptr_->report(which));
142  }
143  else
144  {
145  resultString.append("This DataLogger has not yet been initialized and ");
146  resultString.append("therefore can not provide reporting.");
147  }
148 
149  return resultString;
150 }
151 
152 bool artdaq::DataLoggerApp::do_add_config_archive_entry(std::string const& key, std::string const& value)
153 {
154  report_string_ = "";
155  external_request_status_ = DataLogger_ptr_->add_config_archive_entry(key, value);
156  if (!external_request_status_)
157  {
158  report_string_ = "Error adding config entry with key ";
159  report_string_.append(key + " and value \"");
160  report_string_.append(value + "\" in");
161  report_string_.append(app_name + ".");
162  }
163 
164  return external_request_status_;
165 }
166 
168 {
169  report_string_ = "";
170  external_request_status_ = DataLogger_ptr_->clear_config_archive();
171  if (!external_request_status_)
172  {
173  report_string_ = "Error clearing the configuration archive in ";
174  report_string_.append(app_name + ".");
175  }
176 
177  return external_request_status_;
178 }
bool do_initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t) override
Initialize the DataLoggerCore.
DataLoggerApp()
DataLoggerApp Constructor.
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.
bool do_clear_config_archive() override
Clear the configuration archive list in the DataLoggerCore.
bool do_start(art::RunID id, uint64_t, uint64_t) override
Start the DataLoggerCore.
bool do_add_config_archive_entry(std::string const &, std::string const &) override
Add the specified configuration archive entry to 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.