101 auto const excess = value % period;
102 auto const base = value - excess;
103 return (excess < (period /
T(2)))?
base:
base + period;
109 template <
typename Clock,
typename Unit>
129 template <
typename TimeInterval>
133 (std::chrono::duration_cast<Unit>(dt).count());
137 template <
typename Rep,
typename Period>
139 {
return toDuration(std::chrono::duration<Rep, Period>(1)); }
142 template <
typename TimePo
int>
144 {
return toDuration(t.time_since_epoch()); }
149 template <
typename Clock,
typename Duration>
166 using clock_t = Clock;
167 using system_clock_t = std::chrono::system_clock;
171 if (std::is_same<clock_t, system_clock_t>()) {
173 <<
"Using system clock for timestamp: no offset needed.";
184 (timeFromEpoch(sys_clock_time) - timeFromEpoch(clock_time))
189 <<
"Offset with system clock is small (" 190 << (timeFromEpoch(sys_clock_time) - timeFromEpoch(clock_time))
191 <<
", " << timeFromEpoch(sys_clock_time)
192 <<
" vs. " << timeFromEpoch(clock_time)
193 <<
"): no offset needed." 201 using clock_period_t =
typename clock_t::period;
202 using system_clock_period_t = system_clock_t::period;
203 using largest_period_t = std::conditional_t<
209 system_clock_period_t
212 constexpr
auto largest_period
213 = periodToDuration<typename clock_t::rep, largest_period_t>();
218 constexpr
unsigned int times = 10U;
220 for (
unsigned int i = 0; i < times; ++i) {
223 (timeFromEpoch(sys_clock_time) - timeFromEpoch(clock_time));
230 <<
"System clock period: " 231 << periodToDuration<typename clock_t::rep, system_clock_period_t>()
232 <<
"\nUser clock period: " 233 << periodToDuration<typename clock_t::rep, clock_period_t>()
234 <<
"\nOffset: " << offset.
average()
235 <<
" (rounded to: " << largest_period <<
")" 247 template <
typename Clock,
typename Duration,
typename =
void>
252 template <
typename Clock,
typename Duration>
254 (Clock::period::num * Duration::period::den > Duration::period::num * Clock::period::den)
270 static constexpr
intmax_t paddingfactor
278 {
return Base_t::read_clock() + flat(engine); }
282 std::uniform_int_distribution<duration_t>
flat;
303 <<
"Timestamp plugin: timestamp from local clock time in nanoseconds";
327 <<
"Generated time stamp: " << ts.
value() <<
" for event " << id;
std::ratio< ClockPeriod::num *ReqPeriod::den, ReqPeriod::num *ClockPeriod::den > PeriodRatio
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
virtual void rewind() override
Resets the status; since this plug in is stateless, this is a no-op.
auto discretize(T value, T period)
Returns the multiple of period closest to value.
Plugin to assign an empty event a time stamp from the clock.
static constexpr auto periodToDuration()
Returns the duration (duration_t) of a period type.
void insert(data_t value)
constexpr TimeValue_t value() const
Class reading a Clock and converting the value to a specific Unit.
static duration_t read_clock()
Reads and returns the current time the clock.
typename Duration::period ReqPeriod
GeneratedEventTimestamp(fhicl::ParameterSet const &pset)
Constructor: nothing specific.
std::uniform_int_distribution< duration_t > flat
art::TimeValue_t const fOffsetFromEpoch
Offset to be added to the chosen clock to get an absolute time.
#define DEFINE_ART_EMPTYEVENTTIMESTAMP_PLUGIN(klass)
static constexpr duration_t toDuration(TimeInterval dt)
Converts a std::chrono::duration into our duration metric.
std::uint64_t TimeValue_t
const GenericPointer< typename T::ValueType > T2 value
virtual art::Timestamp eventTimestamp(art::EventID const &id) override
Returns the time stamp for the specified event.
art::TimeValue_t duration_t
Type of the time duration as returned by this class.
art::TimeValue_t duration_t
Type of the time duration as returned by this class.
typename Clock::period ClockPeriod
MaybeLogger_< ELseverityLevel::ELsev_success, true > LogTrace
std::default_random_engine engine
static duration_t currentOffsetFromEpoch()
Event Generation using GENIE, cosmics or single particles.
static duration_t timeFromEpoch(TimePoint t)
Returns the time elapsed from the epoch to t.
nanosecond nanoseconds
Alias for common language habits.