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