1 #define TRACE_NAME "BinaryNetOutput"
2 #include "artdaq/DAQdata/Globals.hh"
4 #include "art/Framework/Core/ModuleMacros.h"
5 #include "art/Framework/Core/OutputModule.h"
6 #include "art/Framework/Principal/EventPrincipal.h"
7 #include "art/Framework/Principal/Handle.h"
8 #include "art/Framework/Principal/RunPrincipal.h"
9 #include "art/Framework/Principal/Selector.h"
10 #include "art/Framework/Principal/SubRunPrincipal.h"
11 #include "art/Persistency/Common/GroupQueryResult.h"
12 #include "art/Persistency/Provenance/ModuleContext.h"
13 #include "canvas/Persistency/Common/Wrapper.h"
14 #include "canvas/Utilities/DebugMacros.h"
15 #include "canvas/Utilities/Exception.h"
16 #if ART_HEX_VERSION < 0x30901
17 #include "canvas/Utilities/WrappedTypeID.h"
19 #include "canvas/Persistency/Common/WrappedTypeID.h"
21 #include "fhiclcpp/ParameterSet.h"
23 #include "artdaq-core/Data/Fragment.hh"
24 #include "artdaq/DAQrate/DataSenderManager.hh"
39 using fhicl::ParameterSet;
74 void beginJob()
override;
76 void endJob()
override;
78 void write(EventPrincipal& )
override;
80 void writeRun(RunPrincipal& )
override{};
81 void writeSubRun(SubRunPrincipal& )
override{};
83 void initialize_MPI_();
85 void deinitialize_MPI_();
87 bool readParameterSet_(fhicl::ParameterSet
const& pset);
90 ParameterSet data_pset_;
91 std::string name_ =
"BinaryNetOutput";
93 std::unique_ptr<artdaq::DataSenderManager> sender_ptr_ = {
nullptr};
99 TLOG(TLVL_DEBUG) <<
"Begin: BinaryNetOutput::BinaryNetOutput(ParameterSet const& ps)\n";
100 readParameterSet_(ps);
101 TLOG(TLVL_DEBUG) <<
"End: BinaryNetOutput::BinaryNetOutput(ParameterSet const& ps)\n";
106 void art::BinaryNetOutput::beginJob()
108 TLOG(TLVL_DEBUG) <<
"Begin: BinaryNetOutput::beginJob()\n";
110 TLOG(TLVL_DEBUG) <<
"End: BinaryNetOutput::beginJob()\n";
113 void art::BinaryNetOutput::endJob()
115 TLOG(TLVL_DEBUG) <<
"Begin: BinaryNetOutput::endJob()\n";
117 TLOG(TLVL_DEBUG) <<
"End: BinaryNetOutput::endJob()\n";
120 void art::BinaryNetOutput::initialize_MPI_()
122 if (rt_priority_ > 0)
124 #pragma GCC diagnostic push
125 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
126 sched_param s_param = {};
127 s_param.sched_priority = rt_priority_;
128 int status = pthread_setschedparam(pthread_self(), SCHED_RR, &s_param);
131 TLOG(TLVL_ERROR) << name_ <<
"Failed to set realtime priority to " << rt_priority_
132 <<
", return code = " << status;
134 #pragma GCC diagnostic pop
137 sender_ptr_ = std::make_unique<artdaq::DataSenderManager>(data_pset_);
141 void art::BinaryNetOutput::deinitialize_MPI_() { sender_ptr_.reset(
nullptr); }
143 bool art::BinaryNetOutput::readParameterSet_(fhicl::ParameterSet
const& pset)
145 TLOG(TLVL_DEBUG) << name_ <<
"BinaryNetOutput::readParameterSet_ method called with "
146 <<
"ParameterSet = \"" << pset.to_string() <<
"\".";
150 name_ = pset.get<std::string>(
"module_name",
"BinaryNetOutput");
151 rt_priority_ = pset.get<
int>(
"rt_priority", 0);
153 TLOG(TLVL_TRACE) <<
"BinaryNetOutput::readParameterSet()";
158 void art::BinaryNetOutput::write(EventPrincipal& ep)
162 using RawEvent = artdaq::Fragments;
164 using RawEvents = std::vector<RawEvent>;
165 using RawEventHandle = art::Handle<RawEvent>;
166 using RawEventHandles = std::vector<RawEventHandle>;
168 auto result_handles = std::vector<art::GroupQueryResult>();
170 auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
172 ModuleContext
const mc{moduleDescription()};
173 ProcessTag
const processTag{
"", mc.moduleDescription().processName()};
175 result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
177 artdaq::Fragment::sequence_id_t sequence_id = 0;
179 for (
auto const& result_handle : result_handles)
181 auto const raw_event_handle = RawEventHandle(result_handle);
183 if (!raw_event_handle.isValid())
188 for (
auto const& fragment : *raw_event_handle)
190 auto fragment_copy = fragment;
191 auto fragid_id = fragment_copy.fragmentID();
192 sequence_id = fragment_copy.sequenceID();
193 TLOG(TLVL_DEBUG) <<
"BinaryNetOutput::write seq=" << sequence_id <<
" frag=" << fragid_id <<
" start";
194 sender_ptr_->sendFragment(std::move(fragment_copy));
195 TLOG(TLVL_DEBUG) <<
"BinaryNetOutput::write seq=" << sequence_id <<
" frag=" << fragid_id <<
" done";
201 sender_ptr_->RemoveRoutingTableEntry(sequence_id);
BinaryNetOutput(ParameterSet const &ps)
BinaryNetOutput Constructor.
An art::OutputModule which sends Fragments using DataSenderManager. This module produces output ident...
~BinaryNetOutput() override
BinaryNetOutput Destructor.