DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::utilities::TimestampEstimatorBase Class Referenceabstract

TimestampEstimatorBase is the base class for timestamp-based logic in test systems where the current timestamp must be estimated somehow (eg, because there is no hardware timing system). More...

#include <TimestampEstimatorBase.hpp>

Inheritance diagram for dunedaq::utilities::TimestampEstimatorBase:
[legend]

Public Types

enum  WaitStatus { kFinished , kInterrupted }
 

Public Member Functions

virtual ~TimestampEstimatorBase ()=default
 
virtual uint64_t get_timestamp_estimate () const =0
 
virtual std::chrono::microseconds get_wait_estimate (uint64_t ts) const =0
 
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 valid timestamp is available or not.
 
WaitStatus wait_for_timestamp (uint64_t ts, std::atomic< bool > &continue_flag)
 

Detailed Description

TimestampEstimatorBase is the base class for timestamp-based logic in test systems where the current timestamp must be estimated somehow (eg, because there is no hardware timing system).

Definition at line 23 of file TimestampEstimatorBase.hpp.

Member Enumeration Documentation

◆ WaitStatus

Constructor & Destructor Documentation

◆ ~TimestampEstimatorBase()

virtual dunedaq::utilities::TimestampEstimatorBase::~TimestampEstimatorBase ( )
virtualdefault

Member Function Documentation

◆ get_timestamp_estimate()

virtual uint64_t dunedaq::utilities::TimestampEstimatorBase::get_timestamp_estimate ( ) const
pure virtual

◆ get_wait_estimate()

virtual std::chrono::microseconds dunedaq::utilities::TimestampEstimatorBase::get_wait_estimate ( uint64_t ts) const
pure virtual

◆ wait_for_timestamp()

TimestampEstimatorBase::WaitStatus dunedaq::utilities::TimestampEstimatorBase::wait_for_timestamp ( uint64_t ts,
std::atomic< bool > & continue_flag )

Wait for the current timestamp estimate to reach ts, or for continue_flag to become false.

Returns kFinished if the timestamp became valid, or kInterrupted if continue_flag became false first

Definition at line 43 of file TimestampEstimatorBase.cpp.

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}
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

◆ wait_for_valid_timestamp()

TimestampEstimatorBase::WaitStatus dunedaq::utilities::TimestampEstimatorBase::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 valid timestamp is available or not.

Wait for the current timestamp estimate to become valid, or for continue_flag to become false. The timestamp becomes valid once at least one TimeSync message has been received.

Returns kFinished if the timestamp became valid, or kInterrupted if continue_flag became false first

Parameters
continue_flagwhether to continue waiting until a valid timestamp is available or return immediately

The value of the continue_flag can be changed from true to false externally to this method, and that will cause the method to exit soon thereafter (on the order of 10 msec) and return the current status.

Returns
kFinished if a valid timestamp is available or kInterrupted if one is not

Definition at line 27 of file TimestampEstimatorBase.cpp.

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}

The documentation for this class was generated from the following files: