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