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 {
14namespace utilities {
15
27TimestampEstimatorBase::wait_for_valid_timestamp(std::atomic<bool>& continue_flag)
28{
29 auto sleep_time = std::chrono::microseconds(1);
30 while (continue_flag.load() && get_timestamp_estimate() == std::numeric_limits<uint64_t>::max()) {
31 std::this_thread::sleep_for(sleep_time);
32 if (sleep_time < std::chrono::milliseconds(10)) {
33 sleep_time *= 2;
34 }
35 }
36
37 // 27-May-2025, KAB: modified this return statement so that the return code is based on whether a
38 // valid timestamp is available (instead of whether the caller asked the method to wait or not)
39 return (get_timestamp_estimate() != std::numeric_limits<uint64_t>::max()) ? TimestampEstimatorBase::kFinished : TimestampEstimatorBase::kInterrupted;
40}
41
43TimestampEstimatorBase::wait_for_timestamp(uint64_t ts, std::atomic<bool>& continue_flag)
44{
45 auto get_sleep_time = [this, ts]() {
46 auto est = get_wait_estimate(ts);
47 auto pest = static_cast<long>(est.count() * 0.8);
48 if (pest < 1 && est != std::chrono::microseconds(0))
49 return std::chrono::microseconds(1);
50 return std::chrono::microseconds(pest);
51 };
52 auto sleep_time = get_sleep_time();
53 while (continue_flag.load() &&
54 (get_timestamp_estimate() < ts || get_timestamp_estimate() == std::numeric_limits<uint64_t>::max())) {
55 std::this_thread::sleep_for(sleep_time);
56 sleep_time = get_sleep_time();
57 }
58
60}
61
62} // namespace utilities
63} // namespace dunedaq
WaitStatus wait_for_valid_timestamp(std::atomic< bool > &continue_flag)
Waits for a valid timestamp to become available. Returns a status value that indicates whether a vali...
WaitStatus wait_for_timestamp(uint64_t ts, 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
Including Qt Headers.
PDS Frame with unphysical timestamp detected with ts