2 #include "art/Framework/Core/OutputModule.h"
3 #include "art/Framework/Principal/EventPrincipal.h"
4 #include "art/Framework/Principal/OutputHandle.h"
5 #include "art/Framework/Principal/RunPrincipal.h"
6 #include "art/Framework/Principal/SubRunPrincipal.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Services/Registry/ServiceHandle.h"
10 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
11 #if ART_HEX_VERSION < 0x30000
12 #include "art/Persistency/Provenance/ProductMetaData.h"
14 #if ART_HEX_VERSION >= 0x30200
15 #include "art_root_io/setup.h"
20 #include "canvas/Persistency/Provenance/BranchDescription.h"
21 #include "canvas/Persistency/Provenance/BranchKey.h"
22 #include "canvas/Persistency/Provenance/History.h"
23 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
24 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
25 #include "canvas/Persistency/Provenance/ProcessConfigurationID.h"
26 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
27 #include "canvas/Persistency/Provenance/ProductList.h"
28 #include "canvas/Persistency/Provenance/ProductProvenance.h"
29 #include "canvas/Persistency/Provenance/RunAuxiliary.h"
30 #include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
31 #include "canvas/Utilities/DebugMacros.h"
32 #include "canvas/Utilities/Exception.h"
33 #include "cetlib/column_width.h"
34 #include "cetlib/lpad.h"
35 #include "cetlib/rpad.h"
36 #include "fhiclcpp/ParameterSet.h"
37 #include "fhiclcpp/ParameterSetID.h"
38 #include "fhiclcpp/ParameterSetRegistry.h"
40 #include "artdaq/DAQdata/Globals.hh"
41 #include "artdaq/DAQdata/NetMonHeader.hh"
43 #include "artdaq-core/Data/Fragment.hh"
44 #include "artdaq-core/Data/detail/ParentageMap.hh"
54 #include <TBufferFile.h>
57 #include <TStreamerInfo.h>
59 #define TLVL_OPENFILE 5
60 #define TLVL_CLOSEFILE 6
61 #define TLVL_RESPONDTOCLOSEINPUTFILE 7
62 #define TLVL_RESPONDTOCLOSEOUTPUTFILE 8
64 #define TLVL_SENDINIT 10
65 #define TLVL_SENDINIT_VERBOSE1 32
66 #define TLVL_SENDINIT_VERBOSE2 33
67 #define TLVL_WRITEDATAPRODUCTS 11
68 #define TLVL_WRITEDATAPRODUCTS_VERBOSE 34
70 #define TLVL_WRITERUN 13
71 #define TLVL_WRITERUN_VERBOSE 37
72 #define TLVL_WRITESUBRUN 14
73 #define TLVL_WRITESUBRUN_VERBOSE 35
74 #define TLVL_EXTRACTPRODUCTS 15
75 #define TLVL_EXTRACTPRODUCTS_VERBOSE 36
77 #if ART_HEX_VERSION < 0x30000
79 #define SUBRUN_AUX aux
85 #define RUN_AUX runAux
86 #define SUBRUN_AUX subRunAux
87 #define EVENT_AUX eventAux
89 #define SUBRUN_ID subRunID
90 #define EVENT_ID eventID
97 static artdaq::FragmentPtr outputFrag =
nullptr;
98 char* Fragment_ReAllocChar(
char* dataPtr,
size_t size,
size_t )
100 if (outputFrag !=
nullptr && dataPtr == reinterpret_cast<char*>(outputFrag->dataBegin()))
102 outputFrag->resizeBytes(size);
104 return reinterpret_cast<char*
>(outputFrag->dataBegin());
120 : OutputModule(ps), initMsgSent_(false), productList_(), last_fragment_size_(10)
122 #if ART_HEX_VERSION >= 0x30200
138 TLOG(TLVL_OPENFILE) <<
"Begin/End: ArtdaqOutput::openFile(const FileBlock&)";
144 virtual void closeFile() { TLOG(TLVL_CLOSEFILE) <<
"Begin/End: ArtdaqOutput::closeFile()"; }
151 TLOG(TLVL_RESPONDTOCLOSEINPUTFILE) <<
"Begin/End: ArtdaqOutput::"
152 "respondToCloseOutputFiles(FileBlock const&)";
160 TLOG(TLVL_RESPONDTOCLOSEOUTPUTFILE) <<
"Begin/End: ArtdaqOutput::"
161 "respondToCloseOutputFiles(FileBlock const&)";
169 TLOG(TLVL_ENDJOB) <<
"Begin/End: ArtdaqOutput::endJob()";
176 virtual void beginRun(RunPrincipal
const& rp)
final
204 virtual void event(EventPrincipal
const& ep)
final
212 virtual void event_(EventPrincipal
const&) {}
218 virtual void write(EventPrincipal& ep)
final;
224 virtual void writeRun(RunPrincipal& rp)
final;
230 virtual void writeSubRun(SubRunPrincipal& srp)
final;
238 void writeDataProducts(std::unique_ptr<TBufferFile>& msg,
const Principal& principal, std::vector<BranchKey*>& bkv);
256 virtual void SendMessage(artdaq::FragmentPtr& msg) = 0;
260 ProductList productList_;
261 size_t last_fragment_size_;
263 std::unique_ptr<TBufferFile> prepareMessage(artdaq::Fragment::sequence_id_t seqID, artdaq::Fragment::type_t type)
266 outputFrag.reset(
new artdaq::Fragment(last_fragment_size_, seqID, 0, type, hdr));
267 std::unique_ptr<TBufferFile> msg(
new TBufferFile(TBuffer::kWrite, last_fragment_size_ *
sizeof(artdaq::RawDataType), outputFrag->dataBegin(), kFALSE, &Fragment_ReAllocChar));
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: " << (
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, 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 unsigned long 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 ..." << (
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!";
460 unsigned long prd_cnt = 0;
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 ART_HEX_VERSION < 0x30000
470 if (*ref == productDescription)
473 if (ref.second == productDescription)
480 #if ART_HEX_VERSION < 0x30000
481 if (I->second->productUnavailable() || !found)
483 if (!I->second->productAvailable() || !found)
493 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): Streaming product count: " +
494 std::to_string(prd_cnt);
495 msg->WriteULong(prd_cnt);
496 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): Finished streaming product count.";
508 bkv.reserve(prd_cnt);
510 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
512 auto const& productDescription = I->second->productDescription();
513 auto const& refs = keptProducts()[productDescription.branchType()];
515 for (
auto const& ref : refs)
517 #if ART_HEX_VERSION < 0x30000
518 if (*ref == productDescription)
521 if (ref.second == productDescription)
528 #if ART_HEX_VERSION < 0x30000
529 if (I->second->productUnavailable() || !found)
531 if (!I->second->productAvailable() || !found)
536 const BranchDescription& bd(I->second->productDescription());
537 bkv.push_back(
new BranchKey(bd));
538 TLOG(TLVL_WRITEDATAPRODUCTS_VERBOSE)
539 <<
"ArtdaqOutput::writeDataProducts(...): Dumping branch key of class: '"
540 << bkv.back()->friendlyClassName_ <<
"' modlbl: '" << bkv.back()->moduleLabel_ <<
"' instnm: '"
541 << bkv.back()->productInstanceName_ <<
"' procnm: '" << bkv.back()->processName_ <<
"'";
542 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
543 "Streaming branch key of class: '"
544 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
545 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
546 msg->WriteObjectAny(bkv.back(), branch_key_class);
548 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
549 "Streaming product of class: '"
550 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
551 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
553 OutputHandle oh = principal.getForOutput(bd.productID(),
true);
554 const EDProduct* prd = oh.wrapper();
555 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"Class for branch " << bd.wrappedName() <<
" is "
556 << (
void*)TClass::GetClass(bd.wrappedName().c_str());
557 msg->WriteObjectAny(prd, TClass::GetClass(bd.wrappedName().c_str()));
558 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
559 "Streaming product provenance of class: '"
560 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
561 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
562 #if ART_HEX_VERSION < 0x30000
563 const ProductProvenance* prdprov = I->second->productProvenancePtr().get();
565 const ProductProvenance* prdprov = I->second->productProvenance().get();
567 msg->WriteObjectAny(prdprov, prdprov_class);
569 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"End: ArtdaqOutput::writeDataProducts(...)";
577 TLOG(TLVL_WRITE) <<
"Begin: ArtdaqOutput::write(const EventPrincipal& ep)";
580 send_init_message(ep.history());
586 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
587 if (run_aux_class ==
nullptr)
589 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
590 "Could not get TClass for art::RunAuxiliary!";
592 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
593 if (subrun_aux_class ==
nullptr)
595 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
596 "Could not get TClass for art::SubRunAuxiliary!";
598 static TClass* event_aux_class = TClass::GetClass(
"art::EventAuxiliary");
599 if (event_aux_class ==
nullptr)
601 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
602 "Could not get TClass for art::EventAuxiliary!";
604 static TClass* history_class = TClass::GetClass(
"art::History");
605 if (history_class ==
nullptr)
607 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
608 "Could not get TClass for art::History!";
613 auto msg = prepareMessage(ep.EVENT_ID().event(), 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().RUN_AUX(), 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().SUBRUN_AUX(), 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.EVENT_AUX(), 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 #if ART_HEX_VERSION < 0x30000
681 send_init_message(art::History());
683 send_init_message(rp.history());
692 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
693 assert(run_aux_class !=
nullptr &&
"writeRun: Could not get TClass for art::RunAuxiliary!");
697 auto msg = prepareMessage(0, artdaq::Fragment::EndOfRunFragmentType);
702 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streaming message type code ...";
704 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: finished streaming message type code.";
710 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streaming RunAuxiliary ...";
711 msg->WriteObjectAny(&rp.RUN_AUX(), run_aux_class);
712 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streamed RunAuxiliary.";
717 std::vector<BranchKey*> bkv;
718 writeDataProducts(msg, rp, bkv);
720 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: Sending message";
722 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: Done sending message";
724 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
730 TLOG(TLVL_WRITERUN) <<
"End: ArtdaqOutput::writeRun(RunPrincipal& rp)";
736 TLOG(TLVL_WRITESUBRUN) <<
"Begin: ArtdaqOutput::writeSubRun(const SubRunPrincipal& srp)";
739 #if ART_HEX_VERSION < 0x30000
740 send_init_message(art::History());
742 send_init_message(srp.history());
750 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
751 if (subrun_aux_class ==
nullptr)
753 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeSubRun: "
754 "Could not get TClass for art::SubRunAuxiliary!";
759 auto msg = prepareMessage(0, artdaq::Fragment::EndOfSubrunFragmentType);
764 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streaming message type code ...";
766 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: finished streaming message type code.";
772 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streaming SubRunAuxiliary ...";
774 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: dumping ProcessHistoryRegistry ...";
777 for (
auto I = std::begin(art::ProcessHistoryRegistry::get()), E = std::end(art::ProcessHistoryRegistry::get());
780 std::ostringstream OS;
782 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: id: '" << OS.str() <<
"'";
784 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: data.size(): " << I->second.data().size();
785 if (I->second.data().size())
787 I->second.data().back().id().print(OS);
788 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: data.back().id(): '" << OS.str() <<
"'";
791 if (!srp.SUBRUN_AUX().processHistoryID().isValid())
793 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessHistoryID: 'INVALID'";
797 std::ostringstream OS;
798 srp.SUBRUN_AUX().processHistoryID().print(OS);
799 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessHistoryID: '" << OS.str() <<
"'";
801 ProcessHistory processHistory;
802 ProcessHistoryRegistry::get(srp.SUBRUN_AUX().processHistoryID(), processHistory);
803 if (processHistory.data().size())
806 processHistory.data().back().id().print(OS);
807 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessConfigurationID: '" << OS.str() <<
"'";
809 OS << processHistory.data().back();
810 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessConfiguration: '" << OS.str();
813 msg->WriteObjectAny(&srp.SUBRUN_AUX(), subrun_aux_class);
814 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streamed SubRunAuxiliary.";
819 std::vector<BranchKey*> bkv;
820 writeDataProducts(msg, srp, bkv);
822 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: Sending message";
824 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: Done sending message";
829 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
834 TLOG(TLVL_WRITESUBRUN) <<
"End: ArtdaqOutput::writeSubRun(const SubRunPrincipal& srp)";
839 TLOG(TLVL_EXTRACTPRODUCTS) <<
"Begin: ArtdaqOutput::extractProducts_(Principal const& principal) sz=" << principal.size();
840 #if ART_HEX_VERSION < 0x30000
841 productList_ = art::ProductMetaData::instance().productList();
844 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
846 auto const& productDescription = I->second->productDescription();
847 auto const& branchKey = BranchKey(productDescription);
849 if (!productList_.count(branchKey))
851 TLOG(TLVL_EXTRACTPRODUCTS_VERBOSE) <<
"ArtdaqOutput::extractProducts_:"
852 <<
"Adding branch key to productList of class: '"
853 << branchKey.friendlyClassName_ <<
"' modlbl: '" << branchKey.moduleLabel_ <<
"' instnm: '"
854 << branchKey.productInstanceName_ <<
"' procnm: '" << branchKey.processName_ <<
"'"
855 <<
", description: " << productDescription.wrappedName();
857 productList_[branchKey] = productDescription;
862 TLOG(TLVL_EXTRACTPRODUCTS) <<
"End: ArtdaqOutput::extractProducts_(Principal const& principal) Product list sz=" << productList_.size();
virtual void writeRun(RunPrincipal &rp) final
Write a RunPrincipal to TBufferFile and send
virtual void event(EventPrincipal const &ep) final
Perform actions for each event. Derived classes should implement event_ instead.
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
virtual void beginSubRun(SubRunPrincipal const &srp) final
Perform Begin SubRun actions. Derived classes should implement beginSubRun_ instead.
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
virtual void beginRun(RunPrincipal const &rp) final
Perform Begin Run actions. Derived classes should implement beginRun_ 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...
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 ...
virtual 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
virtual 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