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/ProcessHistoryRegistry.h"
13 #if ART_HEX_VERSION < 0x30000
14 #include "art/Persistency/Provenance/ProductMetaData.h"
16 #if ART_HEX_VERSION >= 0x30200
17 #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/RawEvent.hh"
45 #include "artdaq-core/Data/detail/ParentageMap.hh"
47 #include <TBufferFile.h>
50 #include <TStreamerInfo.h>
62 #define TLVL_OPENFILE 5
63 #define TLVL_CLOSEFILE 6
64 #define TLVL_RESPONDTOCLOSEINPUTFILE 7
65 #define TLVL_RESPONDTOCLOSEOUTPUTFILE 8
67 #define TLVL_SENDINIT 10
68 #define TLVL_SENDINIT_VERBOSE1 32
69 #define TLVL_SENDINIT_VERBOSE2 33
70 #define TLVL_WRITEDATAPRODUCTS 11
71 #define TLVL_WRITEDATAPRODUCTS_VERBOSE 34
73 #define TLVL_WRITERUN 13
74 #define TLVL_WRITERUN_VERBOSE 37
75 #define TLVL_WRITESUBRUN 14
76 #define TLVL_WRITESUBRUN_VERBOSE 35
77 #define TLVL_EXTRACTPRODUCTS 15
78 #define TLVL_EXTRACTPRODUCTS_VERBOSE 36
80 #if ART_HEX_VERSION < 0x30000
82 #define SUBRUN_AUX aux
88 #define RUN_AUX runAux
89 #define SUBRUN_AUX subRunAux
90 #define EVENT_AUX eventAux
92 #define SUBRUN_ID subRunID
93 #define EVENT_ID eventID
100 static artdaq::FragmentPtr outputFrag =
nullptr;
101 inline char* Fragment_ReAllocChar(
char* dataPtr,
size_t size,
size_t )
103 if (outputFrag !=
nullptr && dataPtr == reinterpret_cast<char*>(outputFrag->dataBegin()))
105 outputFrag->resizeBytes(size);
107 return reinterpret_cast<char*
>(outputFrag->dataBegin());
123 : OutputModule(ps), productList_(), raw_data_label_(ps.get<std::string>(
"raw_data_label",
"daq"))
125 #if ART_HEX_VERSION >= 0x30200
141 TLOG(TLVL_OPENFILE) <<
"Begin/End: ArtdaqOutput::openFile(const FileBlock&)";
147 virtual void closeFile() { TLOG(TLVL_CLOSEFILE) <<
"Begin/End: ArtdaqOutput::closeFile()"; }
154 TLOG(TLVL_RESPONDTOCLOSEINPUTFILE) <<
"Begin/End: ArtdaqOutput::"
155 "respondToCloseOutputFiles(FileBlock const&)";
163 TLOG(TLVL_RESPONDTOCLOSEOUTPUTFILE) <<
"Begin/End: ArtdaqOutput::"
164 "respondToCloseOutputFiles(FileBlock const&)";
172 TLOG(TLVL_ENDJOB) <<
"Begin/End: ArtdaqOutput::endJob()";
207 void event(EventPrincipal
const& ep)
final
215 virtual void event_(EventPrincipal
const&) {}
221 void write(EventPrincipal& ep)
final;
227 void writeRun(RunPrincipal& rp)
final;
241 void writeDataProducts(std::unique_ptr<TBufferFile>& msg,
const Principal& principal, std::vector<BranchKey*>& bkv);
259 virtual void SendMessage(artdaq::FragmentPtr& msg) = 0;
267 bool initMsgSent_{
false};
268 ProductList productList_;
269 size_t last_fragment_size_{10};
270 artdaq::Fragment::sequence_id_t last_sequence_id_{0};
271 artdaq::Fragment::timestamp_t last_timestamp_{0};
272 std::string raw_data_label_;
274 std::unique_ptr<TBufferFile> prepareMessage(artdaq::Fragment::sequence_id_t seqID, artdaq::Fragment::timestamp_t ts, artdaq::Fragment::type_t type)
277 outputFrag = std::make_unique<artdaq::Fragment>(last_fragment_size_, seqID, my_rank, type, hdr, ts);
278 auto msg = std::make_unique<TBufferFile>(TBuffer::kWrite, last_fragment_size_ *
sizeof(artdaq::RawDataType), outputFrag->dataBegin(), kFALSE, &Fragment_ReAllocChar);
281 if (seqID > last_sequence_id_) last_sequence_id_ = seqID;
282 if (ts > last_timestamp_) last_timestamp_ = ts;
287 void sendMessage(std::unique_ptr<TBufferFile>& msg)
290 hdr.
data_length =
static_cast<uint64_t
>(msg->Length());
291 outputFrag->updateMetadata(hdr);
293 last_fragment_size_ = std::ceil(msg->Length() /
static_cast<double>(
sizeof(artdaq::RawDataType)));
300 TLOG(TLVL_SENDINIT) <<
"Begin: ArtdaqOutput::send_init_message()";
310 static TClass* product_list_class = TClass::GetClass(
"std::map<art::BranchKey,art::BranchDescription>");
311 if (product_list_class ==
nullptr)
313 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
314 "Could not get TClass for "
315 "map<art::BranchKey,art::BranchDescription>!";
321 static TClass* process_history_map_class = TClass::GetClass(
"std::map<const art::Hash<2>,art::ProcessHistory>");
322 if (process_history_map_class ==
nullptr)
324 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
325 "Could not get class for "
326 "std::map<const art::Hash<2>,art::ProcessHistory>!";
330 static TClass* parentage_map_class = TClass::GetClass(
"art::ParentageMap");
331 if (parentage_map_class ==
nullptr)
333 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
334 "Could not get class for ParentageMap.";
336 TLOG(TLVL_SENDINIT) <<
"parentage_map_class: " <<
static_cast<void*
>(parentage_map_class);
338 static TClass* history_class = TClass::GetClass(
"art::History");
339 if (history_class ==
nullptr)
341 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message(): "
342 "Could not get TClass for art::History!";
348 auto msg = prepareMessage(0, 0, artdaq::Fragment::InitFragmentType);
352 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming message type code ...";
354 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming message type code.";
361 std::vector<std::string> classNames{
"std::map<art::BranchKey,art::BranchDescription>",
"std::map<const art::Hash<2>,art::ProcessHistory>",
"art::ParentageMap",
362 "art::History",
"art::BranchKey",
"art::ProductProvenance",
"art::RunAuxiliary",
"art::SubRunAuxiliary",
"art::EventAuxiliary"};
363 for (
auto& className : classNames)
365 TClass* class_ptr = TClass::GetClass(className.c_str());
366 if (class_ptr ==
nullptr)
368 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::send_init_message: Could not get TClass for " << className <<
"!";
370 infos.Add(class_ptr->GetStreamerInfo());
372 msg->WriteObject(&infos);
377 ULong_t ps_cnt = fhicl::ParameterSetRegistry::size();
378 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): parameter set count: " << ps_cnt;
379 msg->WriteULong(ps_cnt);
380 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming parameter sets ...";
381 for (
auto I = std::begin(fhicl::ParameterSetRegistry::get()), E = std::end(fhicl::ParameterSetRegistry::get());
384 TLOG(TLVL_SENDINIT) <<
"Pset ID " << I->first <<
": " << I->second.to_string();
385 std::string pset_str = I->second.to_string();
387 msg->WriteStdString(pset_str);
389 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming parameter sets.";
394 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming Product List sz=" << productList_.size() <<
"...";
395 msg->WriteObjectAny(&productList_, product_list_class);
396 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming Product List.";
398 art::ProcessHistoryMap phr;
399 for (
auto const& pr : art::ProcessHistoryRegistry::get())
406 TLOG(TLVL_SENDINIT_VERBOSE2) <<
"ArtdaqOutput::send_init_message(): Dumping ProcessHistoryRegistry ...";
409 TLOG(TLVL_SENDINIT_VERBOSE2) <<
"ArtdaqOutput::send_init_message(): phr: size: " << phr.size();
410 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
412 std::ostringstream OS;
414 TLOG(TLVL_SENDINIT_VERBOSE2) <<
"ArtdaqOutput::send_init_message(): phr: id: '" << OS.str() <<
"'";
419 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming ProcessHistoryRegistry ...";
422 const art::ProcessHistoryMap& phm = phr;
423 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): phm: size: " << phm.size();
424 msg->WriteObjectAny(&phm, process_history_map_class);
425 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming ProcessHistoryRegistry.";
430 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming ParentageRegistry ..." <<
static_cast<void*
>(parentage_map_class);
431 art::ParentageMap parentageMap{};
432 for (
auto const& pr : art::ParentageRegistry::get())
434 parentageMap.emplace(pr.first, pr.second);
437 msg->WriteObjectAny(&parentageMap, parentage_map_class);
439 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Finished streaming ParentageRegistry.";
441 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Streaming History";
442 msg->WriteObjectAny(&history, history_class);
443 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Done streaming History";
445 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Sending init message";
447 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): Done sending init message";
449 TLOG(TLVL_SENDINIT) <<
"ArtdaqOutput::send_init_message(): END";
454 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"Begin: ArtdaqOutput::writeDataProducts(...)";
459 static TClass* branch_key_class = TClass::GetClass(
"art::BranchKey");
460 if (branch_key_class ==
nullptr)
462 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeDataProducts(...): "
463 "Could not get TClass for art::BranchKey!";
465 static TClass* prdprov_class = TClass::GetClass(
"art::ProductProvenance");
466 if (prdprov_class ==
nullptr)
468 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeDataProducts(...): "
469 "Could not get TClass for art::ProductProvenance!";
477 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
479 auto const& productDescription = I->second->productDescription();
480 auto const& refs = keptProducts()[productDescription.branchType()];
482 for (
auto const& ref : refs)
484 #if ART_HEX_VERSION < 0x30000
485 if (*ref == productDescription)
488 if (ref.second == productDescription)
495 #if ART_HEX_VERSION < 0x30000
496 if (I->second->productUnavailable() || !found)
498 if (!I->second->productAvailable() || !found)
508 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): Streaming product count: " +
509 std::to_string(prd_cnt);
510 msg->WriteULong(prd_cnt);
511 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): Finished streaming product count.";
523 bkv.reserve(prd_cnt);
525 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
527 auto const& productDescription = I->second->productDescription();
528 auto const& refs = keptProducts()[productDescription.branchType()];
530 for (
auto const& ref : refs)
532 #if ART_HEX_VERSION < 0x30000
533 if (*ref == productDescription)
536 if (ref.second == productDescription)
543 #if ART_HEX_VERSION < 0x30000
544 if (I->second->productUnavailable() || !found)
546 if (!I->second->productAvailable() || !found)
551 const BranchDescription& bd(I->second->productDescription());
552 bkv.push_back(
new BranchKey(bd));
553 TLOG(TLVL_WRITEDATAPRODUCTS_VERBOSE)
554 <<
"ArtdaqOutput::writeDataProducts(...): Dumping branch key of class: '"
555 << bkv.back()->friendlyClassName_ <<
"' modlbl: '" << bkv.back()->moduleLabel_ <<
"' instnm: '"
556 << bkv.back()->productInstanceName_ <<
"' procnm: '" << bkv.back()->processName_ <<
"'";
557 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
558 "Streaming branch key of class: '"
559 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
560 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
561 msg->WriteObjectAny(bkv.back(), branch_key_class);
563 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
564 "Streaming product of class: '"
565 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
566 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
568 OutputHandle oh = principal.getForOutput(bd.productID(),
true);
569 const EDProduct* prd = oh.wrapper();
570 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"Class for branch " << bd.wrappedName() <<
" is "
571 <<
static_cast<void*
>(TClass::GetClass(bd.wrappedName().c_str()));
572 msg->WriteObjectAny(prd, TClass::GetClass(bd.wrappedName().c_str()));
573 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"ArtdaqOutput::writeDataProducts(...): "
574 "Streaming product provenance of class: '"
575 << bd.producedClassName() <<
"' modlbl: '" << bd.moduleLabel() <<
"' instnm: '"
576 << bd.productInstanceName() <<
"' procnm: '" << bd.processName() <<
"'";
577 #if ART_HEX_VERSION < 0x30000
578 const ProductProvenance* prdprov = I->second->productProvenancePtr().get();
580 const ProductProvenance* prdprov = I->second->productProvenance().get();
582 msg->WriteObjectAny(prdprov, prdprov_class);
584 TLOG(TLVL_WRITEDATAPRODUCTS) <<
"End: ArtdaqOutput::writeDataProducts(...)";
592 TLOG(TLVL_WRITE) <<
"Begin: ArtdaqOutput::write(const EventPrincipal& ep)";
595 send_init_message(ep.history());
601 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
602 if (run_aux_class ==
nullptr)
604 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
605 "Could not get TClass for art::RunAuxiliary!";
607 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
608 if (subrun_aux_class ==
nullptr)
610 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
611 "Could not get TClass for art::SubRunAuxiliary!";
613 static TClass* event_aux_class = TClass::GetClass(
"art::EventAuxiliary");
614 if (event_aux_class ==
nullptr)
616 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
617 "Could not get TClass for art::EventAuxiliary!";
619 static TClass* history_class = TClass::GetClass(
"art::History");
620 if (history_class ==
nullptr)
622 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::write(const EventPrincipal& ep): "
623 "Could not get TClass for art::History!";
627 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Setting Output Fragment Header Fields";
628 auto seqID = (
static_cast<uint64_t
>(ep.EVENT_ID().subRun() - 1) << 32) + ep.EVENT_ID().event();
630 #if ART_HEX_VERSION > 0x30000
631 art::ProcessTag tag(
"", processName());
632 auto res = ep.getMany(art::ModuleContext::invalid(), art::WrappedTypeID::make<artdaq::detail::RawEventHeader>(), art::MatchAllSelector(), tag);
634 auto res = ep.getMany( art::WrappedTypeID::make<artdaq::detail::RawEventHeader>(), art::MatchAllSelector());
637 artdaq::Fragment::timestamp_t ts = 0;
639 for (
auto const& qr : res)
641 Handle<artdaq::detail::RawEventHeader> handle{qr};
642 if (handle.isValid()) {
643 if (handle->timestamp > ts) ts = handle->timestamp;
646 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Data Fragment Header Fields: SeqID: " << seqID <<
", timestamp: " << ts;
652 auto msg = prepareMessage(seqID, ts, artdaq::Fragment::DataFragmentType);
656 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming message type code ...";
658 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming message type code.";
663 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming RunAuxiliary ...";
664 msg->WriteObjectAny(&ep.subRunPrincipal().runPrincipal().RUN_AUX(), run_aux_class);
665 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming RunAuxiliary.";
670 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming SubRunAuxiliary ...";
671 msg->WriteObjectAny(&ep.subRunPrincipal().SUBRUN_AUX(), subrun_aux_class);
672 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming SubRunAuxiliary.";
678 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming EventAuxiliary ...";
679 msg->WriteObjectAny(&ep.EVENT_AUX(), event_aux_class);
680 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming EventAuxiliary.";
686 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Streaming History ...";
687 msg->WriteObjectAny(&ep.history(), history_class);
688 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write(const EventPrincipal& ep): Finished streaming History.";
693 std::vector<BranchKey*> bkv;
694 writeDataProducts(msg, ep, bkv);
696 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write: Sending message";
698 TLOG(TLVL_WRITE) <<
"ArtdaqOutput::write: Done sending message";
703 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
708 TLOG(TLVL_WRITE) <<
"End: ArtdaqOutput::write(const EventPrincipal& ep)";
715 TLOG(TLVL_WRITERUN) <<
"Begin: ArtdaqOutput::writeRun(const RunPrincipal& rp)";
719 #if ART_HEX_VERSION < 0x30000
720 send_init_message(art::History());
722 send_init_message(rp.history());
731 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
732 assert(run_aux_class !=
nullptr &&
"writeRun: Could not get TClass for art::RunAuxiliary!");
736 auto msg = prepareMessage(last_sequence_id_ + 1,last_timestamp_ + 1, artdaq::Fragment::EndOfRunFragmentType);
741 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streaming message type code ...";
743 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: finished streaming message type code.";
749 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streaming RunAuxiliary ...";
750 msg->WriteObjectAny(&rp.RUN_AUX(), run_aux_class);
751 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: streamed RunAuxiliary.";
756 std::vector<BranchKey*> bkv;
757 writeDataProducts(msg, rp, bkv);
759 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: Sending message";
761 TLOG(TLVL_WRITERUN) <<
"ArtdaqOutput::writeRun: Done sending message";
763 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
769 TLOG(TLVL_WRITERUN) <<
"End: ArtdaqOutput::writeRun(RunPrincipal& rp)";
775 TLOG(TLVL_WRITESUBRUN) <<
"Begin: ArtdaqOutput::writeSubRun(const SubRunPrincipal& srp)";
778 #if ART_HEX_VERSION < 0x30000
779 send_init_message(art::History());
781 send_init_message(srp.history());
789 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
790 if (subrun_aux_class ==
nullptr)
792 throw art::Exception(art::errors::DictionaryNotFound) <<
"ArtdaqOutput::writeSubRun: "
793 "Could not get TClass for art::SubRunAuxiliary!";
798 auto msg = prepareMessage(last_sequence_id_ + 1, last_timestamp_ + 1, artdaq::Fragment::EndOfSubrunFragmentType);
803 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streaming message type code ...";
805 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: finished streaming message type code.";
811 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streaming SubRunAuxiliary ...";
813 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: dumping ProcessHistoryRegistry ...";
816 for (
auto I = std::begin(art::ProcessHistoryRegistry::get()), E = std::end(art::ProcessHistoryRegistry::get());
819 std::ostringstream OS;
821 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: id: '" << OS.str() <<
"'";
823 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: data.size(): " << I->second.data().size();
824 if (!I->second.data().empty())
826 I->second.data().back().id().print(OS);
827 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: phr: data.back().id(): '" << OS.str() <<
"'";
830 if (!srp.SUBRUN_AUX().processHistoryID().isValid())
832 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessHistoryID: 'INVALID'";
836 std::ostringstream OS;
837 srp.SUBRUN_AUX().processHistoryID().print(OS);
838 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessHistoryID: '" << OS.str() <<
"'";
840 ProcessHistory processHistory;
841 ProcessHistoryRegistry::get(srp.SUBRUN_AUX().processHistoryID(), processHistory);
842 if (!processHistory.data().empty())
845 processHistory.data().back().id().print(OS);
846 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessConfigurationID: '" << OS.str() <<
"'";
848 OS << processHistory.data().back();
849 TLOG(TLVL_WRITESUBRUN_VERBOSE) <<
"ArtdaqOutput::writeSubRun: ProcessConfiguration: '" << OS.str();
852 msg->WriteObjectAny(&srp.SUBRUN_AUX(), subrun_aux_class);
853 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: streamed SubRunAuxiliary.";
858 std::vector<BranchKey*> bkv;
859 writeDataProducts(msg, srp, bkv);
861 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: Sending message";
863 TLOG(TLVL_WRITESUBRUN) <<
"ArtdaqOutput::writeSubRun: Done sending message";
868 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
873 TLOG(TLVL_WRITESUBRUN) <<
"End: ArtdaqOutput::writeSubRun(const SubRunPrincipal& srp)";
878 TLOG(TLVL_EXTRACTPRODUCTS) <<
"Begin: ArtdaqOutput::extractProducts_(Principal const& principal) sz=" << principal.size();
879 #if ART_HEX_VERSION < 0x30000
880 productList_ = art::ProductMetaData::instance().productList();
883 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
885 auto const& productDescription = I->second->productDescription();
886 auto const& branchKey = BranchKey(productDescription);
888 if (!productList_.count(branchKey))
890 TLOG(TLVL_EXTRACTPRODUCTS_VERBOSE) <<
"ArtdaqOutput::extractProducts_:"
891 <<
"Adding branch key to productList of class: '"
892 << branchKey.friendlyClassName_ <<
"' modlbl: '" << branchKey.moduleLabel_ <<
"' instnm: '"
893 << branchKey.productInstanceName_ <<
"' procnm: '" << branchKey.processName_ <<
"'"
894 <<
", description: " << productDescription.wrappedName();
896 productList_[branchKey] = productDescription;
901 TLOG(TLVL_EXTRACTPRODUCTS) <<
"End: ArtdaqOutput::extractProducts_(Principal const& principal) Product list sz=" << productList_.size();
904 #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