tdaq-develop-2025-02-12
ARTDAQConsumerImpl.cc
1 
2 // #include "artdaq/Application/Commandable.hh"
3 // #include "fhiclcpp/make_ParameterSet.h"
4 // #include "otsdaq/DataManager/DataManager.h"
5 // #include "otsdaq/DataManager/DataManagerSingleton.h"
6 #include "otsdaq/DataProcessorPlugins/ARTDAQConsumer.h"
7 // #include "otsdaq/Macros/CoutMacros.h"
8 // #include "otsdaq/MessageFacility/MessageFacility.h"
9 
10 // #include <cstdint>
11 // #include <fstream>
12 // #include <iostream>
13 // #include <set>
14 
15 using namespace ots;
16 
17 // #define ARTDAQ_FCL_PATH std::string(__ENV__("USER_DATA")) + "/" + "ARTDAQConfigurations/" #define ARTDAQ_FILE_PREAMBLE "boardReader"
18 
19 //==============================================================================
20 ARTDAQConsumer::ARTDAQConsumer(std::string supervisorApplicationUID,
21  std::string bufferUID,
22  std::string processorUID,
23  const ConfigurationTree& theXDAQContextConfigTree,
24  const std::string& configurationPath)
25  : WorkLoop(processorUID)
26  , DataConsumer(supervisorApplicationUID, bufferUID, processorUID, LowConsumerPriority)
27  , ARTDAQReaderProcessorBase(supervisorApplicationUID,
28  bufferUID,
29  processorUID,
30  theXDAQContextConfigTree,
31  configurationPath)
35 {
36  __COUT__ << "ARTDAQ Consumer constructed." << __E__;
37  //__COUT__ << "Configuration string:-" <<
38  // theXDAQContextConfigTree.getNode(configurationPath).getNode("ConfigurationString").getValue<std::string>()
39  //<< "-" << __E__;
40  //
41  // std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE + "-";
42  // std::string uid =
43  // theXDAQContextConfigTree.getNode(configurationPath).getValue();
44  //
45  // __COUT__ << "uid: " << uid << __E__;
46  // for(unsigned int i = 0; i < uid.size(); ++i)
47  // if((uid[i] >= 'a' && uid[i] <= 'z') || (uid[i] >= 'A' && uid[i] <= 'Z') ||
48  // (uid[i] >= '0' && uid[i] <= '9')) // only allow alpha numeric in file name
49  // filename += uid[i];
50  // filename += ".fcl";
51  //
52  // __COUT__ << __E__;
53  // __COUT__ << __E__;
54  // __COUT__ << "filename: " << filename << __E__;
55  //
56  // std::string fileFclString;
57  // {
58  // std::ifstream in(filename, std::ios::in | std::ios::binary);
59  // if(in)
60  // {
61  // std::string contents;
62  // in.seekg(0, std::ios::end);
63  // fileFclString.resize(in.tellg());
64  // in.seekg(0, std::ios::beg);
65  // in.read(&fileFclString[0], fileFclString.size());
66  // in.close();
67  // }
68  // }
69  // //__COUT__ << fileFclString << __E__;
70  //
71  // // find fragment_receiver {
72  // // and insert e.g.,
73  // // SupervisorApplicationUID:"ARTDataManager0"
74  // // BufferUID:"ART_S0_DM0_DataBuffer0"
75  // // ProcessorUID:"ART_S0_DM0_DB0_ARTConsumer0"
76  // size_t fcli =
77  // fileFclString.find("fragment_receiver: {") + +strlen("fragment_receiver: {");
78  // if(fcli == std::string::npos)
79  // {
80  // __SS__ << "Could not find 'fragment_receiver: {' in Board Reader fcl string!"
81  // << __E__;
82  // __COUT__ << "\n" << ss.str();
83  // __SS_THROW__;
84  // }
85  //
86  // // get the parent IDs from configurationPath
87  // __COUT__ << "configurationPath " << configurationPath << __E__;
88  //
89  // std::string consumerID, bufferID, appID;
90  // unsigned int backSteps; // at 2, 4, and 7 are the important parent IDs
91  // size_t backi = -1, backj;
92  // backSteps = 7;
93  // for(unsigned int i = 0; i < backSteps; i++)
94  // {
95  // //__COUT__ << "backsteps: " << i+1 << __E__;
96  //
97  // backj = backi;
98  // backi = configurationPath.rfind('/', backi - 1);
99  //
100  // //__COUT__ << "backi:" << backi << " backj:" << backj << __E__;
101  // //__COUT__ << "substr: " << configurationPath.substr(backi+1,backj-backi-1) <<
102  // // __E__;
103  //
104  // if(i + 1 == 2)
105  // consumerID = configurationPath.substr(backi + 1, backj - backi - 1);
106  // else if(i + 1 == 4)
107  // bufferID = configurationPath.substr(backi + 1, backj - backi - 1);
108  // else if(i + 1 == 7)
109  // appID = configurationPath.substr(backi + 1, backj - backi - 1);
110  // }
111  //
112  // // insert parent IDs into fcl string
113  // fileFclString = fileFclString.substr(0, fcli) + "\n\t\t" +
114  // "SupervisorApplicationUID: \"" + appID + "\"\n\t\t" +
115  // "BufferUID: \"" + bufferID + "\"\n\t\t" + "ProcessorUID: \"" +
116  // consumerID + "\"\n" + fileFclString.substr(fcli);
117  //
118  // __COUT__ << fileFclString << __E__;
119  //
120  // fhicl::make_ParameterSet(fileFclString, fhiclConfiguration_);
121  //
122  // //
123  // fhicl::make_ParameterSet(theXDAQContextConfigTree.getNode(configurationPath).getNode("ConfigurationString").getValue<std::string>(),
124  // // fhiclConfiguration_);
125 }
126 
127 //==============================================================================
131 //{}
132 
133 //==============================================================================
135 {
136  halt();
137  __COUT__ << "Destructed." << __E__;
138 }
139 
142 //{
143 // name_ = "BoardReader_" + DataConsumer::processorUID_;
144 // configure(rank);
145 //}
146 
147 // #define ARTDAQ_FCL_PATH std::string(__ENV__("USER_DATA")) + "/" + "ARTDAQConfigurations/" #define ARTDAQ_FILE_PREAMBLE "boardReader"
148 
151 //{
152 // __COUT__ << "\tConfigure" << __E__;
153 //
154 // report_string_ = "";
155 // external_request_status_ = true;
156 //
157 // // in the following block, we first destroy the existing BoardReader
158 // // instance, then create a new one. Doing it in one step does not
159 // // produce the desired result since that creates a new instance and
160 // // then deletes the old one, and we need the opposite order.
161 // fragment_receiver_ptr_.reset(nullptr);
162 // __COUT__ << "\tNew core" << __E__;
163 // my_rank = rank;
164 // app_name = name_;
165 // fragment_receiver_ptr_.reset(new artdaq::BoardReaderApp());
166 // // FIXME These are passed as parameters
167 // uint64_t timeout = 45;
168 // // uint64_t timestamp = 184467440737095516;
169 // uint64_t timestamp = 184467440737095516;
170 // __COUT__ << "\tInitialize: "
171 // << __E__; //<< fhiclConfiguration_.to_string() << __E__;
172 // external_request_status_ =
173 // fragment_receiver_ptr_->initialize(fhiclConfiguration_, timeout, timestamp);
174 // __COUT__ << "\tDone Initialize" << __E__;
175 // if(!external_request_status_)
176 // {
177 // report_string_ = "Error initializing ";
178 // report_string_.append(name_ + " ");
179 // report_string_.append("with ParameterSet = \"" + fhiclConfiguration_.to_string() +
180 // "\".");
181 // }
182 // __COUT__ << "\tDone Configure" << __E__;
183 //}
184 
187 //{
188 // __COUT__ << "\tHalt" << __E__;
189 // // FIXME These are passed as parameters
190 // uint64_t timeout = 45;
191 // // uint64_t timestamp = 184467440737095516;
192 // report_string_ = "";
193 // external_request_status_ = fragment_receiver_ptr_->shutdown(timeout);
194 // if(!external_request_status_)
195 // {
196 // report_string_ = "Error shutting down ";
197 // report_string_.append(name_ + ".");
198 // }
199 //}
200 
201 //==============================================================================
202 void ARTDAQConsumer::pauseProcessingData(void) { ARTDAQReaderProcessorBase::pause(); }
203 //{
204 // __COUT__ << "\tPause" << __E__;
205 // // FIXME These are passed as parameters
206 // uint64_t timeout = 45;
207 // uint64_t timestamp = 184467440737095516;
208 // report_string_ = "";
209 // external_request_status_ = fragment_receiver_ptr_->pause(timeout, timestamp);
210 // if(!external_request_status_)
211 // {
212 // report_string_ = "Error pausing ";
213 // report_string_.append(name_ + ".");
214 // }
215 //}
216 
217 //==============================================================================
218 void ARTDAQConsumer::resumeProcessingData(void) { ARTDAQReaderProcessorBase::resume(); }
219 //{
220 // __COUT__ << "\tResume" << __E__;
221 // // FIXME These are passed as parameters
222 // uint64_t timeout = 45;
223 // uint64_t timestamp = 184467440737095516;
224 // report_string_ = "";
225 // external_request_status_ = fragment_receiver_ptr_->resume(timeout, timestamp);
226 // if(!external_request_status_)
227 // {
228 // report_string_ = "Error resuming ";
229 // report_string_.append(name_ + ".");
230 // }
231 //}
232 
233 //==============================================================================
234 void ARTDAQConsumer::startProcessingData(std::string runNumber)
235 {
236  ARTDAQReaderProcessorBase::start(runNumber);
237 }
238 //{
239 // __COUT__ << "\tStart" << __E__;
240 //
241 // art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
242 //
243 // // FIXME These are passed as parameters
244 // uint64_t timeout = 45;
245 // uint64_t timestamp = 184467440737095516;
246 //
247 // report_string_ = "";
248 // __COUT__ << "\tStart run: " << runId << __E__;
249 // external_request_status_ = fragment_receiver_ptr_->start(runId, timeout, timestamp);
250 // __COUT__ << "\tStart already crashed " << __E__;
251 // if(!external_request_status_)
252 // {
253 // report_string_ = "Error starting ";
254 // report_string_.append(name_ + " ");
255 // report_string_.append("for run number ");
256 // report_string_.append(boost::lexical_cast<std::string>(runId.run()));
257 // report_string_.append(", timeout ");
258 // report_string_.append(boost::lexical_cast<std::string>(timeout));
259 // report_string_.append(", timestamp ");
260 // report_string_.append(boost::lexical_cast<std::string>(timestamp));
261 // report_string_.append(".");
262 // }
263 //
264 // __COUT__ << "STARTING BOARD READER THREAD" << __E__;
265 //}
266 
267 //==============================================================================
268 void ARTDAQConsumer::stopProcessingData(void) { ARTDAQReaderProcessorBase::stop(); }
269 //{
270 // __COUT__ << "\tStop" << __E__;
271 // // FIXME These are passed as parameters
272 // uint64_t timeout = 45;
273 // uint64_t timestamp = 184467440737095516;
274 // report_string_ = "";
275 //
276 // auto sts = fragment_receiver_ptr_->status();
277 // if(sts == "Ready")
278 // return; // Already stopped/never started
279 //
280 // external_request_status_ = fragment_receiver_ptr_->stop(timeout, timestamp);
281 // if(!external_request_status_)
282 // {
283 // report_string_ = "Error stopping ";
284 // report_string_.append(name_ + ".");
285 // // return false;
286 // }
287 //}
ARTDAQConsumer(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID, const ConfigurationTree &theXDAQContextConfigTree, const std::string &configurationPath)
void pauseProcessingData(void) override
void startProcessingData(std::string runNumber) override
virtual ~ARTDAQConsumer(void)