00001 #include "art/Framework/Core/ModuleMacros.h"
00002 #include "art/Framework/Core/OutputModule.h"
00003 #include "art/Framework/Principal/EventPrincipal.h"
00004 #include "art/Framework/Principal/OutputHandle.h"
00005 #include "art/Framework/Principal/RunPrincipal.h"
00006 #include "art/Framework/Principal/SubRunPrincipal.h"
00007 #include "art/Framework/Services/Registry/ServiceHandle.h"
00008 #if ART_HEX_VERSION >= 0x20703
00009 # include <iterator>
00010 #else
00011 # include "art/Persistency/Provenance/BranchIDListHelper.h"
00012 #endif
00013 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
00014 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
00015 #include "art/Persistency/Provenance/ProductMetaData.h"
00016
00017 #include "canvas/Persistency/Provenance/BranchDescription.h"
00018 #include "canvas/Persistency/Provenance/BranchIDList.h"
00019 #include "canvas/Persistency/Provenance/BranchKey.h"
00020 #include "canvas/Persistency/Provenance/History.h"
00021 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
00022 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
00023 #include "canvas/Persistency/Provenance/ProcessConfigurationID.h"
00024 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
00025 #include "canvas/Persistency/Provenance/ProductList.h"
00026 #include "canvas/Persistency/Provenance/ProductProvenance.h"
00027 #include "canvas/Persistency/Provenance/RunAuxiliary.h"
00028 #include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
00029 #include "canvas/Utilities/DebugMacros.h"
00030 #include "canvas/Utilities/Exception.h"
00031 #include "cetlib/column_width.h"
00032 #include "cetlib/lpad.h"
00033 #include "cetlib/rpad.h"
00034 #include <algorithm>
00035 #include "fhiclcpp/ParameterSet.h"
00036 #include "fhiclcpp/ParameterSetID.h"
00037 #include "fhiclcpp/ParameterSetRegistry.h"
00038
00039 #define TRACE_NAME "RootNetOutput"
00040
00041 #define TLVL_OPENFILE 5
00042 #define TLVL_CLOSEFILE 6
00043 #define TLVL_RESPONDTOCLOSEINPUTFILE 7
00044 #define TLVL_RESPONDTOCLOSEOUTPUTFILE 8
00045 #define TLVL_ENDJOB 9
00046 #define TLVL_SENDINIT 10
00047 #define TLVL_SENDINIT_VERBOSE1 32
00048 #define TLVL_SENDINIT_VERBOSE2 33
00049 #define TLVL_WRITEDATAPRODUCTS 11
00050 #define TLVL_WRITEDATAPRODUCTS_VERBOSE 34
00051 #define TLVL_WRITE 12
00052 #define TLVL_WRITERUN 13
00053 #define TLVL_WRITESUBRUN 14
00054 #define TLVL_WRITESUBRUN_VERBOSE 35
00055
00056
00057 #include "artdaq/DAQdata/Globals.hh"
00058 #include "artdaq/ArtModules/NetMonTransportService.h"
00059 #include "artdaq-core/Data/detail/ParentageMap.hh"
00060 #include "artdaq/DAQdata/NetMonHeader.hh"
00061
00062 #include <iomanip>
00063 #include <iostream>
00064 #include <sstream>
00065 #include <string>
00066 #include <vector>
00067
00068 #include <unistd.h>
00069
00070 #include <TClass.h>
00071 #include <TMessage.h>
00072
00073 # define CONST_WRITE
00074
00075 namespace art
00076 {
00077 class RootNetOutput;
00078 }
00079
00080
00086 class art::RootNetOutput : public OutputModule
00087 {
00088 public:
00096 explicit RootNetOutput(fhicl::ParameterSet const& ps);
00097
00101 ~RootNetOutput();
00102
00103 private:
00104 virtual void openFile(FileBlock const&);
00105
00106 virtual void closeFile();
00107
00108 virtual void respondToCloseInputFile(FileBlock const&);
00109
00110 virtual void respondToCloseOutputFiles(FileBlock const&);
00111
00112 virtual void endJob();
00113
00114 virtual void write(EventPrincipal CONST_WRITE&);
00115
00116 virtual void writeRun(RunPrincipal CONST_WRITE&);
00117
00118 virtual void writeSubRun(SubRunPrincipal CONST_WRITE&);
00119
00120 void writeDataProducts(TBufferFile&, const Principal&,
00121 std::vector<BranchKey*>&);
00122
00123 private:
00124 bool initMsgSent_;
00125 };
00126
00127 art::RootNetOutput::
00128 RootNetOutput(fhicl::ParameterSet const& ps)
00129 : OutputModule(ps)
00130 , initMsgSent_(false)
00131 {
00132 TLOG_DEBUG("RootNetOutput") << "Begin: RootNetOutput::RootNetOutput(ParameterSet const& ps)" << TLOG_ENDL;
00133 ServiceHandle<NetMonTransportService> transport;
00134 transport->connect();
00135 TLOG_DEBUG("RootNetOutput") << "End: RootNetOutput::RootNetOutput(ParameterSet const& ps)" << TLOG_ENDL;
00136 }
00137
00138 art::RootNetOutput::
00139 ~RootNetOutput()
00140 {
00141 TLOG_DEBUG("RootNetOutput") << "Begin: RootNetOutput::~RootNetOutput()" << TLOG_ENDL;
00142 ServiceHandle<NetMonTransportService> transport;
00143 transport->disconnect();
00144 TLOG_DEBUG("RootNetOutput") << "End: RootNetOutput::~RootNetOutput()" << TLOG_ENDL;
00145 }
00146
00147 void
00148 art::RootNetOutput::
00149 openFile(FileBlock const&)
00150 {
00151 TLOG_ARB(TLVL_OPENFILE, "RootNetOutput") << "Begin/End: RootNetOutput::openFile(const FileBlock&)" << TLOG_ENDL;
00152 }
00153
00154 void
00155 art::RootNetOutput::
00156 closeFile()
00157 {
00158 TLOG_ARB(TLVL_CLOSEFILE, "RootNetOutput") << "Begin/End: RootNetOutput::closeFile()" << TLOG_ENDL;
00159 }
00160
00161 void
00162 art::RootNetOutput::
00163 respondToCloseInputFile(FileBlock const&)
00164 {
00165 TLOG_ARB(TLVL_RESPONDTOCLOSEINPUTFILE, "RootNetOutput") << "Begin/End: RootNetOutput::"
00166 "respondToCloseOutputFiles(FileBlock const&)" << TLOG_ENDL;
00167 }
00168
00169 void
00170 art::RootNetOutput::
00171 respondToCloseOutputFiles(FileBlock const&)
00172 {
00173 TLOG_ARB(TLVL_RESPONDTOCLOSEOUTPUTFILE, "RootNetOutput") << "Begin/End: RootNetOutput::"
00174 "respondToCloseOutputFiles(FileBlock const&)" << TLOG_ENDL;
00175 }
00176
00177 static
00178 void
00179 send_shutdown_message()
00180 {
00181
00182
00183
00184
00185 }
00186
00187 void
00188 art::RootNetOutput::
00189 endJob()
00190 {
00191 TLOG_ARB(TLVL_ENDJOB, "RootNetOutput") << "Begin: RootNetOutput::endJob()" << TLOG_ENDL;
00192 send_shutdown_message();
00193 TLOG_ARB(TLVL_ENDJOB, "RootNetOutput") << "End: RootNetOutput::endJob()" << TLOG_ENDL;
00194 }
00195
00196
00197
00198 static
00199 void
00200 send_init_message()
00201 {
00202 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "Begin: RootNetOutput static send_init_message()" << TLOG_ENDL;
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 static TClass* product_list_class = TClass::GetClass(
00213 "std::map<art::BranchKey,art::BranchDescription>");
00214 if (product_list_class == nullptr)
00215 {
00216 throw art::Exception(art::errors::DictionaryNotFound) <<
00217 "RootNetOutput static send_init_message(): "
00218 "Could not get TClass for "
00219 "map<art::BranchKey,art::BranchDescription>!";
00220 }
00221
00222
00223
00224
00225 static TClass* process_history_map_class = TClass::GetClass(
00226 "std::map<const art::Hash<2>,art::ProcessHistory>");
00227 if (process_history_map_class == nullptr)
00228 {
00229 throw art::Exception(art::errors::DictionaryNotFound) <<
00230 "RootNetOutput static send_init_message(): "
00231 "Could not get class for "
00232 "std::map<const art::Hash<2>,art::ProcessHistory>!";
00233 }
00234
00235
00236
00237 static TClass* parentage_map_class = TClass::GetClass("art::ParentageMap");
00238 if (parentage_map_class == nullptr)
00239 {
00240 throw art::Exception(art::errors::DictionaryNotFound) <<
00241 "RootNetOutput static send_init_message(): "
00242 "Could not get class for ParentageMap.";
00243 }
00244
00245
00246
00247 TBufferFile msg(TBuffer::kWrite);
00248 msg.SetWriteMode();
00249
00250
00251
00252 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Streaming message type code ..." << TLOG_ENDL;
00253 msg.WriteULong(1);
00254 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Finished streaming message type code." << TLOG_ENDL;
00255
00256
00257
00258
00259 unsigned long ps_cnt = fhicl::ParameterSetRegistry::size();
00260 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): parameter set count: " + std::to_string(ps_cnt) << TLOG_ENDL;
00261 msg.WriteULong(ps_cnt);
00262 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Streaming parameter sets ..." << TLOG_ENDL;
00263 for (
00264 # if ART_HEX_VERSION >= 0x20703
00265 auto I = std::begin(fhicl::ParameterSetRegistry::get()),
00266 E = std::end(fhicl::ParameterSetRegistry::get());
00267 # else
00268 auto I = fhicl::ParameterSetRegistry::begin(),
00269 E = fhicl::ParameterSetRegistry::end();
00270 # endif
00271 I != E; ++I)
00272 {
00273 std::string pset_str = I->second.to_string();
00274
00275 msg.WriteStdString(pset_str);
00276 }
00277 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Finished streaming parameter sets." << TLOG_ENDL;
00278
00279
00280
00281
00282 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Streaming MasterProductRegistry ..." << TLOG_ENDL;
00283 art::ProductList productList(
00284 art::ProductMetaData::instance().productList());
00285 msg.WriteObjectAny(&productList, product_list_class);
00286 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Finished streaming MasterProductRegistry." << TLOG_ENDL;
00287
00288
00289
00290
00291 # if ART_HEX_VERSION >= 0x20703
00292 art::BranchIDLists const * bilr =
00293 &art::BranchIDListRegistry::instance().data();
00294 # else
00295 art::BranchIDLists* bilr =
00296 &art::BranchIDListRegistry::instance()->data();
00297 # endif
00298 TLOG_ARB(TLVL_SENDINIT_VERBOSE1, "RootNetOutput") << "RootNetOutput static send_init_message(): Content of BranchIDLists" << TLOG_ENDL;
00299 int max_bli = bilr->size();
00300 TLOG_ARB(TLVL_SENDINIT_VERBOSE1, "RootNetOutput") << "RootNetOutput static send_init_message(): max_bli: " << max_bli << TLOG_ENDL;
00301 for (int i = 0; i < max_bli; ++i)
00302 {
00303 int max_prdidx = (*bilr)[i].size();
00304 TLOG_ARB(TLVL_SENDINIT_VERBOSE1, "RootNetOutput") << "RootNetOutput static send_init_message(): max_prdidx: " << max_prdidx << TLOG_ENDL;
00305 for (int j = 0; j < max_prdidx; ++j)
00306 {
00307 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;
00308 }
00309 }
00310
00311 # if ART_HEX_VERSION >= 0x20703
00312 art::ProcessHistoryMap phr;
00313 for (auto const& pr : art::ProcessHistoryRegistry::get()) {
00314 phr.emplace(pr);
00315 }
00316 # endif
00317
00318
00319
00320 TLOG_ARB(TLVL_SENDINIT_VERBOSE2, "RootNetOutput") << "RootNetOutput static send_init_message(): Dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
00321
00322
00323 # if ART_HEX_VERSION < 0x20703
00324 art::ProcessHistoryMap const& phr = art::ProcessHistoryRegistry::get();
00325 # endif
00326 TLOG_ARB(TLVL_SENDINIT_VERBOSE2, "RootNetOutput") << "RootNetOutput static send_init_message(): phr: size: " << std::to_string(phr.size()) << TLOG_ENDL;
00327 for (auto I = phr.begin(), E = phr.end(); I != E; ++I)
00328 {
00329 std::ostringstream OS;
00330 I->first.print(OS);
00331 TLOG_ARB(TLVL_SENDINIT_VERBOSE2, "RootNetOutput") << "RootNetOutput static send_init_message(): phr: id: '" << OS.str() << "'" << TLOG_ENDL;
00332 }
00333
00334
00335
00336 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Streaming ProcessHistoryRegistry ..." << TLOG_ENDL;
00337
00338
00339 # if ART_HEX_VERSION >= 0x20703
00340 const art::ProcessHistoryMap& phm = phr;
00341 # else
00342 const art::ProcessHistoryMap& phm = art::ProcessHistoryRegistry::get();
00343 # endif
00344 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): phm: size: " << std::to_string(phm.size()) << TLOG_ENDL;
00345 msg.WriteObjectAny(&phm, process_history_map_class);
00346 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Finished streaming ProcessHistoryRegistry." << TLOG_ENDL;
00347
00348
00349
00350
00351 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "static send_init_message(): Streaming ParentageRegistry ..." << TLOG_ENDL;
00352 # if ART_HEX_VERSION >= 0x20703
00353 art::ParentageMap parentageMap{};
00354 for (auto const& pr : art::ParentageRegistry::get()) {
00355 parentageMap.emplace(pr.first, pr.second);
00356 }
00357 # else
00358 const art::ParentageMap& parentageMap = art::ParentageRegistry::get();
00359 # endif
00360
00361 msg.WriteObjectAny(&parentageMap, parentage_map_class);
00362
00363 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "static send_init_message(): Finished streaming ParentageRegistry." << TLOG_ENDL;
00364
00365
00366
00367
00368
00369 art::ServiceHandle<NetMonTransportService> transport;
00370 if (!transport.get())
00371 {
00372 TLOG_ERROR("RootNetOutput") << "Could not get handle to NetMonTransportService!" << TLOG_ENDL;
00373 return;
00374 }
00375 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Sending the init message to " << std::to_string(transport->dataReceiverCount()) << " data receivers ..." << TLOG_ENDL;
00376 for (size_t idx = 0; idx < transport->dataReceiverCount(); ++idx)
00377 {
00378 transport->sendMessage(idx, artdaq::Fragment::InitFragmentType, msg);
00379 }
00380 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "RootNetOutput static send_init_message(): Init message(s) sent." << TLOG_ENDL;
00381
00382 TLOG_ARB(TLVL_SENDINIT, "RootNetOutput") << "End: RootNetOutput static send_init_message()" << TLOG_ENDL;
00383 }
00384
00385
00386
00387 void
00388 art::RootNetOutput::
00389 writeDataProducts(TBufferFile& msg, const Principal& principal,
00390 std::vector<BranchKey*>& bkv)
00391 {
00392 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "Begin: RootNetOutput::writeDataProducts(...)" << TLOG_ENDL;
00393
00394
00395
00396
00397 static TClass* branch_key_class = TClass::GetClass("art::BranchKey");
00398 if (branch_key_class == nullptr)
00399 {
00400 throw art::Exception(art::errors::DictionaryNotFound) <<
00401 "RootNetOutput::writeDataProducts(...): "
00402 "Could not get TClass for art::BranchKey!";
00403 }
00404 static TClass* prdprov_class = TClass::GetClass("art::ProductProvenance");
00405 if (prdprov_class == nullptr)
00406 {
00407 throw art::Exception(art::errors::DictionaryNotFound) <<
00408 "RootNetOutput::writeDataProducts(...): "
00409 "Could not get TClass for art::ProductProvenance!";
00410 }
00411
00412
00413
00414 unsigned long prd_cnt = 0;
00415
00416 for (auto I = principal.begin(), E = principal.end(); I != E; ++I)
00417 {
00418 if (I->second->productUnavailable() || !selected(I->second->productDescription()))
00419 {
00420 continue;
00421 }
00422 ++prd_cnt;
00423 }
00424
00425
00426
00427 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "RootNetOutput::writeDataProducts(...): Streaming product count: " + std::to_string(prd_cnt) << TLOG_ENDL;
00428 msg.WriteULong(prd_cnt);
00429 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "RootNetOutput::writeDataProducts(...): Finished streaming product count." << TLOG_ENDL;
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 bkv.reserve(prd_cnt);
00442
00443 for (auto I = principal.begin(), E = principal.end(); I != E; ++I)
00444 {
00445 if (I->second->productUnavailable() || !selected(I->second->productDescription()))
00446 {
00447 continue;
00448 }
00449 const BranchDescription& bd(I->second->productDescription());
00450 bkv.push_back(new BranchKey(bd));
00451 TLOG_ARB(TLVL_WRITEDATAPRODUCTS_VERBOSE, "RootNetOutput") << "RootNetOutput::writeDataProducts(...): Dumping branch key of class: '"
00452 << bkv.back()->friendlyClassName_
00453 << "' modlbl: '"
00454 << bkv.back()->moduleLabel_
00455 << "' instnm: '"
00456 << bkv.back()->productInstanceName_
00457 << "' procnm: '"
00458 << bkv.back()->processName_
00459 << "'" << TLOG_ENDL;
00460 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "RootNetOutput::writeDataProducts(...): "
00461 "Streaming branch key of class: '"
00462 << bd.producedClassName()
00463 << "' modlbl: '"
00464 << bd.moduleLabel()
00465 << "' instnm: '"
00466 << bd.productInstanceName()
00467 << "' procnm: '"
00468 << bd.processName()
00469 << "'" << TLOG_ENDL;
00470 msg.WriteObjectAny(bkv.back(), branch_key_class);
00471 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "RootNetOutput::writeDataProducts(...): "
00472 "Streaming product of class: '"
00473 << bd.producedClassName()
00474 << "' modlbl: '"
00475 << bd.moduleLabel()
00476 << "' instnm: '"
00477 << bd.productInstanceName()
00478 << "' procnm: '"
00479 << bd.processName()
00480 << "'" << TLOG_ENDL;
00481 OutputHandle oh = principal.getForOutput(bd.branchID(), true);
00482 const EDProduct* prd = oh.wrapper();
00483 msg.WriteObjectAny(prd, TClass::GetClass(bd.wrappedName().c_str()));
00484 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "RootNetOutput::writeDataProducts(...): "
00485 "Streaming product provenance of class: '"
00486 << bd.producedClassName()
00487 << "' modlbl: '"
00488 << bd.moduleLabel()
00489 << "' instnm: '"
00490 << bd.productInstanceName()
00491 << "' procnm: '"
00492 << bd.processName()
00493 << "'" << TLOG_ENDL;
00494 const ProductProvenance* prdprov =
00495 I->second->productProvenancePtr().get();
00496 msg.WriteObjectAny(prdprov, prdprov_class);
00497 }
00498 TLOG_ARB(TLVL_WRITEDATAPRODUCTS, "RootNetOutput") << "End: RootNetOutput::writeDataProducts(...)" << TLOG_ENDL;
00499 }
00500
00501 void
00502 art::RootNetOutput::
00503 write(CONST_WRITE EventPrincipal& ep)
00504 {
00505
00506
00507
00508 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "Begin: RootNetOutput::write(const EventPrincipal& ep)" << TLOG_ENDL;
00509 if (!initMsgSent_)
00510 {
00511 send_init_message();
00512 initMsgSent_ = true;
00513 }
00514
00515
00516
00517 static TClass* run_aux_class = TClass::GetClass("art::RunAuxiliary");
00518 if (run_aux_class == nullptr)
00519 {
00520 throw art::Exception(art::errors::DictionaryNotFound) <<
00521 "RootNetOutput::write(const EventPrincipal& ep): "
00522 "Could not get TClass for art::RunAuxiliary!";
00523 }
00524 static TClass* subrun_aux_class = TClass::GetClass("art::SubRunAuxiliary");
00525 if (subrun_aux_class == nullptr)
00526 {
00527 throw art::Exception(art::errors::DictionaryNotFound) <<
00528 "RootNetOutput::write(const EventPrincipal& ep): "
00529 "Could not get TClass for art::SubRunAuxiliary!";
00530 }
00531 static TClass* event_aux_class = TClass::GetClass("art::EventAuxiliary");
00532 if (event_aux_class == nullptr)
00533 {
00534 throw art::Exception(art::errors::DictionaryNotFound) <<
00535 "RootNetOutput::write(const EventPrincipal& ep): "
00536 "Could not get TClass for art::EventAuxiliary!";
00537 }
00538 static TClass* history_class = TClass::GetClass("art::History");
00539 if (history_class == nullptr)
00540 {
00541 throw art::Exception(art::errors::DictionaryNotFound) <<
00542 "RootNetOutput::write(const EventPrincipal& ep): "
00543 "Could not get TClass for art::History!";
00544 }
00545
00546
00547
00548 TBufferFile msg(TBuffer::kWrite);
00549 msg.SetWriteMode();
00550
00551
00552
00553 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Streaming message type code ..." << TLOG_ENDL;
00554 msg.WriteULong(4);
00555 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Finished streaming message type code." << TLOG_ENDL;
00556
00557
00558
00559
00560 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Streaming RunAuxiliary ..." << TLOG_ENDL;
00561 msg.WriteObjectAny(&ep.subRunPrincipal().runPrincipal().aux(),
00562 run_aux_class);
00563 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Finished streaming RunAuxiliary." << TLOG_ENDL;
00564
00565
00566
00567
00568 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Streaming SubRunAuxiliary ..." << TLOG_ENDL;
00569 msg.WriteObjectAny(&ep.subRunPrincipal().aux(),
00570 subrun_aux_class);
00571 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Finished streaming SubRunAuxiliary." << TLOG_ENDL;
00572
00573
00574
00575
00576 {
00577 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Streaming EventAuxiliary ..." << TLOG_ENDL;
00578 msg.WriteObjectAny(&ep.aux(), event_aux_class);
00579 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Finished streaming EventAuxiliary." << TLOG_ENDL;
00580 }
00581
00582
00583
00584 {
00585 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Streaming History ..." << TLOG_ENDL;
00586 msg.WriteObjectAny(&ep.history(), history_class);
00587 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Finished streaming History." << TLOG_ENDL;
00588 }
00589
00590
00591
00592 std::vector<BranchKey*> bkv;
00593 writeDataProducts(msg, ep, bkv);
00594
00595
00596
00597 {
00598 ServiceHandle<NetMonTransportService> transport;
00599 if (!transport.get())
00600 {
00601 TLOG_ERROR("RootNetOutput") << "Could not get handle to NetMonTransportService!" << TLOG_ENDL;
00602 return;
00603 }
00604 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Sending a message ..." << TLOG_ENDL;
00605 transport->sendMessage(ep.id().event(), artdaq::Fragment::DataFragmentType, msg);
00606 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "RootNetOutput::write(const EventPrincipal& ep): Message sent." << TLOG_ENDL;
00607 }
00608
00609
00610
00611 for (auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
00612 {
00613 delete *I;
00614 *I = 0;
00615 }
00616 TLOG_ARB(TLVL_WRITE, "RootNetOutput") << "End: RootNetOutput::write(const EventPrincipal& ep)" << TLOG_ENDL;
00617 }
00618
00619 void
00620 art::RootNetOutput::
00621 writeRun(CONST_WRITE RunPrincipal& rp)
00622 {
00623
00624
00625
00626 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "Begin: RootNetOutput::writeRun(const RunPrincipal& rp)" << TLOG_ENDL;
00627 (void)rp;
00628 if (!initMsgSent_)
00629 {
00630 send_init_message();
00631 initMsgSent_ = true;
00632 }
00633 #if 0
00634
00635
00636
00637
00638 static TClass* run_aux_class = TClass::GetClass("art::RunAuxiliary");
00639 assert(run_aux_class != nullptr && "writeRun: Could not get TClass for art::RunAuxiliary!");
00640
00641
00642
00643 TBufferFile msg(TBuffer::kWrite);
00644 msg.SetWriteMode();
00645
00646
00647
00648 {
00649 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "writeRun: streaming message type code ..." << TLOG_ENDL;
00650 msg.WriteULong(2);
00651 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "writeRun: finished streaming message type code." << TLOG_ENDL;
00652 }
00653
00654
00655
00656 {
00657 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "writeRun: streaming RunAuxiliary ..." << TLOG_ENDL;
00658 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
00659
00660
00661 art::ProcessHistoryMap const& phr =
00662 art::ProcessHistoryRegistry::get();
00663 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: phr: size: " << phr.size() << TLOG_ENDL;
00664 for (auto I = phr.begin(), E = phr.end(); I != E; ++I) {
00665 std::ostringstream OS;
00666 I->first.print(OS);
00667 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: phr: id: '" << OS.str() << "'" << TLOG_ENDL;
00668 OS.str("");
00669 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: phr: data.size(): " << I->second.data().size() << TLOG_ENDL;
00670 if (I->second.data().size()) {
00671 I->second.data().back().id().print(OS);
00672 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: phr: data.back().id(): '" << OS.str() << "'" << TLOG_ENDL;
00673 }
00674 }
00675 if (!rp.aux().processHistoryID().isValid()) {
00676 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: ProcessHistoryID: 'INVALID'" << TLOG_ENDL;
00677 }
00678 else {
00679 std::ostringstream OS;
00680 rp.aux().processHistoryID().print(OS);
00681 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: ProcessHistoryID: '" << OS.str() << "'" << TLOG_ENDL;
00682 OS.str("");
00683 const ProcessHistory& processHistory =
00684 ProcessHistoryRegistry::get(rp.aux().processHistoryID());
00685 if (processHistory.data().size()) {
00686
00687 processHistory.data().back().id().print(OS);
00688 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: ProcessConfigurationID: '" << OS.str() << "'" << TLOG_ENDL;
00689 OS.str("");
00690 TLOG_ARB(TLVL_WRITERUN_VERBOSE, "RootNetOutput") << "writeRun: ProcessConfiguration: '" << processHistory.data().back() << TLOG_ENDL;
00691 }
00692 }
00693 msg.WriteObjectAny(&rp.aux(), run_aux_class);
00694 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "writeRun: streamed RunAuxiliary." << TLOG_ENDL;
00695 }
00696
00697
00698
00699 std::vector<BranchKey*> bkv;
00700 writeDataProducts(msg, rp, bkv);
00701
00702
00703
00704 {
00705 ServiceHandle<NetMonTransportService> transport;
00706 if (!transport.get())
00707 {
00708 TLOG_ERROR("RootNetOutput") << "Could not get handle to NetMonTransportService!" << TLOG_ENDL;
00709 return;
00710 }
00711 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "writeRun: sending a message ..." << TLOG_ENDL;
00712 transport->sendMessage(0, artdaq::Fragment::EndOfRunFragmentType, msg);
00713 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "writeRun: message sent." << TLOG_ENDL;
00714 }
00715
00716
00717
00718 for (auto I = bkv.begin(), E = bkv.end(); I != E; ++I) {
00719 delete *I;
00720 *I = 0;
00721 }
00722 #endif // 0
00723 TLOG_ARB(TLVL_WRITERUN, "RootNetOutput") << "End: RootNetOutput::writeRun(const RunPrincipal& rp)" << TLOG_ENDL;
00724 }
00725
00726 void
00727 art::RootNetOutput::writeSubRun(CONST_WRITE SubRunPrincipal& srp)
00728 {
00729
00730
00731
00732 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "Begin: RootNetOutput::writeSubRun(const SubRunPrincipal& srp)" << TLOG_ENDL;
00733 if (!initMsgSent_)
00734 {
00735 send_init_message();
00736 initMsgSent_ = true;
00737 }
00738
00739
00740
00741
00742 static TClass* subrun_aux_class = TClass::GetClass("art::SubRunAuxiliary");
00743 if (subrun_aux_class == nullptr)
00744 {
00745 throw art::Exception(art::errors::DictionaryNotFound) <<
00746 "RootNetOutput::writeSubRun: "
00747 "Could not get TClass for art::SubRunAuxiliary!";
00748 }
00749
00750
00751
00752 TBufferFile msg(TBuffer::kWrite);
00753 msg.SetWriteMode();
00754
00755
00756
00757 {
00758 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "RootNetOutput::writeSubRun: streaming message type code ..." << TLOG_ENDL;
00759 msg.WriteULong(3);
00760 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "RootNetOutput::writeSubRun: finished streaming message type code." << TLOG_ENDL;
00761 }
00762
00763
00764
00765 {
00766 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "RootNetOutput::writeSubRun: streaming SubRunAuxiliary ..." << TLOG_ENDL;
00767
00768 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: dumping ProcessHistoryRegistry ..." << TLOG_ENDL;
00769
00770
00771 # if ART_HEX_VERSION >= 0x20703
00772 for (auto I = std::begin(art::ProcessHistoryRegistry::get())
00773 , E = std::end(art::ProcessHistoryRegistry::get()); I != E; ++I)
00774 # else
00775 art::ProcessHistoryMap const& phr =
00776 art::ProcessHistoryRegistry::get();
00777 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: phr: size: " << std::to_string(phr.size()) << TLOG_ENDL;
00778 for (auto I = phr.begin(), E = phr.end(); I != E; ++I)
00779 # endif
00780 {
00781 std::ostringstream OS;
00782 I->first.print(OS);
00783 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: phr: id: '" << OS.str() << "'" << TLOG_ENDL;
00784 OS.str("");
00785 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: phr: data.size(): " << std::to_string(I->second.data().size()) << TLOG_ENDL;
00786 if (I->second.data().size())
00787 {
00788 I->second.data().back().id().print(OS);
00789 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: phr: data.back().id(): '" << OS.str() << "'" << TLOG_ENDL;
00790 }
00791 }
00792 if (!srp.aux().processHistoryID().isValid())
00793 {
00794 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: ProcessHistoryID: 'INVALID'" << TLOG_ENDL;
00795 }
00796 else
00797 {
00798 std::ostringstream OS;
00799 srp.aux().processHistoryID().print(OS);
00800 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: ProcessHistoryID: '" << OS.str() << "'" << TLOG_ENDL;
00801 OS.str("");
00802 # if ART_HEX_VERSION >= 0x20703
00803 ProcessHistory processHistory;
00804 ProcessHistoryRegistry::get(srp.aux().processHistoryID(), processHistory);
00805 # else
00806 const ProcessHistory& processHistory =
00807 ProcessHistoryRegistry::get(srp.aux().processHistoryID());
00808 # endif
00809 if (processHistory.data().size())
00810 {
00811
00812 processHistory.data().back().id().print(OS);
00813 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: ProcessConfigurationID: '" << OS.str() << "'" << TLOG_ENDL;
00814 OS.str("");
00815 OS << processHistory.data().back();
00816 TLOG_ARB(TLVL_WRITESUBRUN_VERBOSE, "RootNetOutput") << "RootNetOutput::writeSubRun: ProcessConfiguration: '" << OS.str() << TLOG_ENDL;
00817 }
00818 }
00819 msg.WriteObjectAny(&srp.aux(), subrun_aux_class);
00820 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "RootNetOutput::writeSubRun: streamed SubRunAuxiliary." << TLOG_ENDL;
00821 }
00822
00823
00824
00825 std::vector<BranchKey*> bkv;
00826 writeDataProducts(msg, srp, bkv);
00827
00828
00829
00830 ServiceHandle<NetMonTransportService> transport;
00831 if (!transport.get())
00832 {
00833 TLOG_ERROR("RootNetOutput") << "Could not get handle to NetMonTransportService!" << TLOG_ENDL;
00834 return;
00835 }
00836 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "RootNetOutput::writeSubRun: Sending the EndOfSubrun message to " << std::to_string(transport->dataReceiverCount()) << " data receivers ..." << TLOG_ENDL;
00837 for (size_t idx = 0; idx < transport->dataReceiverCount(); ++idx)
00838 {
00839 transport->sendMessage(idx, artdaq::Fragment::EndOfSubrunFragmentType, msg);
00840 }
00841 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "RootNetOutput::writeSubRun: EndOfSubrun message(s) sent." << TLOG_ENDL;
00842
00843
00844
00845 transport->disconnect();
00846
00847
00848
00849
00850 for (auto I = bkv.begin(), E = bkv.end(); I != E; ++I)
00851 {
00852 delete *I;
00853 *I = 0;
00854 }
00855 TLOG_ARB(TLVL_WRITESUBRUN, "RootNetOutput") << "End: RootNetOutput::writeSubRun(const SubRunPrincipal& srp)" << TLOG_ENDL;
00856 }
00857
00858 DEFINE_ART_MODULE(art::RootNetOutput)