1 #include "art/Framework/Core/ModuleMacros.h"
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"
7 #include "art/Framework/Services/Registry/ServiceHandle.h"
8 #if ART_HEX_VERSION >= 0x20703
11 # include "art/Persistency/Provenance/BranchIDListHelper.h"
13 #if ART_HEX_VERSION < 0x20900
14 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
15 #include "canvas/Persistency/Provenance/BranchIDList.h"
17 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
18 #include "art/Persistency/Provenance/ProductMetaData.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"
37 #include "fhiclcpp/ParameterSet.h"
38 #include "fhiclcpp/ParameterSetID.h"
39 #include "fhiclcpp/ParameterSetRegistry.h"
41 #include "artdaq/TransferPlugins/TransferInterface.hh"
42 #include "artdaq/TransferPlugins/MakeTransferPlugin.hh"
43 #include "artdaq-core/Data/detail/ParentageMap.hh"
44 #include "artdaq/DAQdata/Globals.hh"
45 #include "artdaq/DAQdata/NetMonHeader.hh"
87 virtual void openFile(FileBlock
const&);
89 virtual void closeFile();
91 virtual void respondToCloseInputFile(FileBlock
const&);
93 virtual void respondToCloseOutputFiles(FileBlock
const&);
95 virtual void endJob();
97 virtual void write(EventPrincipal&);
99 virtual void writeRun(RunPrincipal&);
101 virtual void writeSubRun(SubRunPrincipal&);
103 void writeDataProducts(TBufferFile&,
const Principal&,
104 std::vector<BranchKey*>&);
108 std::unique_ptr<artdaq::TransferInterface> transfer_;
110 void sendMessage_(uint64_t sequenceId, uint8_t messageType, TBufferFile& msg);
111 void send_init_message();
118 , initMsgSent_(false)
120 TLOG_DEBUG(
"TransferOutput") <<
"Begin: TransferOutput::TransferOutput(ParameterSet const& ps)" << TLOG_ENDL;
122 TLOG_DEBUG(
"TransferOutput") <<
"END: TransferOutput::TransferOutput" << TLOG_ENDL;
128 TLOG_DEBUG(
"TransferOutput") <<
"Begin: TransferOutput::~TransferOutput()" << TLOG_ENDL;
130 auto sts = transfer_->moveFragment(std::move(*artdaq::Fragment::eodFrag(0)));
132 transfer_.reset(
nullptr);
136 art::TransferOutput::
137 openFile(FileBlock
const&)
139 TLOG_TRACE(
"TransferOutput") <<
"Begin/End: TransferOutput::openFile(const FileBlock&)" << TLOG_ENDL;
143 art::TransferOutput::
146 TLOG_TRACE(
"TransferOutput") <<
"Begin/End: TransferOutput::closeFile()" << TLOG_ENDL;
150 art::TransferOutput::
151 respondToCloseInputFile(FileBlock
const&)
153 TLOG_TRACE(
"TransferOutput") <<
"Begin/End: TransferOutput::" <<
154 "respondToCloseOutputFiles(FileBlock const&)" << TLOG_ENDL;
158 art::TransferOutput::
159 respondToCloseOutputFiles(FileBlock
const&)
161 TLOG_TRACE(
"TransferOutput") <<
"Begin/End: TransferOutput::" <<
162 "respondToCloseOutputFiles(FileBlock const&)" << TLOG_ENDL;
166 art::TransferOutput::
169 TLOG_TRACE(
"TransferOutput") <<
"Begin: TransferOutput::endJob()" << TLOG_ENDL;
175 art::TransferOutput::
178 TLOG_TRACE(
"TransferOutput") <<
"Begin: TransferOutput static send_init_message()" << TLOG_ENDL;
188 static TClass* product_list_class = TClass::GetClass(
189 "std::map<art::BranchKey,art::BranchDescription>");
190 if (product_list_class ==
nullptr)
192 throw art::Exception(art::errors::DictionaryNotFound) <<
193 "TransferOutput static send_init_message(): "
194 "Could not get TClass for "
195 "map<art::BranchKey,art::BranchDescription>!";
201 static TClass* process_history_map_class = TClass::GetClass(
202 "std::map<const art::Hash<2>,art::ProcessHistory>");
203 if (process_history_map_class ==
nullptr)
205 throw art::Exception(art::errors::DictionaryNotFound) <<
206 "TransferOutput static send_init_message(): "
207 "Could not get class for "
208 "std::map<const art::Hash<2>,art::ProcessHistory>!";
213 static TClass* parentage_map_class = TClass::GetClass(
"art::ParentageMap");
214 if (parentage_map_class ==
nullptr)
216 throw art::Exception(art::errors::DictionaryNotFound) <<
217 "TransferOutput static send_init_message(): "
218 "Could not get class for ParentageMap";
223 TBufferFile msg(TBuffer::kWrite);
228 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): "
229 "Streaming message type code ..." << TLOG_ENDL;
231 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): "
232 "Finished streaming message type code." << TLOG_ENDL;
237 unsigned long ps_cnt = fhicl::ParameterSetRegistry::size();
238 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): parameter set count: " << std::to_string(ps_cnt) << TLOG_ENDL;
239 msg.WriteULong(ps_cnt);
240 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): Streaming parameter sets ..." << TLOG_ENDL;
242 #
if ART_HEX_VERSION >= 0x20703
243 auto I = std::begin(fhicl::ParameterSetRegistry::get()),
244 E = std::end(fhicl::ParameterSetRegistry::get());
246 auto I = fhicl::ParameterSetRegistry::begin(),
247 E = fhicl::ParameterSetRegistry::end();
251 std::string pset_str = I->second.to_string();
253 msg.WriteStdString(pset_str);
255 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): Finished streaming parameter sets." << TLOG_ENDL;
260 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): Streaming MasterProductRegistry ..." << TLOG_ENDL;;
261 art::ProductList productList(art::ProductMetaData::instance().productList());
262 msg.WriteObjectAny(&productList, product_list_class);
263 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): Finished streaming MasterProductRegistry." << TLOG_ENDL;
265 #if ART_HEX_VERSION < 0x20900
269 if (art::debugit() >= 2)
274 # if ART_HEX_VERSION >= 0x20703
275 art::BranchIDLists
const * bilr =
276 &art::BranchIDListRegistry::instance().data();
278 art::BranchIDLists* bilr =
279 &art::BranchIDListRegistry::instance()->data();
281 TLOG_TRACE(
"TransferOutput") <<
"TransferOutput static send_init_message(): " <<
"Content of BranchIDLists" << TLOG_ENDL;
282 int max_bli = bilr->size();
283 TLOG_TRACE(
"TransferOutput") <<
"TransferOutput static send_init_message(): " <<
284 "max_bli: " << max_bli << TLOG_ENDL;
285 for (
int i = 0; i < max_bli; ++i)
287 int max_prdidx = (*bilr)[i].size();
288 TLOG_TRACE(
"TransferOutput") <<
"TransferOutput static send_init_message(): " <<
289 "max_prdidx: " << max_prdidx << TLOG_ENDL;
290 for (
int j = 0; j < max_prdidx; ++j)
292 TLOG_TRACE(
"TransferOutput") <<
"TransferOutput static send_init_message(): " <<
295 <<
" bid: 0x" << std::hex
296 <<
static_cast<unsigned long>((*bilr)[i][j])
297 << std::dec << TLOG_ENDL;
303 # if ART_HEX_VERSION >= 0x20703
304 art::ProcessHistoryMap phr;
305 for (
auto const& pr : art::ProcessHistoryRegistry::get())
313 if (art::debugit() >= 1)
315 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): "
316 "Dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
319 # if ART_HEX_VERSION < 0x20703
320 art::ProcessHistoryMap
const& phr = art::ProcessHistoryRegistry::get();
322 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): " <<
323 "phr: size: " + std::to_string(phr.size()) << TLOG_ENDL;
324 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
326 std::ostringstream OS;
328 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): " <<
329 "phr: id: '" + OS.str() +
"'" << TLOG_ENDL;
336 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): " <<
337 "Streaming ProcessHistoryRegistry ..." << TLOG_ENDL;
340 # if ART_HEX_VERSION >= 0x20703
341 const art::ProcessHistoryMap& phm = phr;
343 const art::ProcessHistoryMap& phm = art::ProcessHistoryRegistry::get();
345 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): " <<
346 "phm: size: " << std::to_string(phm.size()) << TLOG_ENDL;
347 msg.WriteObjectAny(&phm, process_history_map_class);
348 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): " <<
349 "Finished streaming ProcessHistoryRegistry." << TLOG_ENDL;
355 TLOG_DEBUG(
"TransferOutput") <<
"TransferOutput static send_init_message(): " <<
356 "Streaming ParentageRegistry ... sz=" << std::to_string(msg.Length()) << TLOG_ENDL;
358 # if ART_HEX_VERSION >= 0x20703
359 art::ParentageMap parentageMap{};
360 for (
auto const& pr : art::ParentageRegistry::get())
362 parentageMap.emplace(pr.first, pr.second);
365 const art::ParentageMap& parentageMap = art::ParentageRegistry::get();
368 TLOG_TRACE(
"TransferOutput") <<
"Before WriteObjectAny ParentageMap" << TLOG_ENDL;
372 msg.WriteObjectAny(&parentageMap, parentage_map_class);
373 TLOG_TRACE(
"RootMPIOuptut") <<
"After WriteObjectAny ParentageMap" << TLOG_ENDL;
375 TLOG_DEBUG(
"TransferOutput") <<
"TransferOutput: TransferOutput static send_init_message(): " <<
376 "Finished streaming ParentageRegistry." <<
" sts=" << sts <<
", sz=" << std::to_string(msg.Length()) << TLOG_ENDL;
383 TLOG_DEBUG(
"TransferOutput") <<
"TransferOutput: TransferOutput static send_init_message(): " <<
"Sending the init message." << TLOG_ENDL;
384 sendMessage_(artdaq::Fragment::InvalidSequenceID - 1, artdaq::Fragment::InitFragmentType, msg);
385 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput static send_init_message(): "
386 "Init message(s) sent." << TLOG_ENDL;
388 TLOG_TRACE(
"TransferOutput") <<
" End: TransferOutput static send_init_message()" << TLOG_ENDL;
391 #//pragma GCC pop_options
394 art::TransferOutput::
395 writeDataProducts(TBufferFile& msg,
const Principal& principal,
396 std::vector<BranchKey*>& bkv)
398 TLOG_TRACE(
"TransferOutput") <<
" Begin: TransferOutput::writeDataProducts(...)" << TLOG_ENDL;
403 static TClass* branch_key_class = TClass::GetClass(
"art::BranchKey");
404 if (branch_key_class ==
nullptr)
406 throw art::Exception(art::errors::DictionaryNotFound) <<
407 "TransferOutput::writeDataProducts(...): "
408 "Could not get TClass for art::BranchKey!";
410 static TClass* prdprov_class = TClass::GetClass(
"art::ProductProvenance");
411 if (prdprov_class ==
nullptr)
413 throw art::Exception(art::errors::DictionaryNotFound) <<
414 "TransferOutput::writeDataProducts(...): "
415 "Could not get TClass for art::ProductProvenance!";
420 unsigned long prd_cnt = 0;
422 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
424 #if ART_HEX_VERSION > 0x20800
425 auto const& productDescription = I->second->productDescription();
426 auto const& refs = keptProducts()[productDescription.branchType()];
428 for (
auto const& ref : refs)
430 if (*ref == productDescription) {
435 if (I->second->productUnavailable() || !found)
440 if (I->second->productUnavailable() || !selected(I->second->productDescription()))
452 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeDataProducts(...): "
453 "Streaming product count: " << std::to_string(prd_cnt) << TLOG_ENDL;
454 msg.WriteULong(prd_cnt);
455 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeDataProducts(...): "
456 "Finished streaming product count." << TLOG_ENDL;
468 bkv.reserve(prd_cnt);
470 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
472 #if ART_HEX_VERSION > 0x20800
473 auto const& productDescription = I->second->productDescription();
474 auto const& refs = keptProducts()[productDescription.branchType()];
476 for (
auto const& ref : refs)
478 if (*ref == productDescription) {
483 if (I->second->productUnavailable() || !found)
488 if (I->second->productUnavailable() || !selected(I->second->productDescription()))
494 const BranchDescription& bd(I->second->productDescription());
495 bkv.push_back(
new BranchKey(bd));
496 if (art::debugit() >= 2)
498 TLOG_TRACE(
"TransferOutput") <<
"TransferOutput::writeDataProducts(...): "
499 "Dumping branch key of class: '"
500 << bkv.back()->friendlyClassName_
502 << bkv.back()->moduleLabel_
504 << bkv.back()->productInstanceName_
506 << bkv.back()->processName_
510 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeDataProducts(...): "
511 "Streaming branch key of class: '"
512 + bd.producedClassName()
516 + bd.productInstanceName()
520 msg.WriteObjectAny(bkv.back(), branch_key_class);
523 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeDataProducts(...): "
524 "Streaming product of class: '"
525 + bd.producedClassName()
529 + bd.productInstanceName()
533 #if ART_HEX_VERSION > 0x20800
534 OutputHandle oh = principal.getForOutput(bd.productID(),
true);
536 OutputHandle oh = principal.getForOutput(bd.branchID(),
true);
538 const EDProduct* prd = oh.wrapper();
539 msg.WriteObjectAny(prd, TClass::GetClass(bd.wrappedName().c_str()));
542 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeDataProducts(...): "
543 "Streaming product provenance of class: '"
544 + bd.producedClassName()
548 + bd.productInstanceName()
552 const ProductProvenance* prdprov =
553 I->second->productProvenancePtr().get();
554 msg.WriteObjectAny(prdprov, prdprov_class);
557 TLOG_TRACE(
"TransferOutput") <<
" End: TransferOutput::writeDataProducts(...)" << TLOG_ENDL;
561 art::TransferOutput::
562 write(EventPrincipal& ep)
567 TLOG_TRACE(
"TransferOutput") <<
" Begin: TransferOutput::"
568 "write(const EventPrincipal& ep)" << TLOG_ENDL;
577 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
578 if (run_aux_class ==
nullptr)
580 throw art::Exception(art::errors::DictionaryNotFound) <<
581 "TransferOutput::write(const EventPrincipal& ep): "
582 "Could not get TClass for art::RunAuxiliary!";
584 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
585 if (subrun_aux_class ==
nullptr)
587 throw art::Exception(art::errors::DictionaryNotFound) <<
588 "TransferOutput::write(const EventPrincipal& ep): "
589 "Could not get TClass for art::SubRunAuxiliary!";
591 static TClass* event_aux_class = TClass::GetClass(
"art::EventAuxiliary");
592 if (event_aux_class ==
nullptr)
594 throw art::Exception(art::errors::DictionaryNotFound) <<
595 "TransferOutput::write(const EventPrincipal& ep): "
596 "Could not get TClass for art::EventAuxiliary!";
598 static TClass* history_class = TClass::GetClass(
"art::History");
599 if (history_class ==
nullptr)
601 throw art::Exception(art::errors::DictionaryNotFound) <<
602 "TransferOutput::write(const EventPrincipal& ep): "
603 "Could not get TClass for art::History!";
608 TBufferFile msg(TBuffer::kWrite);
614 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
615 "Streaming message type code ..." << TLOG_ENDL;
617 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
618 "Finished streaming message type code." << TLOG_ENDL;
624 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
625 "Streaming RunAuxiliary ..." << TLOG_ENDL;
626 msg.WriteObjectAny(&ep.subRunPrincipal().runPrincipal().aux(),
628 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
629 "Finished streaming RunAuxiliary." << TLOG_ENDL;
635 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
636 "Streaming SubRunAuxiliary ..." << TLOG_ENDL;
637 msg.WriteObjectAny(&ep.subRunPrincipal().aux(),
639 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
640 "Finished streaming SubRunAuxiliary." << TLOG_ENDL;
646 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
647 "Streaming EventAuxiliary ..." << TLOG_ENDL;
648 msg.WriteObjectAny(&ep.aux(), event_aux_class);
649 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
650 "Finished streaming EventAuxiliary." << TLOG_ENDL;
656 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
657 "Streaming History ..." << TLOG_ENDL;
658 msg.WriteObjectAny(&ep.history(), history_class);
659 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
660 "Finished streaming History." << TLOG_ENDL;
665 std::vector<BranchKey*> bkv;
666 writeDataProducts(msg, ep, bkv);
671 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
672 "Sending a message ..." << TLOG_ENDL;
673 sendMessage_(ep.id().event(), artdaq::Fragment::DataFragmentType, msg);
674 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::write(const EventPrincipal& ep): "
675 "Message sent." << TLOG_ENDL;
680 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
685 TLOG_TRACE(
"TransferOutput") <<
" End: TransferOutput::write(const EventPrincipal& ep)" << TLOG_ENDL;
689 art::TransferOutput::
690 writeRun(RunPrincipal& rp)
695 TLOG_TRACE(
"TransferOutput") <<
" Begin: TransferOutput::writeRun(const RunPrincipal& rp)" << TLOG_ENDL;
707 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
708 assert(run_aux_class !=
nullptr &&
"writeRun: Could not get TClass for "
709 "art::RunAuxiliary!");
713 TBufferFile msg(TBuffer::kWrite);
719 TLOG_TRACE(
"TransferOutput") <<
" writeRun: streaming message type code ...");
721 TLOG_TRACE(
"TransferOutput") <<
" writeRun: finished streaming message type code.");
727 TLOG_TRACE(
"TransferOutput") <<
" writeRun: streaming RunAuxiliary ...");
728 if (art::debugit() >= 1)
730 TLOG_TRACE(
"TransferOutput") <<
" writeRun: dumping ProcessHistoryRegistry ...");
733 art::ProcessHistoryMap
const& phr =
734 art::ProcessHistoryRegistry::get();
735 TLOG_TRACE(
"TransferOutput") <<
" writeRun: phr: size: " << phr.size() <<
'\n';
736 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
738 std::ostringstream OS;
740 TLOG_TRACE(
"TransferOutput") <<
" writeRun: phr: id: '" << OS.str() <<
"'");
742 TLOG_TRACE(
"TransferOutput") <<
" writeRun: phr: data.size(): "
743 << I->second.data().size() <<
'\n';
744 if (I->second.data().size())
746 I->second.data().back().id().print(OS);
747 TLOG_TRACE(
"TransferOutput") <<
" writeRun: phr: data.back().id(): '"
751 if (!rp.aux().processHistoryID().isValid())
753 TLOG_TRACE(
"TransferOutput") <<
" writeRun: ProcessHistoryID: 'INVALID'");
757 std::ostringstream OS;
758 rp.aux().processHistoryID().print(OS);
759 TLOG_TRACE(
"TransferOutput") <<
" writeRun: ProcessHistoryID: '"
762 const ProcessHistory& processHistory =
763 ProcessHistoryRegistry::get(rp.aux().processHistoryID());
764 if (processHistory.data().size())
767 processHistory.data().back().id().print(OS);
768 TLOG_TRACE(
"TransferOutput") <<
" writeRun: ProcessConfigurationID: '"
771 TLOG_TRACE(
"TransferOutput") <<
" writeRun: ProcessConfiguration: '"
772 << processHistory.data().back() <<
'\n';
776 msg.WriteObjectAny(&rp.aux(), run_aux_class);
777 TLOG_TRACE(
"TransferOutput") <<
" writeRun: streamed RunAuxiliary.");
782 std::vector<BranchKey*> bkv;
783 writeDataProducts(msg, rp, bkv);
788 TLOG_TRACE(
"TransferOutput") <<
" writeRun: sending a message ...");
789 sendMessage_(0, artdaq::Fragment::EndOfRunFragmentType, msg);
790 TLOG_TRACE(
"TransferOutput") <<
" writeRun: message sent.");
795 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
801 TLOG_TRACE(
"TransferOutput") <<
" End: TransferOutput::writeRun(const RunPrincipal& rp)" << TLOG_ENDL;
805 art::TransferOutput::writeSubRun(SubRunPrincipal& srp)
810 TLOG_TRACE(
"TransferOutput") <<
" Begin: TransferOutput::"
811 "writeSubRun(const SubRunPrincipal& srp)" << TLOG_ENDL;
821 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
822 if (subrun_aux_class ==
nullptr)
824 throw art::Exception(art::errors::DictionaryNotFound) <<
825 "TransferOutput::writeSubRun: "
826 "Could not get TClass for art::SubRunAuxiliary!";
831 TBufferFile msg(TBuffer::kWrite);
837 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
838 "streaming message type code ..." << TLOG_ENDL;
840 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
841 "finished streaming message type code." << TLOG_ENDL;
847 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
848 "streaming SubRunAuxiliary ..." << TLOG_ENDL;
849 if (art::debugit() >= 1)
851 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
852 "dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
855 # if ART_HEX_VERSION >= 0x20703
856 for (
auto I = std::begin(art::ProcessHistoryRegistry::get())
857 , E = std::end(art::ProcessHistoryRegistry::get()); I != E; ++I)
859 art::ProcessHistoryMap
const& phr =
860 art::ProcessHistoryRegistry::get();
861 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
862 "phr: size: " << std::to_string(phr.size()) << TLOG_ENDL;
863 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
866 std::ostringstream OS;
868 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
869 "phr: id: '" + OS.str() +
"'" << TLOG_ENDL;
871 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
872 "phr: data.size(): " << std::to_string(I->second.data().size()) << TLOG_ENDL;
873 if (I->second.data().size())
875 I->second.data().back().id().print(OS);
876 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
877 "phr: data.back().id(): '"
878 + OS.str() +
"'" << TLOG_ENDL;
881 if (!srp.aux().processHistoryID().isValid())
883 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
884 "ProcessHistoryID: 'INVALID'" << TLOG_ENDL;;
888 std::ostringstream OS;
889 srp.aux().processHistoryID().print(OS);
890 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: ProcessHistoryID: '"
891 + OS.str() +
"'" << TLOG_ENDL;
893 # if ART_HEX_VERSION >= 0x20703
894 ProcessHistory processHistory;
895 ProcessHistoryRegistry::get(srp.aux().processHistoryID(), processHistory);
897 const ProcessHistory& processHistory =
898 ProcessHistoryRegistry::get(srp.aux().processHistoryID());
900 if (processHistory.data().size())
903 processHistory.data().back().id().print(OS);
904 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
905 "ProcessConfigurationID: '"
906 + OS.str() +
"'" << TLOG_ENDL;
908 OS << processHistory.data().back();
909 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
910 "ProcessConfiguration: '"
911 + OS.str() << TLOG_ENDL;
915 msg.WriteObjectAny(&srp.aux(), subrun_aux_class);
916 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: streamed SubRunAuxiliary." << TLOG_ENDL;
921 std::vector<BranchKey*> bkv;
922 writeDataProducts(msg, srp, bkv);
927 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
928 "Sending the EndOfSubrun message." << TLOG_ENDL;
929 sendMessage_(0, artdaq::Fragment::EndOfSubrunFragmentType, msg);
930 TLOG_TRACE(
"TransferOutput") <<
" TransferOutput::writeSubRun: "
931 "EndOfSubrun message(s) sent." << TLOG_ENDL;
937 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
942 TLOG_TRACE(
"TransferOutput") <<
" End: TransferOutput::writeSubRun(const SubRunPrincipal& srp)" << TLOG_ENDL;
947 art::TransferOutput::sendMessage_(uint64_t sequenceId, uint8_t messageType, TBufferFile& msg)
949 TLOG_DEBUG(
"TransferOutput") <<
"Sending message with sequenceID=" << std::to_string(sequenceId) <<
", type=" << std::to_string(messageType) <<
", length=" << std::to_string(msg.Length()) << TLOG_ENDL;
951 header.
data_length =
static_cast<uint64_t
>(msg.Length());
953 fragment(std::ceil(msg.Length() /
954 static_cast<double>(
sizeof(artdaq::RawDataType))),
955 sequenceId, 0, messageType, header);
957 memcpy(&*fragment.dataBegin(), msg.Buffer(), msg.Length());
961 sts = transfer_->copyFragment(fragment);
965 if (messageType == artdaq::Fragment::InitFragmentType)
967 std::fstream ostream(
"sendInitMessage_TransferOutput.bin", std::ios::out | std::ios::binary);
968 ostream.write(msg.Buffer(), msg.Length());
~TransferOutput()
TransferOutput Destructor.
std::unique_ptr< artdaq::TransferInterface > MakeTransferPlugin(const fhicl::ParameterSet &pset, std::string plugin_label, TransferInterface::Role role)
Load a TransferInterface plugin.
TransferOutput(fhicl::ParameterSet const &ps)
TransferOutput Constructor.
An art::OutputModule which sends events using DataSenderManager. This module is designed for transpor...
This TransferInterface is a Sender.
Some error occurred, but no exception was thrown.
The send operation completed successfully.