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