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