00001 #include "art/Framework/Core/FileBlock.h"
00002 #include "art/Framework/Core/InputSourceMacros.h"
00003 #include "art/Framework/Core/ProductRegistryHelper.h"
00004 #include "art/Framework/IO/Sources/Source.h"
00005 #include "art/Framework/IO/Sources/SourceHelper.h"
00006 #include "art/Framework/IO/Sources/SourceTraits.h"
00007 #include "art/Framework/Services/Registry/ServiceHandle.h"
00008
00009 #if ART_HEX_VERSION < 0x20703
00010 # include "art/Persistency/Provenance/BranchIDListHelper.h"
00011 #endif
00012 #if ART_HEX_VERSION < 0x20900
00013 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
00014 #include "canvas/Persistency/Provenance/BranchIDList.h"
00015 #endif
00016 #include "art/Persistency/Provenance/MasterProductRegistry.h"
00017 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
00018 #include "art/Persistency/Provenance/ProductMetaData.h"
00019
00020 #include "canvas/Persistency/Common/EDProduct.h"
00021 #include "canvas/Persistency/Common/Wrapper.h"
00022 #include "canvas/Persistency/Provenance/BranchDescription.h"
00023 #include "canvas/Persistency/Provenance/BranchKey.h"
00024 #include "canvas/Persistency/Provenance/History.h"
00025 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
00026 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
00027 #include "canvas/Persistency/Provenance/ProcessHistory.h"
00028 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
00029 #include "canvas/Persistency/Provenance/ProductList.h"
00030 #include "canvas/Persistency/Provenance/ProductProvenance.h"
00031 #include "canvas/Utilities/DebugMacros.h"
00032
00033 #include "fhiclcpp/make_ParameterSet.h"
00034 #include "fhiclcpp/ParameterSet.h"
00035 #include "fhiclcpp/ParameterSetID.h"
00036 #include "fhiclcpp/ParameterSetRegistry.h"
00037
00038 #include <TClass.h>
00039 #include <TMessage.h>
00040 #include <TBufferFile.h>
00041
00042 #include "artdaq/DAQdata/Globals.hh"
00043 #include "artdaq/ArtModules/InputUtilities.hh"
00044 #include "artdaq-core/Data/detail/ParentageMap.hh"
00045 #include "artdaq-core/Utilities/ExceptionHandler.hh"
00046
00047 #include <cstdio>
00048 #include <iomanip>
00049 #include <memory>
00050 #include <sstream>
00051 #include <string>
00052 #include <vector>
00053 #include <sys/time.h>
00054 #include <iostream>
00055
00056 namespace art
00057 {
00058 template <typename U>
00059 class ArtdaqInput;
00060 }
00061
00076 template <typename U>
00077 class art::ArtdaqInput
00078 {
00079 public:
00083 ArtdaqInput(const ArtdaqInput&) = delete;
00084
00089 ArtdaqInput& operator=(const ArtdaqInput&) = delete;
00090
00094 ~ArtdaqInput();
00095
00102 ArtdaqInput(const fhicl::ParameterSet& ps, art::ProductRegistryHelper& helper,
00103 art::SourceHelper const& pm);
00104
00108 void closeCurrentFile();
00109
00114 void readFile(const std::string&, art::FileBlock*& fb);
00115
00120 bool hasMoreData() const;
00121
00131 bool readNext(art::RunPrincipal* const inR,
00132 art::SubRunPrincipal* const inSR, art::RunPrincipal*& outR,
00133 art::SubRunPrincipal*& outSR, art::EventPrincipal*& outE);
00134
00135 private:
00136 void
00137 readAndConstructPrincipal(std::unique_ptr<TBufferFile>&,
00138 unsigned long,
00139 art::RunPrincipal* const,
00140 art::SubRunPrincipal* const,
00141 art::RunPrincipal*&,
00142 art::SubRunPrincipal*&,
00143 art::EventPrincipal*&);
00144
00145 template <class T>
00146 void readDataProducts(std::unique_ptr<TBufferFile>&, T*&);
00147
00148 void putInPrincipal(RunPrincipal*&, std::unique_ptr<EDProduct>&&, const BranchDescription&, std::unique_ptr<const ProductProvenance>&&);
00149
00150 void putInPrincipal(SubRunPrincipal*&, std::unique_ptr<EDProduct>&&, const BranchDescription&, std::unique_ptr<const ProductProvenance>&&);
00151
00152 void putInPrincipal(EventPrincipal*&, std::unique_ptr<EDProduct>&&, const BranchDescription&, std::unique_ptr<const ProductProvenance>&&);
00153
00154
00155 private:
00156 bool shutdownMsgReceived_;
00157 bool outputFileCloseNeeded_;
00158 art::SourceHelper const& pm_;
00159 U communicationWrapper_;
00160 };
00161
00162 template <typename U>
00163 art::ArtdaqInput<U>::
00164 ArtdaqInput(const fhicl::ParameterSet& ps,
00165 art::ProductRegistryHelper& helper,
00166 art::SourceHelper const& pm)
00167 : shutdownMsgReceived_(false)
00168 , outputFileCloseNeeded_(false)
00169 , pm_(pm)
00170 , communicationWrapper_(ps)
00171 {
00172 artdaq::configureMessageFacility("artdaqart");
00173
00174
00175
00176
00177
00178
00179
00180 TLOG_ARB(5, "ArtdaqInput") << "Begin: ArtdaqInput::ArtdaqInput(" <<
00181 "const fhicl::ParameterSet& ps, " <<
00182 "art::ProductRegistryHelper& helper, " <<
00183 "const art::SourceHelper& pm)" << TLOG_ENDL;
00184 (void)helper;
00185
00186 TLOG_ARB(5, "ArtdaqInput") << "Going to receive init message" << TLOG_ENDL;
00187 std::unique_ptr<TBufferFile> msg(nullptr);
00188 communicationWrapper_.receiveInitMessage(msg);
00189 TLOG_ARB(5, "ArtdaqInput") << "Init message received" << TLOG_ENDL;
00190
00191 if (!msg)
00192 {
00193 throw art::Exception(art::errors::DataCorruption) <<
00194 "ArtdaqInput: Could not receive init message!";
00195 }
00196
00197
00198 unsigned long dummy = 0;
00199 msg->ReadULong(dummy);
00200
00201
00202
00203
00204 unsigned long ps_cnt = 0;
00205 msg->ReadULong(ps_cnt);
00206 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: parameter set count: " << ps_cnt << TLOG_ENDL;
00207 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: reading parameter sets ..." << TLOG_ENDL;
00208 for (unsigned long I = 0; I < ps_cnt; ++I)
00209 {
00210 std::string pset_str = "";
00211 msg->ReadStdString(pset_str);
00212
00213 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: parameter set: " << pset_str << TLOG_ENDL;
00214
00215 fhicl::ParameterSet pset;
00216 fhicl::make_ParameterSet(pset_str, pset);
00217
00218 pset.id();
00219 fhicl::ParameterSetRegistry::put(pset);
00220 }
00221 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: finished reading parameter sets." << TLOG_ENDL;
00222
00223
00224
00225
00226 art::ProductList* productlist = ReadObjectAny<art::ProductList>(msg, "std::map<art::BranchKey,art::BranchDescription>", "ArtdaqInput::ArtdaqInput");
00227 helper.productList(productlist);
00228 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: got product list" << TLOG_ENDL;
00229
00230 #if ART_HEX_VERSION < 0x20900
00231 if (art::debugit() >= 1)
00232 {
00233 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: before BranchIDLists" << TLOG_ENDL;
00234
00235 #if ART_HEX_VERSION >= 0x20703
00236 BranchIDLists const * bil = &BranchIDListRegistry::instance().data();
00237 #else
00238 BranchIDLists* bil = &BranchIDListRegistry::instance()->data();
00239 #endif
00240 int max_bli = bil->size();
00241 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: max_bli: " << max_bli << TLOG_ENDL;
00242 for (int i = 0; i < max_bli; ++i)
00243 {
00244 int max_prdidx = (*bil)[i].size();
00245 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: max_prdidx: " << max_prdidx << TLOG_ENDL;
00246 for (int j = 0; j < max_prdidx; ++j)
00247 {
00248 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput:"
00249 << " bli: "
00250 << i
00251 << " prdidx: "
00252 << j
00253 << " bid: 0x"
00254 << std::hex
00255 << static_cast<unsigned long>((*bil)[i][j])
00256 << std::dec << TLOG_ENDL;
00257 }
00258 }
00259 }
00260 #endif
00261
00262
00263
00264 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: Reading ProcessHistory" << TLOG_ENDL;
00265 art::ProcessHistoryMap* phm = ReadObjectAny<art::ProcessHistoryMap>(msg, "std::map<const art::Hash<2>,art::ProcessHistory>", "ArtdaqInput::ArtdaqInput");
00266 printProcessMap(*phm, "ArtdaqInput's ProcessHistoryMap");
00267
00268 ProcessHistoryRegistry::put(*phm);
00269 printProcessMap(ProcessHistoryRegistry::get(), "ArtdaqInput's ProcessHistoryRegistry");
00270
00271
00272
00273
00274 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput: Reading ParentageMap" << TLOG_ENDL;
00275 ParentageMap* parentageMap = ReadObjectAny<ParentageMap>(msg, "art::ParentageMap", "ArtdaqInput::ArtdaqInput");
00276 ParentageRegistry::put(*parentageMap);
00277
00278
00279
00280
00281 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::ArtdaqInput(" << "const fhicl::ParameterSet& ps, " << "art::ProductRegistryHelper& helper, " << "const art::SourceHelper& pm)" << TLOG_ENDL;
00282 }
00283
00284 template <typename U>
00285 art::ArtdaqInput<U>::
00286 ~ArtdaqInput() {}
00287
00288 template <typename U>
00289 void
00290 art::ArtdaqInput<U>::
00291 closeCurrentFile()
00292 {
00293 TLOG_ARB(5, "ArtdaqInput") << "Begin/End: ArtdaqInput::closeCurrentFile()" << TLOG_ENDL;
00294 }
00295
00296 template <typename U>
00297 void
00298 art::ArtdaqInput<U>::
00299 readFile(const std::string&, art::FileBlock*& fb)
00300 {
00301 TLOG_ARB(5, "ArtdaqInput") << "Begin: ArtdaqInput::"
00302 "readFile(const std::string& name, art::FileBlock*& fb)" << TLOG_ENDL;
00303 fb = new art::FileBlock(art::FileFormatVersion(1, "ArtdaqInput2013"),
00304 "nothing");
00305 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::"
00306 "readFile(const std::string& name, art::FileBlock*& fb)" << TLOG_ENDL;
00307 }
00308
00309 template <typename U>
00310 bool
00311 art::ArtdaqInput<U>::
00312 hasMoreData() const
00313 {
00314 TLOG_ARB(5, "ArtdaqInput") << "Begin: ArtdaqInput::hasMoreData()" << TLOG_ENDL;
00315 if (shutdownMsgReceived_)
00316 {
00317 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::hasMoreData(): "
00318 "returning false on shutdownMsgReceived_." << TLOG_ENDL;
00319 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::hasMoreData()" << TLOG_ENDL;
00320 return false;
00321 }
00322 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::hasMoreData(): "
00323 "returning true on not shutdownMsgReceived_." << TLOG_ENDL;
00324 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::hasMoreData()" << TLOG_ENDL;
00325 return true;
00326 }
00327
00328 template <typename U>
00329 void
00330 art::ArtdaqInput<U>::
00331 readAndConstructPrincipal(std::unique_ptr<TBufferFile>& msg,
00332 unsigned long msg_type_code,
00333 art::RunPrincipal* const inR,
00334 art::SubRunPrincipal* const inSR,
00335 art::RunPrincipal*& outR,
00336 art::SubRunPrincipal*& outSR,
00337 art::EventPrincipal*& outE)
00338 {
00339
00340
00341
00342 std::unique_ptr<art::RunAuxiliary> run_aux;
00343 std::unique_ptr<art::SubRunAuxiliary> subrun_aux;
00344 std::unique_ptr<art::EventAuxiliary> event_aux;
00345 std::shared_ptr<History> history;
00346
00347 if (msg_type_code == 2)
00348 {
00349
00350 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "processing EndRun message ..." << TLOG_ENDL;
00351
00352 run_aux.reset(ReadObjectAny<art::RunAuxiliary>(msg, "art::RunAuxiliary", "ArtdaqInput::readAndConstructPrincipal"));
00353 printProcessHistoryID("readAndConstructPrincipal", run_aux.get());
00354
00355 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making flush RunPrincipal ..." << TLOG_ENDL;
00356 outR = pm_.makeRunPrincipal(RunID::flushRun(), run_aux->beginTime());
00357
00358 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making flush SubRunPrincipal ..." << TLOG_ENDL;
00359 outSR = pm_.makeSubRunPrincipal(SubRunID::flushSubRun(), run_aux->beginTime());
00360
00361 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making flush EventPrincipal ..." << TLOG_ENDL;
00362 outE = pm_.makeEventPrincipal(EventID::flushEvent(), run_aux->endTime(), true, EventAuxiliary::Any);
00363
00364 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " <<
00365 "finished processing EndRun message." << TLOG_ENDL;
00366 }
00367 else if (msg_type_code == 3)
00368 {
00369
00370 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "processing EndSubRun message ..." << TLOG_ENDL;
00371
00372 subrun_aux.reset(ReadObjectAny<art::SubRunAuxiliary>(msg, "art::SubRunAuxiliary", "ArtdaqInput::readAndConstructPrincipal"));
00373 printProcessHistoryID("readAndConstructPrincipal", subrun_aux.get());
00374
00375 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making flush RunPrincipal ..." << TLOG_ENDL;
00376 outR = pm_.makeRunPrincipal(RunID::flushRun(), subrun_aux->beginTime());
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 art::Timestamp currentTime = time(0);
00394 if (inR != nullptr) { inR->setEndTime(currentTime); }
00395 if (inSR != nullptr) { inSR->setEndTime(currentTime); }
00396
00397 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making flush SubRunPrincipal ..." << TLOG_ENDL;
00398 outSR = pm_.makeSubRunPrincipal(SubRunID::flushSubRun(), subrun_aux->beginTime());
00399
00400 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making flush EventPrincipal ..." << TLOG_ENDL;
00401 outE = pm_.makeEventPrincipal(EventID::flushEvent(), subrun_aux->endTime(), true, EventAuxiliary::Any);
00402
00403 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "finished processing EndSubRun message." << TLOG_ENDL;
00404 }
00405 else if (msg_type_code == 4)
00406 {
00407
00408 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "processing Event message ..." << TLOG_ENDL;
00409
00410 run_aux.reset(ReadObjectAny<art::RunAuxiliary>(msg, "art::RunAuxiliary", "ArtdaqInput::readAndConstructPrincipal"));
00411 printProcessHistoryID("readAndConstructPrincipal", run_aux.get());
00412
00413 subrun_aux.reset(ReadObjectAny<art::SubRunAuxiliary>(msg, "art::SubRunAuxiliary", "ArtdaqInput::readAndConstructPrincipal"));
00414 printProcessHistoryID("readAndConstructPrincipal", subrun_aux.get());
00415
00416 event_aux.reset(ReadObjectAny<art::EventAuxiliary>(msg, "art::EventAuxiliary", "ArtdaqInput::readAndConstructPrincipal"));
00417
00418 history.reset(ReadObjectAny<art::History>(msg, "art::History", "ArtdaqInput::readAndConstructPrincipal"));
00419 printProcessHistoryID("readAndConstructPrincipal", history.get());
00420
00421
00422 if (!history->processHistoryID().isValid())
00423 {
00424 throw art::Exception(art::errors::Unknown) << "readAndConstructPrincipal: processHistoryID of history in Event message is invalid!";
00425 }
00426
00427 if ((inR == nullptr) || !inR->id().isValid() || (inR->run() != event_aux->run()))
00428 {
00429
00430
00431 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: making RunPrincipal ..." << TLOG_ENDL;
00432 outR = pm_.makeRunPrincipal(*run_aux.get());
00433 }
00434 if ((inSR == nullptr) || !inSR->id().isValid() || (inSR->subRun() != event_aux->subRun()))
00435 {
00436
00437
00438 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "making SubRunPrincipal ..." << TLOG_ENDL;
00439 outSR = pm_.makeSubRunPrincipal(*subrun_aux.get());
00440 }
00441 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: making EventPrincipal ..." << TLOG_ENDL;
00442 outE = pm_.makeEventPrincipal(*event_aux.get(), std::move(history));
00443
00444 TLOG_ARB(5, "ArtdaqInput") << "readAndConstructPrincipal: " << "finished processing Event message." << TLOG_ENDL;
00445 }
00446 }
00447
00448 template <typename U>
00449 template <class T>
00450 void
00451 art::ArtdaqInput<U>::
00452 readDataProducts(std::unique_ptr<TBufferFile>& msg, T*& outPrincipal)
00453 {
00454 unsigned long prd_cnt = 0;
00455 {
00456 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: reading data product count ..." << TLOG_ENDL;
00457 msg->ReadULong(prd_cnt);
00458 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: product count: " << prd_cnt << TLOG_ENDL;
00459 }
00460
00461
00462
00463 const ProductList& productList = ProductMetaData::instance().productList();
00464
00465 for (unsigned long I = 0; I < prd_cnt; ++I)
00466 {
00467 std::unique_ptr<BranchKey> bk;
00468
00469 {
00470 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: Reading branch key." << TLOG_ENDL;
00471 bk.reset(ReadObjectAny<BranchKey>(msg, "art::BranchKey", "ArtdaqInput::readDataProducts"));
00472 }
00473
00474 if (art::debugit() >= 1)
00475 {
00476 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: got product class: '"
00477 << bk->friendlyClassName_
00478 << "' modlbl: '"
00479 << bk->moduleLabel_
00480 << "' instnm: '"
00481 << bk->productInstanceName_
00482 << "' procnm: '"
00483 << bk->processName_ << TLOG_ENDL;
00484 }
00485 ProductList::const_iterator iter;
00486 {
00487 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: looking up product ..." << TLOG_ENDL;
00488 iter = productList.find(*bk);
00489 if (iter == productList.end())
00490 {
00491 throw art::Exception(art::errors::ProductNotFound)
00492 << "No product is registered for\n"
00493 << " process name: '"
00494 << bk->processName_ << "'\n"
00495 << " module label: '"
00496 << bk->moduleLabel_ << "'\n"
00497 << " product friendly class name: '"
00498 << bk->friendlyClassName_ << "'\n"
00499 << " product instance name: '"
00500 << bk->productInstanceName_ << "'\n";
00501 }
00502 }
00503
00504
00505 const BranchDescription& bd = iter->second;
00506 std::unique_ptr<EDProduct> prd;
00507 {
00508 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: Reading product with wrapped name: " << bd.wrappedName()
00509 <<", TClass = " << (void*)TClass::GetClass(bd.wrappedName().c_str()) << TLOG_ENDL;
00510
00511
00512
00513
00514
00515
00516 void* p = msg->ReadObjectAny(TClass::GetClass(bd.wrappedName().c_str()));
00517 auto pp = reinterpret_cast<EDProduct*>(p);
00518
00519 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: After ReadObjectAny(prd): p=" << p
00520 << ", EDProduct::isPresent: " << pp->isPresent() << TLOG_ENDL;
00521 prd.reset(pp);
00522 p = nullptr;
00523 }
00524 std::unique_ptr<const ProductProvenance> prdprov;
00525 {
00526 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: Reading product provenance." << TLOG_ENDL;
00527 prdprov.reset(ReadObjectAny<ProductProvenance>(msg, "art::ProductProvenance", "ArtdaqInput::readDataProducts"));
00528 }
00529 {
00530 TLOG_ARB(5, "ArtdaqInput") << "readDataProducts: inserting product: class: '"
00531 << bd.friendlyClassName()
00532 << "' modlbl: '"
00533 << bd.moduleLabel()
00534 << "' instnm: '"
00535 << bd.productInstanceName()
00536 << "' procnm: '"
00537 << bd.processName() << TLOG_ENDL;
00538 putInPrincipal(outPrincipal, std::move(prd), bd, std::move(prdprov));
00539
00540 }
00541 }
00542 }
00543
00544 template <typename U>
00545 void
00546 art::ArtdaqInput<U>::
00547 putInPrincipal(RunPrincipal*& rp, std::unique_ptr<EDProduct>&& prd, const BranchDescription& bd, std::unique_ptr<const ProductProvenance>&& prdprov)
00548 {
00549 rp->put(std::move(prd), bd, std::move(prdprov), RangeSet::forRun(rp->id()));
00550 }
00551
00552 template <typename U>
00553 void
00554 art::ArtdaqInput<U>::
00555 putInPrincipal(SubRunPrincipal*& srp, std::unique_ptr<EDProduct>&& prd, const BranchDescription& bd, std::unique_ptr<const ProductProvenance>&& prdprov)
00556 {
00557 srp->put(std::move(prd), bd, std::move(prdprov), RangeSet::forSubRun(srp->id()));
00558 }
00559
00560 template <typename U>
00561 void
00562 art::ArtdaqInput<U>::
00563 putInPrincipal(EventPrincipal*& ep, std::unique_ptr<EDProduct>&& prd, const BranchDescription& bd, std::unique_ptr<const ProductProvenance>&& prdprov)
00564 {
00565 TLOG_ARB(6, "ArtdaqInput") << "EventPrincipal size before put: " << ep->size();
00566 ep->put(std::move(prd), bd, std::move(prdprov));
00567 TLOG_ARB(6, "ArtdaqInput") << "EventPrincipal size after put: " << ep->size();
00568 }
00569
00570
00571 template <typename U>
00572 bool
00573 art::ArtdaqInput<U>::
00574 readNext(art::RunPrincipal* const inR, art::SubRunPrincipal* const inSR,
00575 art::RunPrincipal*& outR, art::SubRunPrincipal*& outSR,
00576 art::EventPrincipal*& outE)
00577 {
00578 TLOG_ARB(5, "ArtdaqInput") << "Begin: ArtdaqInput::readNext" << TLOG_ENDL;
00579 if (outputFileCloseNeeded_)
00580 {
00581 outputFileCloseNeeded_ = false;
00582
00583
00584 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::readNext: " << "returning false on outputFileCloseNeeded_" << TLOG_ENDL;
00585 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::readNext" << TLOG_ENDL;
00586 return false;
00587 }
00588
00589 std::unique_ptr<TBufferFile> msg;
00590 communicationWrapper_.receiveMessage(msg);
00591
00592 if (!msg)
00593 {
00594 shutdownMsgReceived_ = true;
00595 return false;
00596 }
00597
00598
00599
00600
00601 unsigned long msg_type_code = 0;
00602 {
00603 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::readNext: " << "getting message type code ..." << TLOG_ENDL;
00604 msg->ReadULong(msg_type_code);
00605 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::readNext: " << "message type: " << msg_type_code << TLOG_ENDL;
00606 }
00607 if (msg_type_code == 5)
00608 {
00609
00610 shutdownMsgReceived_ = true;
00611 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::readNext: " << "returning false on Shutdown message." << TLOG_ENDL;
00612 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::readNext" << TLOG_ENDL;
00613 return false;
00614 }
00615
00616 readAndConstructPrincipal(msg, msg_type_code, inR, inSR, outR,
00617 outSR, outE);
00618
00619
00620
00621 if (msg_type_code == 2)
00622 {
00623
00624
00625 readDataProducts(msg, outR);
00626
00627 TLOG_ARB(5, "ArtdaqInput") << "ArtdaqInput::readNext: " << "returning false on EndRun message." << TLOG_ENDL;
00628 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::readNext" << TLOG_ENDL;
00629 return false;
00630 }
00631 else if (msg_type_code == 3)
00632 {
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642 if (inR != 0 && inSR != 0 && outR != 0 && outSR != 0)
00643 {
00644 if (inR->id().isFlush() && inSR->id().isFlush() &&
00645 outR->id().isFlush() && outSR->id().isFlush())
00646 {
00647 outR = 0;
00648 outSR = 0;
00649 outputFileCloseNeeded_ = true;
00650 return true;
00651 }
00652 }
00653
00654 readDataProducts(msg, outSR);
00655
00656
00657 outputFileCloseNeeded_ = true;
00658 TLOG_ARB(5, "ArtdaqInput") << "readNext: returning true on EndSubRun message." << TLOG_ENDL;
00659 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::readNext" << TLOG_ENDL;
00660 return true;
00661 }
00662 else if (msg_type_code == 4)
00663 {
00664
00665 readDataProducts(msg, outE);
00666 TLOG_ARB(5, "ArtdaqInput") << "readNext: returning true on Event message." << TLOG_ENDL;
00667 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::readNext" << TLOG_ENDL;
00668 return true;
00669 }
00670
00671
00672 TLOG_ARB(5, "ArtdaqInput") << "readNext: returning false on unknown msg_type_code!" << TLOG_ENDL;
00673 TLOG_ARB(5, "ArtdaqInput") << "End: ArtdaqInput::readNext" << TLOG_ENDL;
00674 return false;
00675 }