LCOV - code coverage report
Current view: top level - utilities/src - TimestampEstimatorSystem.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 19 19
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /**
       2              :  * @file TimestampEstimatorSystem.cpp
       3              :  *
       4              :  * This is part of the DUNE DAQ Software Suite, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "utilities/TimestampEstimatorSystem.hpp"
      10              : 
      11              : #include "logging/Logging.hpp"
      12              : 
      13              : #include <chrono>
      14              : 
      15              : namespace dunedaq::utilities {
      16              : 
      17            2 : TimestampEstimatorSystem::TimestampEstimatorSystem(uint64_t clock_frequency_hz) // NOLINT(build/unsigned)
      18            2 :   : m_clock_frequency_hz(clock_frequency_hz)
      19              : {
      20            2 :   TLOG_DEBUG(0) << "Clock frequency is " << m_clock_frequency_hz
      21            2 :                 << " clock_frequency_hz/1000000.=" << (static_cast<double>(m_clock_frequency_hz) / 1000000.);
      22            2 : }
      23              : 
      24              : uint64_t // NOLINT(build/unsigned)
      25           28 : TimestampEstimatorSystem::get_timestamp_estimate() const
      26              : {
      27           28 :   auto now = std::chrono::system_clock::now().time_since_epoch();
      28           28 :   auto now_us = std::chrono::duration_cast<std::chrono::microseconds>(now);
      29           28 :   return static_cast<uint64_t>((static_cast<double>(m_clock_frequency_hz) / 1000000.) * // NOLINT
      30           28 :                                static_cast<double>(now_us.count()));
      31              : }
      32              : 
      33              : std::chrono::microseconds
      34            8 : TimestampEstimatorSystem::get_wait_estimate(uint64_t ts) const // NOLINT(build/unsigned)
      35              : {
      36            8 :   auto now = std::chrono::system_clock::now().time_since_epoch();
      37            8 :   auto now_us = std::chrono::duration_cast<std::chrono::microseconds>(now);
      38            8 :   auto then = static_cast<std::chrono::microseconds::rep>(static_cast<double>(ts) * 1000000. /
      39            8 :                                                           static_cast<double>(m_clock_frequency_hz));
      40            8 :   auto then_us = std::chrono::microseconds(then);
      41            8 :   if (then_us < now_us)
      42            1 :     return std::chrono::microseconds(0);
      43            7 :   return then_us - now_us;
      44              : }
      45              : 
      46              : } // namespace dunedaq::utilities
        

Generated by: LCOV version 2.0-1