1 #include "artdaq/DAQrate/StatisticsHelper.hh"
10 : monitored_quantity_name_list_(0)
11 , primary_stat_ptr_(0)
12 , previous_reporting_index_(0)
13 , previous_stats_calc_time_(0.0) {}
18 monitored_quantity_name_list_.push_back(statKey);
24 artdaq::MonitoredQuantityPtr mqPtr =
25 artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(statKey);
26 if (mqPtr.get() != 0) { mqPtr->addSample(value); }
31 double defaultReportIntervalSeconds,
double defaultMonitorWindow,
32 std::string
const& primaryStatKeyName)
34 reporting_interval_fragments_ =
35 pset.get<
int>(
"reporting_interval_fragments", defaultReportIntervalFragments);
36 reporting_interval_seconds_ =
37 pset.get<
double>(
"reporting_interval_seconds", defaultReportIntervalSeconds);
39 double monitorWindow = pset.get<
double>(
"monitor_window", defaultMonitorWindow);
40 double monitorBinSize =
41 pset.get<
double>(
"monitor_binsize",
42 1.0 +
static_cast<int>((monitorWindow - 1) / 100.0));
44 if (monitorBinSize < 1.0) { monitorBinSize = 1.0; }
45 if (monitorWindow >= 1.0)
47 for (
size_t idx = 0; idx < monitored_quantity_name_list_.size(); ++idx)
49 artdaq::MonitoredQuantityPtr
50 mqPtr(
new artdaq::MonitoredQuantity(monitorBinSize,
52 artdaq::StatisticsCollection::getInstance().addMonitoredQuantity(monitored_quantity_name_list_[idx], mqPtr);
56 primary_stat_ptr_ = artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(primaryStatKeyName);
57 return (primary_stat_ptr_.get() != 0);
62 previous_reporting_index_ = 0;
63 previous_stats_calc_time_ = 0.0;
64 for (
size_t idx = 0; idx < monitored_quantity_name_list_.size(); ++idx)
66 artdaq::MonitoredQuantityPtr mqPtr = artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(monitored_quantity_name_list_[idx]);
67 if (mqPtr.get() !=
nullptr) { mqPtr->reset(); }
74 if (primary_stat_ptr_.get() != 0)
76 double fullDuration = primary_stat_ptr_->getFullDuration();
77 size_t reportIndex = (size_t)(fullDuration / reporting_interval_seconds_);
78 if (reportIndex > previous_reporting_index_)
80 previous_reporting_index_ = reportIndex;
90 if (primary_stat_ptr_.get() != 0)
92 auto lastCalcTime = primary_stat_ptr_->getLastCalculationTime();
93 if (lastCalcTime > previous_stats_calc_time_)
95 auto now = MonitoredQuantity::getCurrentTime();
96 previous_stats_calc_time_ = std::min(lastCalcTime, now);
void addMonitoredQuantityName(std::string const &statKey)
Add a MonitoredQuantity name to the list.
bool statsRollingWindowHasMoved()
Determine if the MonitoredQuantity "recent" window has changed since the last time this function was ...
void addSample(std::string const &statKey, double value) const
Add a sample to the MonitoredQuantity with the given name.
bool createCollectors(fhicl::ParameterSet const &pset, int defaultReportIntervalFragments, double defaultReportIntervalSeconds, double defaultMonitorWindow, std::string const &primaryStatKeyName)
Create MonitoredQuantity objects for all names registered with the StatisticsHelper.
StatisticsHelper()
StatisticsHelper default constructor.
void resetStatistics()
Reset all MonitoredQuantity instances.
bool readyToReport()
Determine if the reporting interval condition has been met.