1 #ifndef dune_ArtModules_PdspHDFFileReader_hh 2 #define dune_ArtModules_PdspHDFFileReader_hh 4 #include "artdaq-core/Data/ContainerFragment.hh" 5 #include "artdaq-core/Data/Fragment.hh" 6 #include "artdaq-core/Data/RawEvent.hh" 7 #include "artdaq-core/Utilities/ExceptionHandler.hh" 8 #include "artdaq-core/Utilities/TimeUtils.hh" 53 std::unique_ptr<dune::HDFFileReader::HDFFileInfo>
hdf_file_;
72 , pretend_module_name(ps.
get<
std::
string>(
"raw_data_label",
"daq"))
76 TLOG_INFO(
"PdspHDFFileReader") <<
"PdspHDFFileReader initializing with ParameterSet: " << ps.
to_string();
78 std::set<std::string> instance_names = {
"FELIX",
"PHOTON"};
79 for (
const auto& set_iter : instance_names)
86 TLOG_INFO(
"PdspHDFFileReader") <<
"PdspHDFFileReader opened HDF file with run number " << hdf_file_->runNumber
87 <<
" and " << unprocessedEventList_.size() <<
" events";
109 TLOG_ARB(5,
"PdspHDFFileReader") <<
"readFile enter/start";
126 TLOG_DEBUG(
"PdspHDFFileReader") <<
"readNext BEGIN";
134 if (unprocessedEventList_.empty()) {
return false;}
136 std::string nextEventGroupName = unprocessedEventList_.front();
137 unprocessedEventList_.pop_front();
144 if (fragmentMap.size() == 0)
146 TLOG_ERROR(
"PdspHDFFileReader") <<
"No data received, either because of a problem or end of file. Returning false (should exit art)";
150 artdaq::detail::RawEventHeader evtHeader(hdf_file_->
runNumber, 1, readNext_calls_, readNext_calls_, 0);
152 for (
auto& subDetName_fragmentList_pair : fragmentMap)
154 for (
auto& frag : *subDetName_fragmentList_pair.second)
156 TLOG_DEBUG(
"PdspHDFFileReader") << subDetName_fragmentList_pair.first <<
" Fragment, " <<
" type " 157 << ((
int) frag.type()) <<
", timestamp " << frag.timestamp()
158 <<
", sequence_id " << frag.sequenceID()
159 <<
" fragment_id " << frag.fragmentID();
160 evtHeader.event_id = frag.sequenceID();
161 evtHeader.sequence_id = frag.sequenceID();
162 evtHeader.timestamp = frag.timestamp();
167 timespec hi_res_time;
168 int retcode = clock_gettime(CLOCK_REALTIME, &hi_res_time);
169 TLOG_ARB(15,
"PdspHDFFileReader") <<
"hi_res_time tv_sec = " << hi_res_time.tv_sec
170 <<
" tv_nsec = " << hi_res_time.tv_nsec <<
" (retcode = " << retcode <<
")";
173 currentTime = ((hi_res_time.tv_sec & 0xffffffff) << 32) | (hi_res_time.tv_nsec & 0xffffffff);
177 TLOG_ERROR(
"PdspHDFFileReader")
178 <<
"Unable to fetch a high-resolution time with clock_gettime for art::Event Timestamp. " 179 <<
"The art::Event Timestamp will be zero for event " << evtHeader.event_id;
183 if (inR == 0 || inR->
run() != evtHeader.run_id)
189 art::SubRunID subrun_check(evtHeader.run_id, evtHeader.subrun_id);
190 if (inSR == 0 || subrun_check != inSR->
subRunID())
195 outE = pmaker.
makeEventPrincipal(evtHeader.run_id, evtHeader.subrun_id, evtHeader.event_id, currentTime);
197 for (
auto& subDetName_fragmentList_pair : fragmentMap)
200 subDetName_fragmentList_pair.first);
207 TLOG_TRACE(
"PdspHDFFileReader") <<
"EventHeader has Run " << evtHeader.run_id <<
", SubRun " << evtHeader.subrun_id <<
", Event " << evtHeader.event_id <<
", SeqID " << evtHeader.sequence_id <<
", IsComplete " << evtHeader.is_complete;
211 for (
auto& fragmentTypePair : eventMap)
213 auto type_code = fragmentTypePair.first;
214 TLOG_TRACE(
"PdspHDFFileReader") <<
"Before GetFragmentsByType call, type is " << (
int)type_code;
215 TLOG_TRACE(
"PdspHDFFileReader") <<
"After GetFragmentsByType call, number of fragments is " << fragmentTypePair.second->size();
217 std::unordered_map<std::string, std::unique_ptr<artdaq::Fragments>> derived_fragments;
218 for (
auto& frag : *fragmentTypePair.second)
220 bytesRead += frag.sizeBytes();
224 if (!instance_name_result.first)
226 TLOG_WARNING(
"PdspHDFFileReader")
227 <<
"UnknownFragmentType: The product instance name mapping for fragment type \"" << ((
int)type_code)
228 <<
"\" is not known. Fragments of this " 229 <<
"type will be stored in the event with an instance name of \"" << label <<
"\".";
231 if (!derived_fragments.count(label))
233 derived_fragments[
label] = std::make_unique<Fragments>();
235 auto fragSize = frag.size();
236 TLOG_TRACE(
"PdspHDFFileReader") <<
"Moving Fragment with size " << fragSize <<
" from type map (type=" << type_code <<
") to derived map label=" <<
label;
239 TLOG_TRACE(
"PdspHDFFileReader") <<
"Placing derived fragments in outE";
240 for (
auto&
type : derived_fragments)
246 TLOG_TRACE(
"PdspHDFFileReader") <<
"After putting fragments in event";
247 TLOG_ARB(10,
"PdspHDFFileReader") <<
"readNext: bytesRead=" <<
bytesRead;;
249 TLOG_TRACE(
"PdspHDFFileReader") <<
"Returning from readNext";
HDFFileInfoPtr reopenFile(HDFFileInfoPtr oldHdfFileInfoPtr)
The PdspHDFFileReader is a class which implements the methods needed by art::Source.
HDFFileInfoPtr openFile(const std::string &fileName)
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
bool readNext(art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
Dequeue a RawEvent and declare its Fragment contents to art, creating Run, SubRun, and EventPrincipal objects as necessary.
std::string pretend_module_name
The module name to store data under.
std::list< std::string > getTopLevelGroupNames(HDFFileInfoPtr &hdfFileInfoPtr)
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
art::SourceHelper const & pmaker
An art::SourceHelper instance.
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
void closeCurrentFile()
Emulate closing a file. No-Op.
PdspHDFFileReader(PdspHDFFileReader const &)=delete
Copy Constructor is deleted.
T get(std::string const &key) const
SubRunID subRunID() const
std::list< std::string > unprocessedEventList_
size_t bytesRead
running total of number of bytes received
static constexpr double ps
FragmentListsByType getFragmentsForEvent(HDFFileInfoPtr &hdfFileInfoPtr, const std::string &topLevelGroupName)
virtual ~PdspHDFFileReader()
PdspHDFFileReader destructor.
std::unique_ptr< dune::HDFFileReader::HDFFileInfo > hdf_file_
std::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
std::map< std::string, std::unique_ptr< artdaq::Fragments > > FragmentListsByType
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
PdspHDFFileReader(fhicl::ParameterSet const &ps, art::ProductRegistryHelper &help, art::SourceHelper const &pm)
PdspHDFFileReader Constructor.
auto const & get(AssnsNode< L, R, D > const &r)
void readFile(std::string const &, art::FileBlock *&fb)
Emulate opening a file.
unsigned readNext_calls_
The number of times readNext has been called.
void closeFile(HDFFileInfoPtr hdfFileInfoPtr)
std::vector< Fragment > Fragments
std::string to_string() const
PdspHDFFileReader & operator=(PdspHDFFileReader const &)=delete
Copy Assignment operator is deleted.