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