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