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