PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
TimedWriter.h
Go to the documentation of this file.
1#ifndef PODIO_TIMEDWRITER_H
2#define PODIO_TIMEDWRITER_H
3
7
8#include <chrono>
9#include <string>
10
11namespace podio {
12
13template <class WrappedWriter>
15 using ClockT = benchmark::ClockT;
16
17public:
18 template <typename... Args>
19 TimedWriter(benchmark::BenchmarkRecorder& recorder, Args&&... args) :
20 m_start(ClockT::now()),
21 m_writer(WrappedWriter(std::forward<Args>(args)...)),
22 m_end(ClockT::now()),
23 m_recorder(recorder),
24 m_perEventTree(m_recorder.addTree("event_times", {"write_event"})) {
25 m_recorder.addTree("setup_times", {"constructor", "finish", "register_for_write"});
26 m_recorder.recordTime("setup_times", "constructor", m_end - m_start);
27 }
28
30 m_recorder.recordTime("setup_times", "register_for_write", m_registerTime);
31 m_recorder.Fill("setup_times");
32 }
33
34 void registerForWrite(const std::string& name) {
35 // summing up the times it takes for all the collections to be registered
36 // here, since we do not know in advance how many collections there will be
37 // in the end
38 const auto duration = benchmark::run_void_member_timed(m_writer, &WrappedWriter::registerForWrite, name);
39 m_registerTime += duration;
40 }
41
42 void writeEvent() {
43 m_perEventTree.recordTime("write_event", benchmark::run_void_member_timed(m_writer, &WrappedWriter::writeEvent));
44 m_perEventTree.Fill();
45 }
46
47 void finish() {
48 m_recorder.recordTime("setup_times", "finish", benchmark::run_void_member_timed(m_writer, &WrappedWriter::finish));
49 }
50
51private:
52 ClockT::time_point m_start;
53 WrappedWriter m_writer;
54 ClockT::time_point m_end;
57 ClockT::duration m_registerTime{std::chrono::nanoseconds{0}};
58};
59
60} // namespace podio
61
62#endif
#define DEPR_EVTSTORE
Definition: Deprecated.h:4
void registerForWrite(const std::string &name)
Definition: TimedWriter.h:34
TimedWriter(benchmark::BenchmarkRecorder &recorder, Args &&... args)
Definition: TimedWriter.h:19
std::chrono::high_resolution_clock ClockT
Definition: BenchmarkUtil.h:9