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