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 "canvas/Persistency/Common/Wrapper.h"
15 #include "canvas/Utilities/DebugMacros.h"
16 #include "canvas/Utilities/Exception.h"
17 #if ART_HEX_VERSION < 0x30901
18 #include "canvas/Utilities/WrappedTypeID.h"
20 #include "fhiclcpp/ParameterSet.h"
22 #include "artdaq/ArtModules/ArtdaqFragmentNamingService.h"
23 #include "artdaq/DAQdata/Globals.hh"
40 using fhicl::ParameterSet;
72 void beginJob()
override;
74 void endJob()
override;
76 void write(EventPrincipal& )
override;
78 void writeRun(RunPrincipal& )
override{};
79 void writeSubRun(SubRunPrincipal& )
override{};
82 std::string name_ =
"HDFFileOutput";
83 art::FileStatsCollector fstats_;
85 std::unique_ptr<artdaq::hdf5::FragmentDataset> ntuple_;
90 , fstats_{name_, processName()}
92 TLOG(TLVL_DEBUG) <<
"Begin: HDFFileOutput::HDFFileOutput(ParameterSet const& ps)\n";
94 ntuple_ = artdaq::hdf5::MakeDatasetPlugin(ps,
"dataset");
96 <<
"End: HDFFileOutput::HDFFileOutput(ParameterSet const& ps)\n";
101 void art::HDFFileOutput::beginJob()
103 TLOG(TLVL_DEBUG) <<
"Begin: HDFFileOutput::beginJob()\n";
104 TLOG(TLVL_DEBUG) <<
"End: HDFFileOutput::beginJob()\n";
107 void art::HDFFileOutput::endJob()
109 TLOG(TLVL_DEBUG) <<
"Begin: HDFFileOutput::endJob()\n";
110 TLOG(TLVL_DEBUG) <<
"End: HDFFileOutput::endJob()\n";
113 void art::HDFFileOutput::write(EventPrincipal& ep)
115 TLOG(TLVL_TRACE) <<
"Begin: HDFFileOutput::write(EventPrincipal& ep)";
116 using RawEvent = artdaq::Fragments;
117 using RawEvents = std::vector<RawEvent>;
118 using RawEventHandle = art::Handle<RawEvent>;
119 using RawEventHeaderHandle = art::Handle<artdaq::detail::RawEventHeader>;
121 auto hdr_found =
false;
122 auto sequence_id = artdaq::Fragment::InvalidSequenceID;
124 TLOG(5) <<
"write: Retrieving event Fragments";
126 auto result_handles = std::vector<art::GroupQueryResult>();
127 auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
128 ModuleContext
const mc{moduleDescription()};
129 ProcessTag
const processTag{
"", mc.moduleDescription().processName()};
131 result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
133 for (
auto const& result_handle : result_handles)
135 auto const raw_event_handle = RawEventHandle(result_handle);
137 if (raw_event_handle.isValid() && !raw_event_handle.product()->empty())
139 TLOG(10) <<
"raw_event_handle labels: branchName:" << raw_event_handle.provenance()->branchName();
140 TLOG(10) <<
"raw_event_handle labels: friendlyClassName:" << raw_event_handle.provenance()->friendlyClassName();
141 TLOG(10) <<
"raw_event_handle labels: inputTag:" << raw_event_handle.provenance()->inputTag();
142 TLOG(10) <<
"raw_event_handle labels: moduleLabel:" << raw_event_handle.provenance()->moduleLabel();
143 TLOG(10) <<
"raw_event_handle labels: processName:" << raw_event_handle.provenance()->processName();
144 sequence_id = (*raw_event_handle).front().sequenceID();
146 TLOG(5) <<
"write: Writing to dataset";
147 ntuple_->insertMany(*raw_event_handle);
151 TLOG(5) <<
"write: Retrieving Event Header";
153 auto result_handles = std::vector<art::GroupQueryResult>();
154 auto const& wrapped = art::WrappedTypeID::make<artdaq::detail::RawEventHeader>();
156 ModuleContext
const mc{moduleDescription()};
157 ProcessTag
const processTag{
"", mc.moduleDescription().processName()};
159 result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
161 for (
auto const& result_handle : result_handles)
163 auto const raw_event_header_handle = RawEventHeaderHandle(result_handle);
165 if (raw_event_header_handle.isValid())
167 auto const& header = *raw_event_header_handle;
169 auto evt_sequence_id = header.sequence_id;
170 TLOG(TLVL_TRACE) <<
"HDFFileOutput::write header seq=" << evt_sequence_id;
172 ntuple_->insertHeader(header);
175 TLOG(5) <<
"HDFFileOutput::write header seq=" << evt_sequence_id <<
" done errno=" << errno;
181 TLOG(5) <<
"write: Header not found, autogenerating";
182 artdaq::detail::RawEventHeader hdr(ep.run(), ep.subRun(), ep.event(), sequence_id, 0);
183 hdr.is_complete =
true;
185 ntuple_->insertHeader(hdr);
188 fstats_.recordEvent(ep.eventID());
190 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.