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 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
14 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
15 #include "art/Persistency/Provenance/ProductMetaData.h"
17 #include "canvas/Persistency/Provenance/BranchDescription.h"
18 #include "canvas/Persistency/Provenance/BranchIDList.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 #include "cetlib/column_width.h"
32 #include "cetlib/lpad.h"
33 #include "cetlib/rpad.h"
35 #include "fhiclcpp/ParameterSet.h"
36 #include "fhiclcpp/ParameterSetID.h"
37 #include "fhiclcpp/ParameterSetRegistry.h"
39 #define TRACE_NAME "RootNetOutput"
41 #define TLVL_OPENFILE 5
42 #define TLVL_CLOSEFILE 6
43 #define TLVL_RESPONDTOCLOSEINPUTFILE 7
44 #define TLVL_RESPONDTOCLOSEOUTPUTFILE 8
46 #define TLVL_SENDINIT 10
47 #define TLVL_SENDINIT_VERBOSE1 32
48 #define TLVL_SENDINIT_VERBOSE2 33
49 #define TLVL_WRITEDATAPRODUCTS 11
50 #define TLVL_WRITEDATAPRODUCTS_VERBOSE 34
52 #define TLVL_WRITERUN 13
53 #define TLVL_WRITESUBRUN 14
54 #define TLVL_WRITESUBRUN_VERBOSE 35
57 #include "artdaq/DAQdata/Globals.hh"
58 #include "artdaq/ArtModules/NetMonTransportService.h"
59 #include "artdaq-core/Data/detail/ParentageMap.hh"
60 #include "artdaq/DAQdata/NetMonHeader.hh"
104 virtual void openFile(FileBlock
const&);
106 virtual void closeFile();
108 virtual void respondToCloseInputFile(FileBlock
const&);
110 virtual void respondToCloseOutputFiles(FileBlock
const&);
112 virtual void endJob();
114 virtual void write(EventPrincipal CONST_WRITE&);
116 virtual void writeRun(RunPrincipal CONST_WRITE&);
118 virtual void writeSubRun(SubRunPrincipal CONST_WRITE&);
120 void writeDataProducts(TBufferFile&,
const Principal&,
121 std::vector<BranchKey*>&);
130 , initMsgSent_(false)
132 TLOG_DEBUG(
"RootNetOutput") <<
"Begin: RootNetOutput::RootNetOutput(ParameterSet const& ps)" << TLOG_ENDL;
133 ServiceHandle<NetMonTransportService> transport;
134 transport->connect();
135 TLOG_DEBUG(
"RootNetOutput") <<
"End: RootNetOutput::RootNetOutput(ParameterSet const& ps)" << TLOG_ENDL;
141 TLOG_DEBUG(
"RootNetOutput") <<
"Begin: RootNetOutput::~RootNetOutput()" << TLOG_ENDL;
142 ServiceHandle<NetMonTransportService> transport;
143 transport->disconnect();
144 TLOG_DEBUG(
"RootNetOutput") <<
"End: RootNetOutput::~RootNetOutput()" << TLOG_ENDL;
149 openFile(FileBlock
const&)
151 TLOG_ARB(TLVL_OPENFILE,
"RootNetOutput") <<
"Begin/End: RootNetOutput::openFile(const FileBlock&)" << TLOG_ENDL;
158 TLOG_ARB(TLVL_CLOSEFILE,
"RootNetOutput") <<
"Begin/End: RootNetOutput::closeFile()" << TLOG_ENDL;
163 respondToCloseInputFile(FileBlock
const&)
165 TLOG_ARB(TLVL_RESPONDTOCLOSEINPUTFILE,
"RootNetOutput") <<
"Begin/End: RootNetOutput::"
166 "respondToCloseOutputFiles(FileBlock const&)" << TLOG_ENDL;
171 respondToCloseOutputFiles(FileBlock
const&)
173 TLOG_ARB(TLVL_RESPONDTOCLOSEOUTPUTFILE,
"RootNetOutput") <<
"Begin/End: RootNetOutput::"
174 "respondToCloseOutputFiles(FileBlock const&)" << TLOG_ENDL;
179 send_shutdown_message()
191 TLOG_ARB(TLVL_ENDJOB,
"RootNetOutput") <<
"Begin: RootNetOutput::endJob()" << TLOG_ENDL;
192 send_shutdown_message();
193 TLOG_ARB(TLVL_ENDJOB,
"RootNetOutput") <<
"End: RootNetOutput::endJob()" << TLOG_ENDL;
202 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"Begin: RootNetOutput static send_init_message()" << TLOG_ENDL;
212 static TClass* product_list_class = TClass::GetClass(
213 "std::map<art::BranchKey,art::BranchDescription>");
214 if (product_list_class ==
nullptr)
216 throw art::Exception(art::errors::DictionaryNotFound) <<
217 "RootNetOutput static send_init_message(): "
218 "Could not get TClass for "
219 "map<art::BranchKey,art::BranchDescription>!";
225 static TClass* process_history_map_class = TClass::GetClass(
226 "std::map<const art::Hash<2>,art::ProcessHistory>");
227 if (process_history_map_class ==
nullptr)
229 throw art::Exception(art::errors::DictionaryNotFound) <<
230 "RootNetOutput static send_init_message(): "
231 "Could not get class for "
232 "std::map<const art::Hash<2>,art::ProcessHistory>!";
237 static TClass* parentage_map_class = TClass::GetClass(
"art::ParentageMap");
238 if (parentage_map_class ==
nullptr)
240 throw art::Exception(art::errors::DictionaryNotFound) <<
241 "RootNetOutput static send_init_message(): "
242 "Could not get class for ParentageMap.";
247 TBufferFile msg(TBuffer::kWrite);
252 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Streaming message type code ..." << TLOG_ENDL;
254 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Finished streaming message type code." << TLOG_ENDL;
259 unsigned long ps_cnt = fhicl::ParameterSetRegistry::size();
260 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): parameter set count: " + std::to_string(ps_cnt) << TLOG_ENDL;
261 msg.WriteULong(ps_cnt);
262 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Streaming parameter sets ..." << TLOG_ENDL;
264 #
if ART_HEX_VERSION >= 0x20703
265 auto I = std::begin(fhicl::ParameterSetRegistry::get()),
266 E = std::end(fhicl::ParameterSetRegistry::get());
268 auto I = fhicl::ParameterSetRegistry::begin(),
269 E = fhicl::ParameterSetRegistry::end();
273 std::string pset_str = I->second.to_string();
275 msg.WriteStdString(pset_str);
277 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Finished streaming parameter sets." << TLOG_ENDL;
282 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Streaming MasterProductRegistry ..." << TLOG_ENDL;
283 art::ProductList productList(
284 art::ProductMetaData::instance().productList());
285 msg.WriteObjectAny(&productList, product_list_class);
286 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Finished streaming MasterProductRegistry." << TLOG_ENDL;
291 # if ART_HEX_VERSION >= 0x20703
292 art::BranchIDLists
const * bilr =
293 &art::BranchIDListRegistry::instance().data();
295 art::BranchIDLists* bilr =
296 &art::BranchIDListRegistry::instance()->data();
298 TLOG_ARB(TLVL_SENDINIT_VERBOSE1,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Content of BranchIDLists" << TLOG_ENDL;
299 int max_bli = bilr->size();
300 TLOG_ARB(TLVL_SENDINIT_VERBOSE1,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): max_bli: " << max_bli << TLOG_ENDL;
301 for (
int i = 0; i < max_bli; ++i)
303 int max_prdidx = (*bilr)[i].size();
304 TLOG_ARB(TLVL_SENDINIT_VERBOSE1,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): max_prdidx: " << max_prdidx << TLOG_ENDL;
305 for (
int j = 0; j < max_prdidx; ++j)
307 TLOG_ARB(TLVL_SENDINIT_VERBOSE1,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): bli: " << i <<
" prdidx: " << j <<
" bid: 0x" << std::hex << static_cast<unsigned long>((*bilr)[i][j]) << std::dec << TLOG_ENDL;
311 # if ART_HEX_VERSION >= 0x20703
312 art::ProcessHistoryMap phr;
313 for (
auto const& pr : art::ProcessHistoryRegistry::get()) {
320 TLOG_ARB(TLVL_SENDINIT_VERBOSE2,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
323 # if ART_HEX_VERSION < 0x20703
324 art::ProcessHistoryMap
const& phr = art::ProcessHistoryRegistry::get();
326 TLOG_ARB(TLVL_SENDINIT_VERBOSE2,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): phr: size: " << std::to_string(phr.size()) << TLOG_ENDL;
327 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
329 std::ostringstream OS;
331 TLOG_ARB(TLVL_SENDINIT_VERBOSE2,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): phr: id: '" << OS.str() <<
"'" << TLOG_ENDL;
336 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Streaming ProcessHistoryRegistry ..." << TLOG_ENDL;
339 # if ART_HEX_VERSION >= 0x20703
340 const art::ProcessHistoryMap& phm = phr;
342 const art::ProcessHistoryMap& phm = art::ProcessHistoryRegistry::get();
344 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): phm: size: " << std::to_string(phm.size()) << TLOG_ENDL;
345 msg.WriteObjectAny(&phm, process_history_map_class);
346 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Finished streaming ProcessHistoryRegistry." << TLOG_ENDL;
351 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"static send_init_message(): Streaming ParentageRegistry ..." << TLOG_ENDL;
352 # if ART_HEX_VERSION >= 0x20703
353 art::ParentageMap parentageMap{};
354 for (
auto const& pr : art::ParentageRegistry::get()) {
355 parentageMap.emplace(pr.first, pr.second);
358 const art::ParentageMap& parentageMap = art::ParentageRegistry::get();
361 msg.WriteObjectAny(&parentageMap, parentage_map_class);
363 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"static send_init_message(): Finished streaming ParentageRegistry." << TLOG_ENDL;
369 art::ServiceHandle<NetMonTransportService> transport;
370 if (!transport.get())
372 TLOG_ERROR(
"RootNetOutput") <<
"Could not get handle to NetMonTransportService!" << TLOG_ENDL;
375 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Sending the init message to " << std::to_string(transport->dataReceiverCount()) <<
" data receivers ..." << TLOG_ENDL;
376 for (
size_t idx = 0; idx < transport->dataReceiverCount(); ++idx)
378 transport->sendMessage(idx, artdaq::Fragment::InitFragmentType, msg);
380 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"RootNetOutput static send_init_message(): Init message(s) sent." << TLOG_ENDL;
382 TLOG_ARB(TLVL_SENDINIT,
"RootNetOutput") <<
"End: RootNetOutput static send_init_message()" << TLOG_ENDL;
389 writeDataProducts(TBufferFile& msg,
const Principal& principal,
390 std::vector<BranchKey*>& bkv)
392 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"Begin: RootNetOutput::writeDataProducts(...)" << TLOG_ENDL;
397 static TClass* branch_key_class = TClass::GetClass(
"art::BranchKey");
398 if (branch_key_class ==
nullptr)
400 throw art::Exception(art::errors::DictionaryNotFound) <<
401 "RootNetOutput::writeDataProducts(...): "
402 "Could not get TClass for art::BranchKey!";
404 static TClass* prdprov_class = TClass::GetClass(
"art::ProductProvenance");
405 if (prdprov_class ==
nullptr)
407 throw art::Exception(art::errors::DictionaryNotFound) <<
408 "RootNetOutput::writeDataProducts(...): "
409 "Could not get TClass for art::ProductProvenance!";
414 unsigned long prd_cnt = 0;
416 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
418 if (I->second->productUnavailable() || !selected(I->second->productDescription()))
427 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"RootNetOutput::writeDataProducts(...): Streaming product count: " + std::to_string(prd_cnt) << TLOG_ENDL;
428 msg.WriteULong(prd_cnt);
429 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"RootNetOutput::writeDataProducts(...): Finished streaming product count." << TLOG_ENDL;
441 bkv.reserve(prd_cnt);
443 for (
auto I = principal.begin(), E = principal.end(); I != E; ++I)
445 if (I->second->productUnavailable() || !selected(I->second->productDescription()))
449 const BranchDescription& bd(I->second->productDescription());
450 bkv.push_back(
new BranchKey(bd));
451 TLOG_ARB(TLVL_WRITEDATAPRODUCTS_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeDataProducts(...): Dumping branch key of class: '"
452 << bkv.back()->friendlyClassName_
454 << bkv.back()->moduleLabel_
456 << bkv.back()->productInstanceName_
458 << bkv.back()->processName_
460 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"RootNetOutput::writeDataProducts(...): "
461 "Streaming branch key of class: '"
462 << bd.producedClassName()
466 << bd.productInstanceName()
470 msg.WriteObjectAny(bkv.back(), branch_key_class);
471 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"RootNetOutput::writeDataProducts(...): "
472 "Streaming product of class: '"
473 << bd.producedClassName()
477 << bd.productInstanceName()
481 OutputHandle oh = principal.getForOutput(bd.branchID(),
true);
482 const EDProduct* prd = oh.wrapper();
483 msg.WriteObjectAny(prd, TClass::GetClass(bd.wrappedName().c_str()));
484 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"RootNetOutput::writeDataProducts(...): "
485 "Streaming product provenance of class: '"
486 << bd.producedClassName()
490 << bd.productInstanceName()
494 const ProductProvenance* prdprov =
495 I->second->productProvenancePtr().get();
496 msg.WriteObjectAny(prdprov, prdprov_class);
498 TLOG_ARB(TLVL_WRITEDATAPRODUCTS,
"RootNetOutput") <<
"End: RootNetOutput::writeDataProducts(...)" << TLOG_ENDL;
503 write(CONST_WRITE EventPrincipal& ep)
508 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"Begin: RootNetOutput::write(const EventPrincipal& ep)" << TLOG_ENDL;
517 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
518 if (run_aux_class ==
nullptr)
520 throw art::Exception(art::errors::DictionaryNotFound) <<
521 "RootNetOutput::write(const EventPrincipal& ep): "
522 "Could not get TClass for art::RunAuxiliary!";
524 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
525 if (subrun_aux_class ==
nullptr)
527 throw art::Exception(art::errors::DictionaryNotFound) <<
528 "RootNetOutput::write(const EventPrincipal& ep): "
529 "Could not get TClass for art::SubRunAuxiliary!";
531 static TClass* event_aux_class = TClass::GetClass(
"art::EventAuxiliary");
532 if (event_aux_class ==
nullptr)
534 throw art::Exception(art::errors::DictionaryNotFound) <<
535 "RootNetOutput::write(const EventPrincipal& ep): "
536 "Could not get TClass for art::EventAuxiliary!";
538 static TClass* history_class = TClass::GetClass(
"art::History");
539 if (history_class ==
nullptr)
541 throw art::Exception(art::errors::DictionaryNotFound) <<
542 "RootNetOutput::write(const EventPrincipal& ep): "
543 "Could not get TClass for art::History!";
548 TBufferFile msg(TBuffer::kWrite);
553 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Streaming message type code ..." << TLOG_ENDL;
555 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Finished streaming message type code." << TLOG_ENDL;
560 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Streaming RunAuxiliary ..." << TLOG_ENDL;
561 msg.WriteObjectAny(&ep.subRunPrincipal().runPrincipal().aux(),
563 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Finished streaming RunAuxiliary." << TLOG_ENDL;
568 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Streaming SubRunAuxiliary ..." << TLOG_ENDL;
569 msg.WriteObjectAny(&ep.subRunPrincipal().aux(),
571 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Finished streaming SubRunAuxiliary." << TLOG_ENDL;
577 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Streaming EventAuxiliary ..." << TLOG_ENDL;
578 msg.WriteObjectAny(&ep.aux(), event_aux_class);
579 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Finished streaming EventAuxiliary." << TLOG_ENDL;
585 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Streaming History ..." << TLOG_ENDL;
586 msg.WriteObjectAny(&ep.history(), history_class);
587 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Finished streaming History." << TLOG_ENDL;
592 std::vector<BranchKey*> bkv;
593 writeDataProducts(msg, ep, bkv);
598 ServiceHandle<NetMonTransportService> transport;
599 if (!transport.get())
601 TLOG_ERROR(
"RootNetOutput") <<
"Could not get handle to NetMonTransportService!" << TLOG_ENDL;
604 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Sending a message ..." << TLOG_ENDL;
605 transport->sendMessage(ep.id().event(), artdaq::Fragment::DataFragmentType, msg);
606 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"RootNetOutput::write(const EventPrincipal& ep): Message sent." << TLOG_ENDL;
611 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
616 TLOG_ARB(TLVL_WRITE,
"RootNetOutput") <<
"End: RootNetOutput::write(const EventPrincipal& ep)" << TLOG_ENDL;
621 writeRun(CONST_WRITE RunPrincipal& rp)
626 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"Begin: RootNetOutput::writeRun(const RunPrincipal& rp)" << TLOG_ENDL;
638 static TClass* run_aux_class = TClass::GetClass(
"art::RunAuxiliary");
639 assert(run_aux_class !=
nullptr &&
"writeRun: Could not get TClass for art::RunAuxiliary!");
643 TBufferFile msg(TBuffer::kWrite);
649 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"writeRun: streaming message type code ..." << TLOG_ENDL;
651 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"writeRun: finished streaming message type code." << TLOG_ENDL;
657 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"writeRun: streaming RunAuxiliary ..." << TLOG_ENDL;
658 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
661 art::ProcessHistoryMap
const& phr =
662 art::ProcessHistoryRegistry::get();
663 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: phr: size: " << phr.size() << TLOG_ENDL;
664 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I) {
665 std::ostringstream OS;
667 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: phr: id: '" << OS.str() <<
"'" << TLOG_ENDL;
669 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: phr: data.size(): " << I->second.data().size() << TLOG_ENDL;
670 if (I->second.data().size()) {
671 I->second.data().back().id().print(OS);
672 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: phr: data.back().id(): '" << OS.str() <<
"'" << TLOG_ENDL;
675 if (!rp.aux().processHistoryID().isValid()) {
676 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: ProcessHistoryID: 'INVALID'" << TLOG_ENDL;
679 std::ostringstream OS;
680 rp.aux().processHistoryID().print(OS);
681 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: ProcessHistoryID: '" << OS.str() <<
"'" << TLOG_ENDL;
683 const ProcessHistory& processHistory =
684 ProcessHistoryRegistry::get(rp.aux().processHistoryID());
685 if (processHistory.data().size()) {
687 processHistory.data().back().id().print(OS);
688 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: ProcessConfigurationID: '" << OS.str() <<
"'" << TLOG_ENDL;
690 TLOG_ARB(TLVL_WRITERUN_VERBOSE,
"RootNetOutput") <<
"writeRun: ProcessConfiguration: '" << processHistory.data().back() << TLOG_ENDL;
693 msg.WriteObjectAny(&rp.aux(), run_aux_class);
694 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"writeRun: streamed RunAuxiliary." << TLOG_ENDL;
699 std::vector<BranchKey*> bkv;
700 writeDataProducts(msg, rp, bkv);
705 ServiceHandle<NetMonTransportService> transport;
706 if (!transport.get())
708 TLOG_ERROR(
"RootNetOutput") <<
"Could not get handle to NetMonTransportService!" << TLOG_ENDL;
711 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"writeRun: sending a message ..." << TLOG_ENDL;
712 transport->sendMessage(0, artdaq::Fragment::EndOfRunFragmentType, msg);
713 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"writeRun: message sent." << TLOG_ENDL;
718 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I) {
723 TLOG_ARB(TLVL_WRITERUN,
"RootNetOutput") <<
"End: RootNetOutput::writeRun(const RunPrincipal& rp)" << TLOG_ENDL;
727 art::RootNetOutput::writeSubRun(CONST_WRITE SubRunPrincipal& srp)
732 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"Begin: RootNetOutput::writeSubRun(const SubRunPrincipal& srp)" << TLOG_ENDL;
742 static TClass* subrun_aux_class = TClass::GetClass(
"art::SubRunAuxiliary");
743 if (subrun_aux_class ==
nullptr)
745 throw art::Exception(art::errors::DictionaryNotFound) <<
746 "RootNetOutput::writeSubRun: "
747 "Could not get TClass for art::SubRunAuxiliary!";
752 TBufferFile msg(TBuffer::kWrite);
758 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: streaming message type code ..." << TLOG_ENDL;
760 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: finished streaming message type code." << TLOG_ENDL;
766 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: streaming SubRunAuxiliary ..." << TLOG_ENDL;
768 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
771 # if ART_HEX_VERSION >= 0x20703
772 for (
auto I = std::begin(art::ProcessHistoryRegistry::get())
773 , E = std::end(art::ProcessHistoryRegistry::get()); I != E; ++I)
775 art::ProcessHistoryMap
const& phr =
776 art::ProcessHistoryRegistry::get();
777 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: phr: size: " << std::to_string(phr.size()) << TLOG_ENDL;
778 for (
auto I = phr.begin(), E = phr.end(); I != E; ++I)
781 std::ostringstream OS;
783 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: phr: id: '" << OS.str() <<
"'" << TLOG_ENDL;
785 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: phr: data.size(): " << std::to_string(I->second.data().size()) << TLOG_ENDL;
786 if (I->second.data().size())
788 I->second.data().back().id().print(OS);
789 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: phr: data.back().id(): '" << OS.str() <<
"'" << TLOG_ENDL;
792 if (!srp.aux().processHistoryID().isValid())
794 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: ProcessHistoryID: 'INVALID'" << TLOG_ENDL;
798 std::ostringstream OS;
799 srp.aux().processHistoryID().print(OS);
800 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: ProcessHistoryID: '" << OS.str() <<
"'" << TLOG_ENDL;
802 # if ART_HEX_VERSION >= 0x20703
803 ProcessHistory processHistory;
804 ProcessHistoryRegistry::get(srp.aux().processHistoryID(), processHistory);
806 const ProcessHistory& processHistory =
807 ProcessHistoryRegistry::get(srp.aux().processHistoryID());
809 if (processHistory.data().size())
812 processHistory.data().back().id().print(OS);
813 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: ProcessConfigurationID: '" << OS.str() <<
"'" << TLOG_ENDL;
815 OS << processHistory.data().back();
816 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: ProcessConfiguration: '" << OS.str() << TLOG_ENDL;
819 msg.WriteObjectAny(&srp.aux(), subrun_aux_class);
820 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: streamed SubRunAuxiliary." << TLOG_ENDL;
825 std::vector<BranchKey*> bkv;
826 writeDataProducts(msg, srp, bkv);
830 ServiceHandle<NetMonTransportService> transport;
831 if (!transport.get())
833 TLOG_ERROR(
"RootNetOutput") <<
"Could not get handle to NetMonTransportService!" << TLOG_ENDL;
836 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: Sending the EndOfSubrun message to " << std::to_string(transport->dataReceiverCount()) <<
" data receivers ..." << TLOG_ENDL;
837 for (
size_t idx = 0; idx < transport->dataReceiverCount(); ++idx)
839 transport->sendMessage(idx, artdaq::Fragment::EndOfSubrunFragmentType, msg);
841 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"RootNetOutput::writeSubRun: EndOfSubrun message(s) sent." << TLOG_ENDL;
845 transport->disconnect();
850 for (
auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
855 TLOG_ARB(TLVL_WRITESUBRUN,
"RootNetOutput") <<
"End: RootNetOutput::writeSubRun(const SubRunPrincipal& srp)" << TLOG_ENDL;
~RootNetOutput()
RootNetOutput Destructor.
An art::OutputModule which sends events using DataSenderManager. This module is designed for transpor...
RootNetOutput(fhicl::ParameterSet const &ps)
RootNetOutput Constructor.