1 #define TRACE_NAME "BinaryNetOutput"
3 #include "art/Framework/Core/ModuleMacros.h"
4 #include "art/Framework/Core/OutputModule.h"
5 #include "art/Framework/Principal/EventPrincipal.h"
6 #include "art/Framework/Principal/RunPrincipal.h"
7 #include "art/Framework/Principal/Selector.h"
8 #include "art/Framework/Principal/SubRunPrincipal.h"
9 #include "art/Framework/Principal/Handle.h"
10 #include "art/Persistency/Common/GroupQueryResult.h"
11 #include "canvas/Utilities/DebugMacros.h"
12 #include "canvas/Utilities/Exception.h"
13 #include "fhiclcpp/ParameterSet.h"
15 #include "artdaq/DAQrate/DataSenderManager.hh"
16 #include "artdaq/DAQdata/Globals.hh"
17 #include "artdaq-core/Data/Fragment.hh"
33 using fhicl::ParameterSet;
63 void beginJob()
override;
65 void endJob()
override;
67 void write(EventPrincipal&)
override;
69 void writeRun(RunPrincipal&)
override {};
70 void writeSubRun(SubRunPrincipal&)
override {};
72 void initialize_MPI_();
74 void deinitialize_MPI_();
76 bool readParameterSet_(fhicl::ParameterSet
const& pset);
79 ParameterSet data_pset_;
80 std::string name_ =
"BinaryNetOutput";
82 std::unique_ptr<artdaq::DataSenderManager> sender_ptr_ = {
nullptr};
89 TLOG(TLVL_DEBUG) <<
"Begin: BinaryNetOutput::BinaryNetOutput(ParameterSet const& ps)\n";
90 readParameterSet_(ps);
91 TLOG(TLVL_DEBUG) <<
"End: BinaryNetOutput::BinaryNetOutput(ParameterSet const& ps)\n";
97 TLOG(TLVL_DEBUG) <<
"Begin/End: BinaryNetOutput::~BinaryNetOutput()\n";
101 art::BinaryNetOutput::
104 TLOG(TLVL_DEBUG) <<
"Begin: BinaryNetOutput::beginJob()\n";
106 TLOG(TLVL_DEBUG) <<
"End: BinaryNetOutput::beginJob()\n";
110 art::BinaryNetOutput::
113 TLOG(TLVL_DEBUG) <<
"Begin: BinaryNetOutput::endJob()\n";
115 TLOG(TLVL_DEBUG) <<
"End: BinaryNetOutput::endJob()\n";
120 art::BinaryNetOutput::
123 if (rt_priority_ > 0)
125 #pragma GCC diagnostic push
126 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
127 sched_param s_param = {};
128 s_param.sched_priority = rt_priority_;
129 int status = pthread_setschedparam(pthread_self(), SCHED_RR, &s_param);
132 TLOG(TLVL_ERROR) << name_
133 <<
"Failed to set realtime priority to " << rt_priority_
134 <<
", return code = " << status;
136 #pragma GCC diagnostic pop
139 sender_ptr_ = std::make_unique<artdaq::DataSenderManager>(data_pset_);
144 art::BinaryNetOutput::
147 sender_ptr_.reset(
nullptr);
151 art::BinaryNetOutput::
152 readParameterSet_(fhicl::ParameterSet
const& pset)
154 TLOG(TLVL_DEBUG) << name_ <<
"BinaryNetOutput::readParameterSet_ method called with "
155 <<
"ParameterSet = \"" << pset.to_string()
160 name_ = pset.get<std::string>(
"module_name",
"BinaryNetOutput");
161 rt_priority_ = pset.get<
int>(
"rt_priority", 0);
163 TLOG(TLVL_TRACE) <<
"BinaryNetOutput::readParameterSet()";
169 art::BinaryNetOutput::
170 write(EventPrincipal& ep)
174 using RawEvent = artdaq::Fragments;;
175 using RawEvents = std::vector<RawEvent>;
176 using RawEventHandle = art::Handle<RawEvent>;
177 using RawEventHandles = std::vector<RawEventHandle>;
179 auto result_handles = std::vector<art::GroupQueryResult>();
181 auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
182 result_handles = ep.getMany(wrapped, art::MatchAllSelector{});
184 for (
auto const& result_handle : result_handles)
186 auto const raw_event_handle = RawEventHandle(result_handle);
188 if (!raw_event_handle.isValid())
191 for (
auto const& fragment : *raw_event_handle)
193 auto fragment_copy = fragment;
194 auto fragid_id = fragment_copy.fragmentID();
195 auto sequence_id = fragment_copy.sequenceID();
196 TLOG(TLVL_DEBUG) <<
"BinaryNetOutput::write seq=" << sequence_id <<
" frag=" << fragid_id <<
" start";
197 sender_ptr_->sendFragment(std::move(fragment_copy));
198 TLOG(TLVL_DEBUG) <<
"BinaryNetOutput::write seq=" << sequence_id <<
" frag=" << fragid_id <<
" done";
BinaryNetOutput(ParameterSet const &ps)
BinaryNetOutput Constructor.
An art::OutputModule which sends Fragments using DataSenderManager. This module produces output ident...
virtual ~BinaryNetOutput()
BinaryNetOutput Destructor.