1 #define TRACE_NAME "HDFFileOutput"
3 #include "artdaq-demo-hdf5/HDF5/MakeDatasetPlugin.hh"
5 #include "art/Framework/Core/ModuleMacros.h"
6 #include "art/Framework/Core/OutputModule.h"
7 #include "art/Framework/IO/FileStatsCollector.h"
8 #include "art/Framework/IO/PostCloseFileRenamer.h"
9 #include "art/Framework/Principal/EventPrincipal.h"
10 #include "art/Framework/Principal/Handle.h"
11 #include "art/Framework/Principal/RunPrincipal.h"
12 #include "art/Framework/Principal/SubRunPrincipal.h"
13 #include "art/Persistency/Common/GroupQueryResult.h"
14 #include "art/Persistency/Provenance/ModuleContext.h"
15 #include "canvas/Persistency/Common/Wrapper.h"
16 #include "canvas/Utilities/DebugMacros.h"
17 #include "canvas/Utilities/Exception.h"
18 #include "canvas/Persistency/Common/WrappedTypeID.h"
19 #include "fhiclcpp/ParameterSet.h"
21 #include "artdaq/ArtModules/ArtdaqFragmentNamingService.h"
22 #include "artdaq/DAQdata/Globals.hh"
39 using fhicl::ParameterSet;
71 void beginJob()
override;
73 void endJob()
override;
75 void write(EventPrincipal& )
override;
77 void writeRun(RunPrincipal& )
override{};
78 void writeSubRun(SubRunPrincipal& )
override{};
81 std::string name_ =
"HDFFileOutput";
82 art::FileStatsCollector fstats_;
84 std::unique_ptr<artdaq::hdf5::FragmentDataset> ntuple_;
89 , fstats_{name_, processName()}
91 TLOG(TLVL_DEBUG) <<
"Begin: HDFFileOutput::HDFFileOutput(ParameterSet const& ps)\n";
93 ntuple_ = artdaq::hdf5::MakeDatasetPlugin(ps,
"dataset");
95 <<
"End: HDFFileOutput::HDFFileOutput(ParameterSet const& ps)\n";
100 void art::HDFFileOutput::beginJob()
102 TLOG(TLVL_DEBUG) <<
"Begin: HDFFileOutput::beginJob()\n";
103 TLOG(TLVL_DEBUG) <<
"End: HDFFileOutput::beginJob()\n";
106 void art::HDFFileOutput::endJob()
108 TLOG(TLVL_DEBUG) <<
"Begin: HDFFileOutput::endJob()\n";
109 TLOG(TLVL_DEBUG) <<
"End: HDFFileOutput::endJob()\n";
112 void art::HDFFileOutput::write(EventPrincipal& ep)
114 TLOG(TLVL_TRACE) <<
"Begin: HDFFileOutput::write(EventPrincipal& ep)";
115 using RawEvent = artdaq::Fragments;
116 using RawEvents = std::vector<RawEvent>;
117 using RawEventHandle = art::Handle<RawEvent>;
118 using RawEventHeaderHandle = art::Handle<artdaq::detail::RawEventHeader>;
120 auto hdr_found =
false;
121 auto sequence_id = artdaq::Fragment::InvalidSequenceID;
123 TLOG(5) <<
"write: Retrieving event Fragments";
125 auto result_handles = std::vector<art::GroupQueryResult>();
126 auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
127 ModuleContext
const mc{moduleDescription()};
128 ProcessTag
const processTag{
"", mc.moduleDescription().processName()};
130 result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
132 for (
auto const& result_handle : result_handles)
134 auto const raw_event_handle = RawEventHandle(result_handle);
136 if (raw_event_handle.isValid() && !raw_event_handle.product()->empty())
138 TLOG(10) <<
"raw_event_handle labels: branchName:" << raw_event_handle.provenance()->branchName();
139 TLOG(10) <<
"raw_event_handle labels: friendlyClassName:" << raw_event_handle.provenance()->friendlyClassName();
140 TLOG(10) <<
"raw_event_handle labels: inputTag:" << raw_event_handle.provenance()->inputTag();
141 TLOG(10) <<
"raw_event_handle labels: moduleLabel:" << raw_event_handle.provenance()->moduleLabel();
142 TLOG(10) <<
"raw_event_handle labels: processName:" << raw_event_handle.provenance()->processName();
143 sequence_id = (*raw_event_handle).front().sequenceID();
145 TLOG(5) <<
"write: Writing to dataset";
146 ntuple_->insertMany(*raw_event_handle);
150 TLOG(5) <<
"write: Retrieving Event Header";
152 auto result_handles = std::vector<art::GroupQueryResult>();
153 auto const& wrapped = art::WrappedTypeID::make<artdaq::detail::RawEventHeader>();
155 ModuleContext
const mc{moduleDescription()};
156 ProcessTag
const processTag{
"", mc.moduleDescription().processName()};
158 result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
160 for (
auto const& result_handle : result_handles)
162 auto const raw_event_header_handle = RawEventHeaderHandle(result_handle);
164 if (raw_event_header_handle.isValid())
166 auto const& header = *raw_event_header_handle;
168 auto evt_sequence_id = header.sequence_id;
169 TLOG(TLVL_TRACE) <<
"HDFFileOutput::write header seq=" << evt_sequence_id;
171 ntuple_->insertHeader(header);
174 TLOG(5) <<
"HDFFileOutput::write header seq=" << evt_sequence_id <<
" done errno=" << errno;
180 TLOG(5) <<
"write: Header not found, autogenerating";
181 artdaq::detail::RawEventHeader hdr(ep.run(), ep.subRun(), ep.event(), sequence_id, 0);
182 hdr.is_complete =
true;
184 ntuple_->insertHeader(hdr);
187 fstats_.recordEvent(ep.eventID());
189 TLOG(TLVL_TRACE) <<
"End: HDFFileOUtput::write(EventPrincipal& ep)";
The HDFFileOutput module streams art Events to a binary file, bypassing ROOT.
~HDFFileOutput() override
HDFFileOutput Destructor.
HDFFileOutput(ParameterSet const &ps)
HDFFileOutput Constructor.