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 FDEBUG(1) <<
"Begin: BinaryNetOutput::BinaryNetOutput(ParameterSet const& ps)\n";
90 readParameterSet_(ps);
91 FDEBUG(1) <<
"End: BinaryNetOutput::BinaryNetOutput(ParameterSet const& ps)\n";
97 FDEBUG(1) <<
"Begin/End: BinaryNetOutput::~BinaryNetOutput()\n";
101 art::BinaryNetOutput::
104 FDEBUG(1) <<
"Begin: BinaryNetOutput::beginJob()\n";
106 FDEBUG(1) <<
"End: BinaryNetOutput::beginJob()\n";
110 art::BinaryNetOutput::
113 FDEBUG(1) <<
"Begin: BinaryNetOutput::endJob()\n";
115 FDEBUG(1) <<
"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);
133 <<
"Failed to set realtime priority to " << rt_priority_
134 <<
", return code = " << status << TLOG_ENDL;
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_DEBUG(name_) <<
"BinaryNetOutput::readParameterSet_ method called with "
155 <<
"ParameterSet = \"" << pset.to_string()
156 <<
"\"." << TLOG_ENDL;
160 name_ = pset.get<std::string>(
"module_name",
"BinaryNetOutput");
161 rt_priority_ = pset.get<
int>(
"rt_priority", 0);
163 TRACE(4,
"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 #if ART_HEX_VERSION < 0x20906
182 ep.getManyByType(art::TypeID(
typeid(RawEvent)), result_handles);
184 auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
185 result_handles = ep.getMany(wrapped, art::MatchAllSelector{});
188 for (
auto const& result_handle : result_handles)
190 auto const raw_event_handle = RawEventHandle(result_handle);
192 if (!raw_event_handle.isValid())
195 for (
auto const& fragment : *raw_event_handle)
197 auto fragment_copy = fragment;
198 auto fragid_id = fragment_copy.fragmentID();
199 auto sequence_id = fragment_copy.sequenceID();
200 TRACE(1,
"BinaryNetOutput::write seq=%lu frag=%i start", sequence_id, fragid_id);
201 sender_ptr_->sendFragment(std::move(fragment_copy));
202 TRACE(2,
"BinaryNetOutput::write seq=%lu frag=%i done", sequence_id, fragid_id);
BinaryNetOutput(ParameterSet const &ps)
BinaryNetOutput Constructor.
An art::OutputModule which sends Fragments using DataSenderManager. This module produces output ident...
virtual ~BinaryNetOutput()
BinaryNetOutput Destructor.