$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/ARTDAQReaderCore/ARTDAQReaderProcessorBase.h" 00002 #include "artdaq/Application/Commandable.hh" 00003 #include "fhiclcpp/make_ParameterSet.h" 00004 #include "otsdaq-core/DataManager/DataManager.h" 00005 #include "otsdaq-core/DataManager/DataManagerSingleton.h" 00006 #include "otsdaq-core/Macros/CoutMacros.h" 00007 //#include "otsdaq-core/Macros/ProcessorPluginMacros.h" 00008 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00009 00010 #include <cstdint> 00011 #include <fstream> 00012 #include <iostream> 00013 #include <set> 00014 00015 using namespace ots; 00016 00017 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/" + "ARTDAQConfigurations/" 00018 #define ARTDAQ_FILE_PREAMBLE "boardReader" 00019 00020 //======================================================================================================================== 00021 ARTDAQReaderProcessorBase::ARTDAQReaderProcessorBase( 00022 std::string supervisorApplicationUID, 00023 std::string bufferUID, 00024 std::string processorUID, 00025 const ConfigurationTree& theXDAQContextConfigTree, 00026 const std::string& configurationPath) 00027 // : WorkLoop(processorUID) 00028 // , DataProducer(supervisorApplicationUID, bufferUID, processorUID) 00029 // theXDAQContextConfigTree.getNode(configurationPath).getNode("BufferSize").getValue<unsigned 00030 // int>()) 00031 : Configurable(theXDAQContextConfigTree, configurationPath) 00032 , name_("BoardReader_" + processorUID) 00033 { 00034 __CFG_COUT__ << "Constructing..." << __E__; 00035 //__CFG_COUT__ << "Configuration string:-" << 00036 // theXDAQContextConfigTree.getNode(configurationPath).getNode("ConfigurationString").getValue<std::string>() 00037 //<< "-" << __E__; 00038 00039 std::string filename = ARTDAQ_FCL_PATH + ARTDAQ_FILE_PREAMBLE + "-"; 00040 std::string uid = theXDAQContextConfigTree.getNode(configurationPath).getValue(); 00041 00042 __CFG_COUT__ << "uid: " << uid << __E__; 00043 for(unsigned int i = 0; i < uid.size(); ++i) 00044 if((uid[i] >= 'a' && uid[i] <= 'z') || (uid[i] >= 'A' && uid[i] <= 'Z') || 00045 (uid[i] >= '0' && uid[i] <= '9')) // only allow alpha numeric in file name 00046 filename += uid[i]; 00047 filename += ".fcl"; 00048 00049 __CFG_COUT__ << __E__; 00050 __CFG_COUT__ << __E__; 00051 __CFG_COUT__ << "filename: " << filename << __E__; 00052 00053 std::string fileFclString; 00054 { 00055 std::ifstream in(filename, std::ios::in | std::ios::binary); 00056 if(in) 00057 { 00058 std::string contents; 00059 in.seekg(0, std::ios::end); 00060 fileFclString.resize(in.tellg()); 00061 in.seekg(0, std::ios::beg); 00062 in.read(&fileFclString[0], fileFclString.size()); 00063 in.close(); 00064 } 00065 } 00066 //__CFG_COUT__ << fileFclString << __E__; 00067 00068 // find fragment_receiver { 00069 // and insert e.g., 00070 // SupervisorApplicationUID:"ARTDataManager0" 00071 // BufferUID:"ART_S0_DM0_DataBuffer0" 00072 // ProcessorUID:"ART_S0_DM0_DB0_ARTConsumer0" 00073 size_t fcli = 00074 fileFclString.find("fragment_receiver: {") + +strlen("fragment_receiver: {"); 00075 if(fcli == std::string::npos) 00076 { 00077 __SS__ << "Could not find 'fragment_receiver: {' in Board Reader fcl string!" 00078 << __E__; 00079 __CFG_COUT__ << "\n" << ss.str(); 00080 __SS_THROW__; 00081 } 00082 00083 // get the parent IDs from configurationPath 00084 __CFG_COUT__ << "configurationPath " << configurationPath << __E__; 00085 00086 std::string consumerID, bufferID, appID; 00087 unsigned int backSteps; // at 2, 4, and 7 are the important parent IDs 00088 size_t backi = -1, backj; 00089 backSteps = 7; 00090 for(unsigned int i = 0; i < backSteps; i++) 00091 { 00092 //__CFG_COUT__ << "backsteps: " << i+1 << __E__; 00093 00094 backj = backi; 00095 backi = configurationPath.rfind('/', backi - 1); 00096 00097 //__CFG_COUT__ << "backi:" << backi << " backj:" << backj << __E__; 00098 //__CFG_COUT__ << "substr: " << configurationPath.substr(backi+1,backj-backi-1) << 00099 // __E__; 00100 00101 if(i + 1 == 2) 00102 consumerID = configurationPath.substr(backi + 1, backj - backi - 1); 00103 else if(i + 1 == 4) 00104 bufferID = configurationPath.substr(backi + 1, backj - backi - 1); 00105 else if(i + 1 == 7) 00106 appID = configurationPath.substr(backi + 1, backj - backi - 1); 00107 } 00108 00109 // insert parent IDs into fcl string 00110 fileFclString = fileFclString.substr(0, fcli) + "\n\t\t" + 00111 "SupervisorApplicationUID: \"" + appID + "\"\n\t\t" + 00112 "BufferUID: \"" + bufferID + "\"\n\t\t" + "ProcessorUID: \"" + 00113 consumerID + "\"\n" + fileFclString.substr(fcli); 00114 00115 __CFG_COUT__ << fileFclString << __E__; 00116 00117 fhicl::make_ParameterSet(fileFclString, fhiclConfiguration_); 00118 00119 // fhicl::make_ParameterSet(theXDAQContextConfigTree.getNode(configurationPath).getNode("ConfigurationString").getValue<std::string>(), 00120 // fhiclConfiguration_); 00121 } 00122 00123 //======================================================================================================================== 00124 // ARTDAQReaderProcessorBase::ARTDAQReaderProcessorBase(std::string interfaceID, MPI_Comm 00125 // local_group_comm, std::string name) :FEVInterface (feId, 0) 00126 // ,local_group_comm_(local_group_comm) 00127 //,name_ (name) 00128 //{} 00129 00130 //======================================================================================================================== 00131 ARTDAQReaderProcessorBase::~ARTDAQReaderProcessorBase(void) 00132 { 00133 halt(); 00134 __CFG_COUT__ << "DONE DELETING!" << __E__; 00135 } 00136 00137 //======================================================================================================================== 00138 void ARTDAQReaderProcessorBase::initLocalGroup(int rank) { configure(rank); } 00139 00140 #define ARTDAQ_FCL_PATH std::string(getenv("USER_DATA")) + "/" + "ARTDAQConfigurations/" 00141 #define ARTDAQ_FILE_PREAMBLE "boardReader" 00142 00143 //======================================================================================================================== 00144 void ARTDAQReaderProcessorBase::configure(int rank) 00145 { 00146 __CFG_COUT__ << "Configuring..." << __E__; 00147 00148 // in the following block, we first destroy the existing BoardReader 00149 // instance, then create a new one. Doing it in one step does not 00150 // produce the desired result since that creates a new instance and 00151 // then deletes the old one, and we need the opposite order. 00152 fragment_receiver_ptr_.reset(nullptr); 00153 __CFG_COUT__ << "New core" << __E__; 00154 my_rank = rank; 00155 app_name = name_; 00156 fragment_receiver_ptr_.reset(new artdaq::BoardReaderApp()); 00157 00158 // FIXME These are passed as parameters 00159 // should they come from the Configuration Tree? 00160 uint64_t timeout = 45; 00161 uint64_t timestamp = 184467440737095516; 00162 __CFG_COUT__ << "Initializing '" << name_ << "'" 00163 << __E__; //<< fhiclConfiguration_.to_string() << __E__; 00164 00165 if(!fragment_receiver_ptr_->initialize(fhiclConfiguration_, timeout, timestamp)) 00166 { 00167 __CFG_SS__ << "Error initializing '" << name_ << "' with ParameterSet = \n" 00168 << fhiclConfiguration_.to_string() << __E__; 00169 __CFG_SS_THROW__; 00170 } 00171 __CFG_COUT__ << "Done Initializing." << __E__; 00172 00173 // do any other configure steps here 00174 00175 __CFG_COUT__ << "Configured." << __E__; 00176 } // end configure() 00177 00178 //======================================================================================================================== 00179 void ARTDAQReaderProcessorBase::halt(void) 00180 { 00181 __CFG_COUT__ << "Halting..." << __E__; 00182 00183 // FIXME These are passed as parameters 00184 // should they come from the Configuration Tree? 00185 uint64_t timeout = 45; 00186 00187 if(!fragment_receiver_ptr_->shutdown(timeout)) 00188 { 00189 __CFG_SS__ << "Error shutting down '" << name_ << ".'" << __E__; 00190 __CFG_SS_THROW__; 00191 } 00192 00193 __CFG_COUT__ << "Halted." << __E__; 00194 } // end halt() 00195 00196 //======================================================================================================================== 00197 void ARTDAQReaderProcessorBase::pause(void) 00198 { 00199 __CFG_COUT__ << "Pausing..." << __E__; 00200 00201 // FIXME These are passed as parameters 00202 // should they come from the Configuration Tree? 00203 uint64_t timeout = 45; 00204 uint64_t timestamp = 184467440737095516; 00205 00206 if(!fragment_receiver_ptr_->pause(timeout, timestamp)) 00207 { 00208 __CFG_SS__ << "Error pausing '" << name_ << ".'" << __E__; 00209 __CFG_SS_THROW__; 00210 } 00211 00212 __CFG_COUT__ << "Paused." << __E__; 00213 } // end pause() 00214 00215 //======================================================================================================================== 00216 void ARTDAQReaderProcessorBase::resume(void) 00217 { 00218 __CFG_COUT__ << "Resuming..." << __E__; 00219 00220 // FIXME These are passed as parameters 00221 // should they come from the Configuration Tree? 00222 uint64_t timeout = 45; 00223 uint64_t timestamp = 184467440737095516; 00224 00225 if(!fragment_receiver_ptr_->resume(timeout, timestamp)) 00226 { 00227 __CFG_SS__ << "Error resuming '" << name_ << ".'" << __E__; 00228 __CFG_SS_THROW__; 00229 } 00230 00231 __CFG_COUT__ << "Resumed." << __E__; 00232 } // end resume () 00233 00234 //======================================================================================================================== 00235 void ARTDAQReaderProcessorBase::start(const std::string& runNumber) 00236 { 00237 __CFG_COUT__ << "Starting..." << __E__; 00238 00239 art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber)); 00240 00241 // FIXME These are passed as parameters 00242 // should they come from the Configuration Tree? 00243 uint64_t timeout = 45; 00244 uint64_t timestamp = 184467440737095516; 00245 00246 __CFG_COUT__ << "Start run: " << runId << __E__; 00247 if(!fragment_receiver_ptr_->start(runId, timeout, timestamp)) 00248 { 00249 __CFG_SS__ << "Error starting '" << name_ << "' for run number '" << runId << ",'" 00250 << __E__; 00251 __CFG_SS_THROW__; 00252 } 00253 00254 __CFG_COUT__ << "Started." << __E__; 00255 } // end start() 00256 00257 //======================================================================================================================== 00258 void ARTDAQReaderProcessorBase::stop(void) 00259 { 00260 __CFG_COUT__ << "Stop" << __E__; 00261 00262 // FIXME These are passed as parameters 00263 // should they come from the Configuration Tree? 00264 uint64_t timeout = 45; 00265 uint64_t timestamp = 184467440737095516; 00266 00267 auto sts = fragment_receiver_ptr_->status(); 00268 if(sts == "Ready") 00269 { 00270 __CFG_COUT__ << "Already stopped - never started!" << __E__; 00271 return; // Already stopped/never started 00272 } 00273 00274 if(!fragment_receiver_ptr_->stop(timeout, timestamp)) 00275 { 00276 __CFG_SS__ << "Error stopping '" << name_ << ".'" << __E__; 00277 __CFG_SS_THROW__; 00278 } 00279 00280 __CFG_COUT__ << "Stopped." << __E__; 00281 } // end stop()