1 #ifndef ARTDAQ_ARTDAQ_ARTMODULES_ARTDAQOUTPUT_HH_
2 #define ARTDAQ_ARTDAQ_ARTMODULES_ARTDAQOUTPUT_HH_
4 #include "art/Framework/Core/OutputModule.h"
5 #include "art/Framework/Principal/EventPrincipal.h"
6 #include "art/Framework/Principal/OutputHandle.h"
7 #include "art/Framework/Principal/RunPrincipal.h"
8 #include "art/Framework/Principal/SubRunPrincipal.h"
10 #include "art/Framework/Core/ModuleMacros.h"
11 #include "art/Framework/Services/Registry/ServiceHandle.h"
12 #include "art/Persistency/Provenance/ModuleContext.h"
13 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
15 #include "art_root_io/setup.h"
17 #include "canvas/Persistency/Common/Wrapper.h"
18 #include "canvas/Persistency/Provenance/BranchDescription.h"
19 #include "canvas/Persistency/Provenance/BranchKey.h"
20 #include "canvas/Persistency/Provenance/History.h"
21 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
22 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
23 #include "canvas/Persistency/Provenance/ProcessConfigurationID.h"
24 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
25 #include "canvas/Persistency/Provenance/ProductList.h"
26 #include "canvas/Persistency/Provenance/ProductProvenance.h"
27 #include "canvas/Persistency/Provenance/RunAuxiliary.h"
28 #include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
29 #include "canvas/Utilities/DebugMacros.h"
30 #include "canvas/Utilities/Exception.h"
31 #if ART_HEX_VERSION < 0x30901
32 #include "canvas/Utilities/WrappedTypeID.h"
34 #include "canvas/Persistency/Common/WrappedTypeID.h"
36 #include "cetlib/column_width.h"
37 #include "cetlib/lpad.h"
38 #include "cetlib/rpad.h"
39 #include "fhiclcpp/ParameterSet.h"
40 #include "fhiclcpp/ParameterSetID.h"
41 #include "fhiclcpp/ParameterSetRegistry.h"
43 #include "artdaq/DAQdata/Globals.hh"
44 #include "artdaq/DAQdata/NetMonHeader.hh"
46 #include "artdaq-core/Data/Fragment.hh"
47 #include "artdaq-core/Data/RawEvent.hh"
48 #include "artdaq-core/Data/detail/ParentageMap.hh"
50 #include <TBufferFile.h>
53 #include <TStreamerInfo.h>
65 #define TLVL_OPENFILE 16
66 #define TLVL_CLOSEFILE 17
67 #define TLVL_RESPONDTOCLOSEINPUTFILE 18
68 #define TLVL_RESPONDTOCLOSEOUTPUTFILE 19
69 #define TLVL_ENDJOB 20
70 #define TLVL_SENDINIT 10
71 #define TLVL_SENDINIT_VERBOSE1 32
72 #define TLVL_SENDINIT_VERBOSE2 33
73 #define TLVL_WRITEDATAPRODUCTS 11
74 #define TLVL_WRITEDATAPRODUCTS_VERBOSE 34
76 #define TLVL_WRITERUN 13
77 #define TLVL_WRITERUN_VERBOSE 37
78 #define TLVL_WRITESUBRUN 14
79 #define TLVL_WRITESUBRUN_VERBOSE 35
80 #define TLVL_EXTRACTPRODUCTS 15
81 #define TLVL_EXTRACTPRODUCTS_VERBOSE 36
87 static artdaq::FragmentPtr outputFrag =
nullptr;
88 inline char* Fragment_ReAllocChar(
char* dataPtr,
size_t size,
size_t )
90 if (outputFrag !=
nullptr && dataPtr == reinterpret_cast<char*>(outputFrag->dataBegin()))
92 outputFrag->resizeBytes(size);
94 return reinterpret_cast<char*
>(outputFrag->dataBegin());
110 : OutputModule(ps), productList_(), raw_data_label_(ps.get<std::string>(
"raw_data_label",
"daq"))
126 TLOG(TLVL_OPENFILE) <<
"Begin/End: ArtdaqOutput::openFile(const FileBlock&)";
132 virtual void closeFile() { TLOG(TLVL_CLOSEFILE) <<
"Begin/End: ArtdaqOutput::closeFile()"; }
139 TLOG(TLVL_RESPONDTOCLOSEINPUTFILE) <<
"Begin/End: ArtdaqOutput::"
140 "respondToCloseOutputFiles(FileBlock const&)";
148 TLOG(TLVL_RESPONDTOCLOSEOUTPUTFILE) <<
"Begin/End: ArtdaqOutput::"
149 "respondToCloseOutputFiles(FileBlock const&)";
157 TLOG(TLVL_ENDJOB) <<
"Begin/End: ArtdaqOutput::endJob()";
192 void event(EventPrincipal
const& ep)
final
200 virtual void event_(EventPrincipal
const&) {}
206 void write(EventPrincipal& ep)
final;
212 void writeRun(RunPrincipal& rp)
final;
226 void writeDataProducts(std::unique_ptr<TBufferFile>& msg,
const Principal& principal, std::vector<BranchKey*>& bkv);
244 virtual void SendMessage(artdaq::FragmentPtr& msg) = 0;
252 bool initMsgSent_{
false};
253 ProductList productList_;
254 size_t last_fragment_size_{10};
255 artdaq::Fragment::sequence_id_t last_sequence_id_{0};
256 artdaq::Fragment::timestamp_t last_timestamp_{0};
257 std::string raw_data_label_;
259 std::unique_ptr<TBufferFile> prepareMessage(artdaq::Fragment::sequence_id_t seqID, artdaq::Fragment::timestamp_t ts, artdaq::Fragment::type_t type)
262 outputFrag = std::make_unique<artdaq::Fragment>(last_fragment_size_, seqID, my_rank, type, hdr, ts);
263 auto msg = std::make_unique<TBufferFile>(TBuffer::kWrite, last_fragment_size_ *
sizeof(artdaq::RawDataType), outputFrag->dataBegin(), kFALSE, &Fragment_ReAllocChar);
266 if (seqID > last_sequence_id_) last_sequence_id_ = seqID;
267 if (ts > last_timestamp_) last_timestamp_ = ts;
272 void sendMessage(std::unique_ptr<TBufferFile>& msg)
275 hdr.
data_length =
static_cast<uint64_t
>(msg->Length());
276 outputFrag->updateMetadata(hdr);
278 last_fragment_size_ = std::ceil(msg->Length() /
static_cast<double>(
sizeof(artdaq::RawDataType)));
285 TLOG(TLVL_SENDINIT) <<
"Begin: ArtdaqOutput::send_init_message()";
295 static TClass* product_list_class = TClass::GetClass(
"std::map<art::BranchKey,art::BranchDescription>");
296 if (product_list_class ==
nullptr)
298 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
299 "Could not get TClass for "
300 "map<art::BranchKey,art::BranchDescription>!";
306 static TClass* process_history_map_class = TClass::GetClass(
"std::map<const art::Hash<2>,art::ProcessHistory>");
307 if (process_history_map_class ==
nullptr)
309 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
310 "Could not get class for "
311 "std::map<const art::Hash<2>,art::ProcessHistory>!";
315 static TClass* parentage_map_class = TClass::GetClass(
"art::ParentageMap");
316 if (parentage_map_class ==
nullptr)
318 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
319 "Could not get class for ParentageMap.";
321 TLOG(TLVL_SENDINIT) <<
"parentage_map_class: " <<
static_cast<void*
>(parentage_map_class);
323 static TClass* history_class = TClass::GetClass(
"art::History");
324 if (history_class ==
nullptr)
326 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
327 "Could not get TClass for art::History!";
333 auto msg = prepareMessage(0, 0, artdaq::Fragment::InitFragmentType);
337 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming message type code ...";
339 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming message type code.";
346 std::vector<std::string> classNames{
"std::map<art::BranchKey,art::BranchDescription>",
"std::map<const art::Hash<2>,art::ProcessHistory>",
"art::ParentageMap",
347 "art::History",
"art::BranchKey",
"art::ProductProvenance",
"art::RunAuxiliary",
"art::SubRunAuxiliary",
"art::EventAuxiliary"};
348 for (
auto& className : classNames)
350 TClass* class_ptr = TClass::GetClass(className.c_str());
351 if (class_ptr ==
nullptr)
353 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message: Could not get TClass for " << className <<
"!";
355 infos.Add(class_ptr->GetStreamerInfo());
357 msg->WriteObject(&infos);
362 ULong_t ps_cnt = fhicl::ParameterSetRegistry::size();
363 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): parameter set count: " << ps_cnt;
364 msg->WriteULong(ps_cnt);
365 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming parameter sets ...";
366 for (
auto I = std::begin(fhicl::ParameterSetRegistry::get()), E = std::end(fhicl::ParameterSetRegistry::get());
369 TLOG(TLVL_SENDINIT) <<
"Pset ID " << I->first <<
": " << I->second.to_string();
370 std::string pset_str = I->second.to_string();
372 msg->WriteStdString(pset_str);
374 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming parameter sets.";
379 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming Product List sz=" << productList_.size() <<
"...";
380 msg->WriteObjectAny(&productList_, product_list_class);
381 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming Product List.";
383 art::ProcessHistoryMap phr;
384 for (
auto const& pr : art::ProcessHistoryRegistry::get())
391 TLOG(TLVL_SENDINIT_VERBOSE2) <<
"ArtdaqOutput::send_init_message(): Dumping ProcessHistoryRegistry ...";
394 TLOG(TLVL_SENDINIT_VERBOSE2) <<
"ArtdaqOutput::send_init_message(): phr: size: " << phr.size();
395 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
397 std::ostringstream OS;
399 TLOG(TLVL_SENDINIT_VERBOSE2) <<
"ArtdaqOutput::send_init_message(): phr: id: '" << OS.str() <<
"'";
404 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming ProcessHistoryRegistry ...";
407 const art::ProcessHistoryMap& phm = phr;
408 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): phm: size: " << phm.size();
409 msg->WriteObjectAny(&phm, process_history_map_class);
410 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming ProcessHistoryRegistry.";
415 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming ParentageRegistry ..." <<
static_cast<void*
>(parentage_map_class);
416 art::ParentageMap parentageMap{};
417 for (
auto const& pr : art::ParentageRegistry::get())
419 parentageMap.emplace(pr.first, pr.second);
422 msg->WriteObjectAny(&parentageMap, parentage_map_class);
424 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming ParentageRegistry.";
426 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming History";
427 msg->WriteObjectAny(&history, history_class);
428 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Done streaming History";
430 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Sending init message";
432 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Done sending init message";
434 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): END";
439 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"Begin: ArtdaqOutput::writeDataProducts(...)";
444 static TClass* branch_key_class = TClass::GetClass(
"art::BranchKey");
445 if (branch_key_class ==
nullptr)
447 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeDataProducts(...): "
448 "Could not get TClass for art::BranchKey!";
450 static TClass* prdprov_class = TClass::GetClass(
"art::ProductProvenance");
451 if (prdprov_class ==
nullptr)
453 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeDataProducts(...): "
454 "Could not get TClass for art::ProductProvenance!";
462 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
464 auto const& productDescription = I->second->productDescription();
465 auto const& refs = keptProducts()[productDescription.branchType()];
467 for (
auto const& ref : refs)
469 if (ref.second == productDescription)
475 if (!I->second->productAvailable() || !found)
484 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): Streaming product count: " +
485 std::to_string(prd_cnt);
486 msg->WriteULong(prd_cnt);
487 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): Finished streaming product count.";
499 bkv.reserve(prd_cnt);
501 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
503 auto const& productDescription = I->second->productDescription();
504 auto const& refs = keptProducts()[productDescription.branchType()];
506 for (
auto const& ref : refs)
508 if (ref.second == productDescription)
514 if (!I->second->productAvailable() || !found)
518 const BranchDescription& bd(I->second->productDescription());
519 bkv.push_back(
new BranchKey(bd));
520 TLOG(TLVL_WRITEDATAPRODUCTS_VERBOSE)
521 <<
"ArtdaqOutput::writeDataProducts(...): Dumping branch key of class: '"
522 << bkv.back()->friendlyClassName_ <<
"' modlbl: '" << bkv.back()->moduleLabel_ <<
"' instnm: '"
523 << bkv.back()->productInstanceName_ <<
"' procnm: '" << bkv.back()->processName_ <<
"'";
524 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
525 "Streaming branch key of class: '"
526 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
527 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
528 msg->WriteObjectAny(bkv.back(), branch_key_class);
530 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
531 "Streaming product of class: '"
532 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
533 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
535 OutputHandle oh = principal.getForOutput(bd.productID(),
true);
536 const EDProduct* prd = oh.wrapper();
537 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"Class for branch " << bd.wrappedName() <<
" is "
538 <<
static_cast<void*
>(TClass::GetClass(bd.wrappedName().c_str()));
539 msg->WriteObjectAny(prd, TClass::GetClass(bd.wrappedName().c_str()));
540 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
541 "Streaming product provenance of class: '"
542 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
543 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
545 const ProductProvenance* prdprov = I->second->productProvenance().get();
547 msg->WriteObjectAny(prdprov, prdprov_class);
549 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"End: ArtdaqOutput::writeDataProducts(...)";
557 TLOG(TLVL_WRITE) <<
"Begin: ArtdaqOutput::write(const EventPrincipal& ep)";
560 send_init_message(ep.history());
566 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
567 if (run_aux_class ==
nullptr)
569 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
570 "Could not get TClass for art::RunAuxiliary!";
572 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
573 if (subrun_aux_class ==
nullptr)
575 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
576 "Could not get TClass for art::SubRunAuxiliary!";
578 static TClass* event_aux_class = TClass::GetClass(
"art::EventAuxiliary");
579 if (event_aux_class ==
nullptr)
581 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
582 "Could not get TClass for art::EventAuxiliary!";
584 static TClass* history_class = TClass::GetClass(
"art::History");
585 if (history_class ==
nullptr)
587 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
588 "Could not get TClass for art::History!";
592 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Setting Output Fragment Header Fields";
593 auto seqID = (
static_cast<uint64_t
>(ep.eventID().subRun() - 1) << 32) + ep.eventID().event();
595 art::ProcessTag tag(
"", processName());
596 auto res = ep.getMany(art::ModuleContext::invalid(), art::WrappedTypeID::make<artdaq::detail::RawEventHeader>(), art::MatchAllSelector(), tag);
598 artdaq::Fragment::timestamp_t ts = 0;
600 for (
auto const& qr : res)
602 Handle<artdaq::detail::RawEventHeader> handle{qr};
603 if (handle.isValid())
605 if (handle->timestamp > ts) ts = handle->timestamp;
608 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Data Fragment Header Fields: SeqID: " << seqID <<
", timestamp: " << ts;
613 auto msg = prepareMessage(seqID, ts, artdaq::Fragment::DataFragmentType);
617 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming message type code ...";
619 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming message type code.";
624 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming RunAuxiliary ...";
625 msg->WriteObjectAny(&ep.subRunPrincipal().runPrincipal().runAux(), run_aux_class);
626 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming RunAuxiliary.";
631 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming SubRunAuxiliary ...";
632 msg->WriteObjectAny(&ep.subRunPrincipal().subRunAux(), subrun_aux_class);
633 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming SubRunAuxiliary.";
639 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming EventAuxiliary ...";
640 msg->WriteObjectAny(&ep.eventAux(), event_aux_class);
641 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming EventAuxiliary.";
647 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming History ...";
648 msg->WriteObjectAny(&ep.history(), history_class);
649 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming History.";
654 std::vector<BranchKey*> bkv;
655 writeDataProducts(msg, ep, bkv);
657 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write: Sending message";
659 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write: Done sending message";
664 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
669 TLOG(TLVL_WRITE) <<
"End: ArtdaqOutput::write(const EventPrincipal& ep)";
676 TLOG(TLVL_WRITERUN) <<
"Begin: ArtdaqOutput::writeRun(const RunPrincipal& rp)";
680 send_init_message(rp.history());
688 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
689 assert(run_aux_class !=
nullptr &&
"writeRun: Could not get TClass for art::RunAuxiliary!");
693 auto msg = prepareMessage(last_sequence_id_ + 1,rp.run() + 1, artdaq::Fragment::EndOfRunFragmentType);
698 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streaming message type code ...";
700 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: finished streaming message type code.";
706 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streaming RunAuxiliary ...";
707 msg->WriteObjectAny(&rp.runAux(), run_aux_class);
708 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streamed RunAuxiliary.";
713 std::vector<BranchKey*> bkv;
714 writeDataProducts(msg, rp, bkv);
716 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: Sending message";
718 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: Done sending message";
720 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
726 TLOG(TLVL_WRITERUN) <<
"End: ArtdaqOutput::writeRun(RunPrincipal& rp)";
732 TLOG(TLVL_WRITESUBRUN) <<
"Begin: ArtdaqOutput::writeSubRun(const SubRunPrincipal& srp)";
735 send_init_message(srp.history());
742 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
743 if (subrun_aux_class ==
nullptr)
745 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeSubRun: "
746 "Could not get TClass for art::SubRunAuxiliary!";
751 auto msg = prepareMessage(last_sequence_id_ + 1, srp.subRun() + 1, artdaq::Fragment::EndOfSubrunFragmentType);
756 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streaming message type code ...";
758 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: finished streaming message type code.";
764 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streaming SubRunAuxiliary ...";
766 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: dumping ProcessHistoryRegistry ...";
769 for (
auto I = std::begin(art::ProcessHistoryRegistry::get()), E = std::end(art::ProcessHistoryRegistry::get());
772 std::ostringstream OS;
774 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: id: '" << OS.str() <<
"'";
776 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: data.size(): " << I->second.data().size();
777 if (!I->second.data().empty())
779 I->second.data().back().id().print(OS);
780 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: data.back().id(): '" << OS.str() <<
"'";
783 if (!srp.subRunAux().processHistoryID().isValid())
785 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessHistoryID: 'INVALID'";
789 std::ostringstream OS;
790 srp.subRunAux().processHistoryID().print(OS);
791 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessHistoryID: '" << OS.str() <<
"'";
793 ProcessHistory processHistory;
794 ProcessHistoryRegistry::get(srp.subRunAux().processHistoryID(), processHistory);
795 if (!processHistory.data().empty())
798 processHistory.data().back().id().print(OS);
799 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessConfigurationID: '" << OS.str() <<
"'";
801 OS << processHistory.data().back();
802 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessConfiguration: '" << OS.str();
805 msg->WriteObjectAny(&srp.subRunAux(), subrun_aux_class);
806 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streamed SubRunAuxiliary.";
811 std::vector<BranchKey*> bkv;
812 writeDataProducts(msg, srp, bkv);
814 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: Sending message";
816 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: Done sending message";
821 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
826 TLOG(TLVL_WRITESUBRUN) <<
"End: ArtdaqOutput::writeSubRun(const SubRunPrincipal& srp)";
831 TLOG(TLVL_EXTRACTPRODUCTS) <<
"Begin: ArtdaqOutput::extractProducts_(Principal const& principal) sz=" << principal.size();
833 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
835 auto const& productDescription = I->second->productDescription();
836 auto const& branchKey = BranchKey(productDescription);
838 if (!productList_.count(branchKey))
840 TLOG(TLVL_EXTRACTPRODUCTS_VERBOSE) <<
"ArtdaqOutput::extractProducts_:"
841 <<
"Adding branch key to productList of class: '"
842 << branchKey.friendlyClassName_ <<
"' modlbl: '" << branchKey.moduleLabel_ <<
"' instnm: '"
843 << branchKey.productInstanceName_ <<
"' procnm: '" << branchKey.processName_ <<
"'"
844 <<
", description: " << productDescription.wrappedName();
846 productList_[branchKey] = productDescription;
850 TLOG(TLVL_EXTRACTPRODUCTS) <<
"End: ArtdaqOutput::extractProducts_(Principal const& principal) Product list sz=" << productList_.size();
853 #endif // ARTDAQ_ARTDAQ_ARTMODULES_ARTDAQOUTPUT_HH_
void writeRun(RunPrincipal &rp) final
Write a RunPrincipal to TBufferFile and send
virtual void event_(EventPrincipal const &)
Perform actions for each event. No-op, but derived classes may override
void send_init_message(History const &history)
Send an init message downstream. Use the given History for initializing downstream art processes...
void extractProducts_(Principal const &principal)
Extract the list of Products from the given Principal
This is the base class for artdaq OutputModules, providing the serialization interface for art Events...
virtual void beginSubRun_(SubRunPrincipal const &)
Perform Begin SubRun actions. No-op, but derived classes may override
virtual ~ArtdaqOutput()=default
Destructor
void event(EventPrincipal const &ep) final
Perform actions for each event. Derived classes should implement event_ instead.
virtual void openFile(FileBlock const &)
Perform actions necessary for opening files. No-op, but derived classes may override ...
virtual void endJob()
Perform End-of-Job actions. No-op, but derived classes may override
virtual void SendMessage(artdaq::FragmentPtr &msg)=0
Send the serialized art Event downstream. Artdaq output modules should define this function...
void beginRun(RunPrincipal const &rp) final
Perform Begin Run actions. Derived classes should implement beginRun_ instead.
void beginSubRun(SubRunPrincipal const &srp) final
Perform Begin SubRun actions. Derived classes should implement beginSubRun_ instead.
virtual void closeFile()
Perform actions necessary for closing files. No-op, but derived classes may override ...
ArtdaqOutput(fhicl::ParameterSet const &ps)
ArtdaqOutput Constructor
virtual void respondToCloseOutputFiles(FileBlock const &)
Perform actions necessary after closing the output file(s). No-op, but derived classes may override ...
void writeSubRun(SubRunPrincipal &srp) final
Write a SubRunPrincipal to TBufferFile and send
virtual void respondToCloseInputFile(FileBlock const &)
Perform actions nesessary after closing the input file. No-op, but derived classes may override ...
virtual void beginRun_(RunPrincipal const &)
Perform Begin Run actions. No-op, but derived classes may override
void write(EventPrincipal &ep) final
Write an EventPrincipal to TBufferFile and send
void writeDataProducts(std::unique_ptr< TBufferFile > &msg, const Principal &principal, std::vector< BranchKey * > &bkv)
Extract the data products from a Principal and write them to the TBufferFile