LCOV - code coverage report
Current view: top level - artdaq/DAQrate - StatisticsHelper.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 80.4 % 51 41
Test Date: 2025-09-04 00:45:34 Functions: 85.7 % 7 6

            Line data    Source code
       1              : #include "artdaq/DAQrate/StatisticsHelper.hh"
       2              : 
       3              : #include "fhiclcpp/ParameterSet.h"
       4              : 
       5              : // This class is really nothing more than a collection of code that
       6              : // would be repeated throughout artdaq "application" classes if it
       7              : // weren't centralized here.  So, we should be careful not to put
       8              : // too much intelligence in this class.  (KAB, 07-Jan-2015)
       9              : 
      10           15 : artdaq::StatisticsHelper::
      11           15 :     StatisticsHelper()
      12           15 :     : monitored_quantity_name_list_(0)
      13           30 :     , primary_stat_ptr_(nullptr) {}
      14              : 
      15           30 : void artdaq::StatisticsHelper::
      16              :     addMonitoredQuantityName(std::string const& statKey)
      17              : {
      18           30 :         monitored_quantity_name_list_.push_back(statKey);
      19           30 : }
      20              : 
      21         2533 : void artdaq::StatisticsHelper::addSample(std::string const& statKey,
      22              :                                          double value) const
      23              : {
      24              :         artdaq::MonitoredQuantityPtr mqPtr =
      25         2533 :             artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(statKey);
      26         2533 :         if (mqPtr.get() != nullptr) { mqPtr->addSample(value); }
      27         2533 : }
      28              : 
      29           15 : bool artdaq::StatisticsHelper::
      30              :     createCollectors(fhicl::ParameterSet const& pset, int defaultReportIntervalFragments,
      31              :                      double defaultReportIntervalSeconds, double defaultMonitorWindow,
      32              :                      std::string const& primaryStatKeyName)
      33              : {
      34           15 :         reporting_interval_fragments_ =
      35           30 :             pset.get<int>("reporting_interval_fragments", defaultReportIntervalFragments);
      36           15 :         reporting_interval_seconds_ =
      37           30 :             pset.get<double>("reporting_interval_seconds", defaultReportIntervalSeconds);
      38              : 
      39           15 :         auto monitorWindow = pset.get<double>("monitor_window", defaultMonitorWindow);
      40              :         auto monitorBinSize =
      41           15 :             pset.get<double>("monitor_binsize",
      42           15 :                              1.0 + static_cast<int>((monitorWindow - 1) / 100.0));
      43              : 
      44           15 :         if (monitorBinSize < 1.0) { monitorBinSize = 1.0; }
      45           15 :         if (monitorWindow >= 1.0)
      46              :         {
      47           45 :                 for (const auto& idx : monitored_quantity_name_list_)
      48              :                 {
      49              :                         artdaq::MonitoredQuantityPtr
      50              :                             mqPtr(new artdaq::MonitoredQuantity(monitorBinSize,
      51           30 :                                                                 monitorWindow));
      52           30 :                         artdaq::StatisticsCollection::getInstance().addMonitoredQuantity(idx, mqPtr);
      53           30 :                 }
      54              :         }
      55              : 
      56           15 :         primary_stat_ptr_ = artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(primaryStatKeyName);
      57           15 :         return (primary_stat_ptr_.get() != nullptr);
      58              : }
      59              : 
      60           17 : void artdaq::StatisticsHelper::resetStatistics()
      61              : {
      62           17 :         previous_reporting_index_ = 0;
      63           17 :         previous_stats_calc_time_ = 0.0;
      64           51 :         for (const auto& idx : monitored_quantity_name_list_)
      65              :         {
      66           34 :                 artdaq::MonitoredQuantityPtr mqPtr = artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(idx);
      67           34 :                 if (mqPtr.get() != nullptr) { mqPtr->reset(); }
      68           34 :         }
      69           17 : }
      70              : 
      71         1578 : bool artdaq::StatisticsHelper::
      72              :     readyToReport()
      73              : {
      74         1578 :         if (primary_stat_ptr_.get() != nullptr)
      75              :         {
      76         1578 :                 double fullDuration = primary_stat_ptr_->getFullDuration();
      77         1578 :                 auto reportIndex = static_cast<size_t>(fullDuration / reporting_interval_seconds_);
      78         1578 :                 if (reportIndex > previous_reporting_index_)
      79              :                 {
      80            0 :                         previous_reporting_index_ = reportIndex;
      81            0 :                         return true;
      82              :                 }
      83              :         }
      84              : 
      85         1578 :         return false;
      86              : }
      87              : 
      88            0 : bool artdaq::StatisticsHelper::statsRollingWindowHasMoved()
      89              : {
      90            0 :         if (primary_stat_ptr_.get() != nullptr)
      91              :         {
      92            0 :                 auto lastCalcTime = primary_stat_ptr_->getLastCalculationTime();
      93            0 :                 if (lastCalcTime > previous_stats_calc_time_)
      94              :                 {
      95            0 :                         auto now = MonitoredQuantity::getCurrentTime();
      96            0 :                         previous_stats_calc_time_ = std::min(lastCalcTime, now);
      97            0 :                         return true;
      98              :                 }
      99              :         }
     100              : 
     101            0 :         return false;
     102              : }
        

Generated by: LCOV version 2.0-1