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