DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TimestampEstimatorBase.cpp
Go to the documentation of this file.
1
10
11#include <thread>
12
13namespace dunedaq::utilities {
14
27TimestampEstimatorBase::wait_for_valid_timestamp(std::atomic<bool>& continue_flag, uint64_t& last_seen_ts) // NOLINT
28{
29 last_seen_ts = s_invalid_ts;
30 auto sleep_time = std::chrono::microseconds(1);
31 // Always call get_timestamp_estimate at least once
32 while ((last_seen_ts = get_timestamp_estimate()) == s_invalid_ts && continue_flag.load()) {
33 std::this_thread::sleep_for(sleep_time);
34 if (sleep_time < std::chrono::milliseconds(10)) {
35 sleep_time *= 2;
36 }
37 }
38
39 // 27-May-2025, KAB: modified this return statement so that the return code is based on whether a
40 // valid timestamp is available (instead of whether the caller asked the method to wait or not)
42}
43
46 std::atomic<bool>& continue_flag,
47 uint64_t& last_seen_ts) // NOLINT(build/unsigned)
48{
49 last_seen_ts = s_invalid_ts;
50 auto get_sleep_time = [this, ts]() {
51 auto est = get_wait_estimate(ts);
52 auto pest = static_cast<std::chrono::microseconds::rep>(static_cast<double>(est.count()) * 0.8);
53 if (pest < 1 && est != std::chrono::microseconds(0))
54 return std::chrono::microseconds(1);
55 return std::chrono::microseconds(pest);
56 };
57 auto sleep_time = get_sleep_time();
58 // Always call get_timestamp_estimate at least once
59 while (((last_seen_ts = get_timestamp_estimate()) < ts || last_seen_ts == s_invalid_ts) && continue_flag.load()) {
60 std::this_thread::sleep_for(sleep_time);
61 sleep_time = get_sleep_time();
62 }
63 return (last_seen_ts >= ts && last_seen_ts != s_invalid_ts) ? TimestampEstimatorBase::kFinished
65}
66
67} // namespace dunedaq::utilities
WaitStatus wait_for_requested_timestamp(uint64_t ts, std::atomic< bool > &continue_flag)
WaitStatus wait_for_valid_timestamp(std::atomic< bool > &continue_flag)
virtual std::chrono::microseconds get_wait_estimate(uint64_t ts) const =0
virtual uint64_t get_timestamp_estimate() const =0
PDS Frame with unphysical timestamp detected with ts