1#ifndef PODIO_TIMEDREADER_H
2#define PODIO_TIMEDREADER_H
14template <
class WrappedReader>
19 template <
typename... Args>
21 m_start(ClockT::now()),
22 m_reader(WrappedReader(std::forward<Args>(args)...)),
25 m_perEventTree(m_recorder.addTree(
27 {
"read_collections",
"read_ev_md",
"read_run_md",
"read_coll_md",
"end_of_event",
"read_event"})) {
28 m_recorder.
addTree(
"setup_times", {
"constructor",
"open_file",
"close_file",
"read_collection_ids",
"get_entries"});
29 m_recorder.
recordTime(
"setup_times",
"constructor", m_end - m_start);
36 m_recorder.
Fill(
"setup_times");
45 m_totalCollectionReadTime += duration;
76 m_perEventTree.
recordTime(
"read_collections", m_totalCollectionReadTime);
77 m_perEventTree.
Fill();
78 m_totalCollectionReadTime = std::chrono::nanoseconds{0};
83 return m_reader.isValid();
86 void openFile(
const std::string& filename)
override {
100 m_reader.goToEvent(ev);
105 return m_reader.currentFileVersion();
109 void recordTime(
bool perEvent,
const std::string& step, ClockT::duration duration)
const {
113 m_recorder.
recordTime(
"setup_times", step, duration);
117 template <
typename FuncT,
typename... Args>
118 inline std::invoke_result_t<FuncT, WrappedReader, Args...> runTimed(
bool perEvent,
const std::string& step,
119 FuncT func, Args&&... args) {
122 recordTime(perEvent, step, duration);
127 template <
typename FuncT,
typename... Args>
128 inline std::invoke_result_t<FuncT, WrappedReader, Args...> runTimed(
bool perEvent,
const std::string& step,
129 FuncT func, Args&&... args)
const {
132 recordTime(perEvent, step, duration);
137 template <
typename FuncT,
typename... Args>
138 inline void runVoidTimed(
bool perEvent,
const std::string& step, FuncT func, Args&&... args) {
141 recordTime(perEvent, step, duration);
146 ClockT::time_point m_start;
147 WrappedReader m_reader;
148 ClockT::time_point m_end;
150 benchmark::BenchmarkRecorder& m_recorder;
152 benchmark::BenchmarkRecorderTree& m_perEventTree;
153 ClockT::duration m_totalCollectionReadTime{std::chrono::nanoseconds{0}};
virtual CollectionBase * readCollection(const std::string &name)=0
virtual std::shared_ptr< CollectionIDTable > getCollectionIDTable()=0
Get CollectionIDTable of read-in data.
virtual void endOfEvent()=0
Prepare the reader to read the next event.
virtual void openFile(const std::string &filename)=0
virtual std::map< int, GenericParameters > * readRunMetaData()=0
virtual GenericParameters * readEventMetaData()=0
read event meta data from file
virtual unsigned getEntries() const =0
get the number of events available from this reader
virtual void closeFile()=0
virtual void readEvent()=0
virtual std::map< int, GenericParameters > * readCollectionMetaData()=0
bool isValid() const override
Check if reader is valid.
void closeFile() override
std::map< int, GenericParameters > * readRunMetaData() override
void endOfEvent() override
Prepare the reader to read the next event.
std::map< int, GenericParameters > * readCollectionMetaData() override
podio::version::Version currentFileVersion() const override
Get the podio version with which the current file has been written.
CollectionBase * readCollection(const std::string &name) override
unsigned getEntries() const override
get the number of events available from this reader
void goToEvent(unsigned ev) override
TimedReader(benchmark::BenchmarkRecorder &recorder, Args &&... args)
void openFile(const std::string &filename) override
void readEvent() override
GenericParameters * readEventMetaData() override
read event meta data from file
std::shared_ptr< CollectionIDTable > getCollectionIDTable() override
Get CollectionIDTable of read-in data.
void recordTime(const std::string &stepName, const ClockT::duration time)
BenchmarkRecorderTree & addTree(const std::string &name, const std::vector< std::string > &steps)
void Fill(const std::string &treeName)
void recordTime(const std::string &treeName, const std::string &stepName, const ClockT::duration time)
ClockT::duration run_void_member_timed(Obj &obj, MemberFunc func, Args &&... args)
std::chrono::high_resolution_clock ClockT
std::pair< std::invoke_result_t< MemberFunc, Obj, Args... >, ClockT::duration > run_member_timed(Obj &obj, MemberFunc func, Args &&... args)