artdaq  v3_09_00
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 #include <memory>
10 
12 
13 // *******************************************************************
14 // *** The following methods implement the state machine operations.
15 // *******************************************************************
16 
17 bool artdaq::DataLoggerApp::do_initialize(fhicl::ParameterSet const& pset, uint64_t /*unused*/, uint64_t /*unused*/)
18 {
19  report_string_ = "";
20 
21  //DataLogger_ptr_.reset(nullptr);
22  if (DataLogger_ptr_ == nullptr)
23  {
24  DataLogger_ptr_ = std::make_unique<DataLoggerCore>();
25  }
26  external_request_status_ = DataLogger_ptr_->initialize(pset);
28  {
29  report_string_ = "Error initializing ";
30  report_string_.append(app_name + " ");
31  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
32  }
33 
35 }
36 
37 bool artdaq::DataLoggerApp::do_start(art::RunID id, uint64_t /*unused*/, uint64_t /*unused*/)
38 {
39  report_string_ = "";
40  external_request_status_ = DataLogger_ptr_->start(id);
41  if (!external_request_status_)
42  {
43  report_string_ = "Error starting ";
44  report_string_.append(app_name + " ");
45  report_string_.append("for run number ");
46  report_string_.append(boost::lexical_cast<std::string>(id.run()));
47  report_string_.append(".");
48  }
49 
50  return external_request_status_;
51 }
52 
53 bool artdaq::DataLoggerApp::do_stop(uint64_t /*unused*/, uint64_t /*unused*/)
54 {
55  report_string_ = "";
56  external_request_status_ = DataLogger_ptr_->stop();
57  if (!external_request_status_)
58  {
59  report_string_ = "Error stopping ";
60  report_string_.append(app_name + ".");
61  }
62 
63  return external_request_status_;
64 }
65 
66 bool artdaq::DataLoggerApp::do_pause(uint64_t /*unused*/, uint64_t /*unused*/)
67 {
68  report_string_ = "";
69  external_request_status_ = DataLogger_ptr_->pause();
70  if (!external_request_status_)
71  {
72  report_string_ = "Error pausing ";
73  report_string_.append(app_name + ".");
74  }
75 
76  return external_request_status_;
77 }
78 
79 bool artdaq::DataLoggerApp::do_resume(uint64_t /*unused*/, uint64_t /*unused*/)
80 {
81  report_string_ = "";
82  external_request_status_ = DataLogger_ptr_->resume();
83  if (!external_request_status_)
84  {
85  report_string_ = "Error resuming ";
86  report_string_.append(app_name + ".");
87  }
88 
89  return external_request_status_;
90 }
91 
92 bool artdaq::DataLoggerApp::do_shutdown(uint64_t /*unused*/)
93 {
94  report_string_ = "";
95  external_request_status_ = DataLogger_ptr_->shutdown();
96  if (!external_request_status_)
97  {
98  report_string_ = "Error shutting down ";
99  report_string_.append(app_name + ".");
100  }
101 
102  return external_request_status_;
103 }
104 
105 bool artdaq::DataLoggerApp::do_soft_initialize(fhicl::ParameterSet const& /*unused*/, uint64_t /*unused*/, uint64_t /*unused*/)
106 {
107  return true;
108 }
109 
110 bool artdaq::DataLoggerApp::do_reinitialize(fhicl::ParameterSet const& /*unused*/, uint64_t /*unused*/, uint64_t /*unused*/)
111 {
112  return true;
113 }
114 
115 std::string artdaq::DataLoggerApp::report(std::string const& which) const
116 {
117  std::string resultString;
118 
119  // if all that is requested is the latest state change result, return it
120  if (which == "transition_status")
121  {
122  if (report_string_.length() > 0) { return report_string_; }
123 
124  return "Success";
125  }
126 
129  //if (report_string_.length() > 0) {
130  // resultString.append("*** Overall status message:\r\n");
131  // resultString.append(report_string_ + "\r\n");
132  // resultString.append("*** Requested report response:\r\n");
133  //}
134 
135  // pass the request to the DataLoggerCore instance, if it's available
136  if (DataLogger_ptr_ != nullptr)
137  {
138  resultString.append(DataLogger_ptr_->report(which));
139  }
140  else
141  {
142  resultString.append("This DataLogger has not yet been initialized and ");
143  resultString.append("therefore can not provide reporting.");
144  }
145 
146  return resultString;
147 }
148 
149 bool artdaq::DataLoggerApp::do_add_config_archive_entry(std::string const& key, std::string const& value)
150 {
151  report_string_ = "";
152  external_request_status_ = DataLogger_ptr_->add_config_archive_entry(key, value);
153  if (!external_request_status_)
154  {
155  report_string_ = "Error adding config entry with key ";
156  report_string_.append(key + " and value \"");
157  report_string_.append(value + "\" in");
158  report_string_.append(app_name + ".");
159  }
160 
161  return external_request_status_;
162 }
163 
165 {
166  report_string_ = "";
167  external_request_status_ = DataLogger_ptr_->clear_config_archive();
168  if (!external_request_status_)
169  {
170  report_string_ = "Error clearing the configuration archive in ";
171  report_string_.append(app_name + ".");
172  }
173 
174  return external_request_status_;
175 }
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 external_request_status_
Whether the last command succeeded.
Definition: Commandable.hh:312
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.
std::string report_string_
Status information about the last command.
Definition: Commandable.hh:313
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.