1 #ifndef artdaq_core_Core_MonitoredQuantity_hh
2 #define artdaq_core_Core_MonitoredQuantity_hh
4 #include "boost/thread/mutex.hpp"
132 return v ? 1e6 / v : INFINITY;
177 void addSample(
const double value = 1.0);
189 void addSample(
const uint32_t value = 1);
195 void addSample(
const uint64_t value = 1);
252 return _intervalForRecentStats;
261 return _expectedCalculationInterval;
303 void _reset_accumulators();
305 void _reset_results();
308 long long _workingSampleCount;
309 double _workingValueSum;
310 double _workingValueSumOfSquares;
311 double _workingValueMin;
312 double _workingValueMax;
313 double _workingLastSampleValue;
315 mutable boost::mutex _accumulationMutex;
317 unsigned int _binCount;
318 unsigned int _workingBinId;
319 std::vector<double> _binValueSumOfSquares;
320 std::vector<double> _binValueMin;
321 std::vector<double> _binValueMax;
323 mutable boost::mutex _resultsMutex;
326 const DURATION_T _expectedCalculationInterval;
double getSampleRate(DataSetType t=DataSetType::FULL) const
Returns the sample rate in the requested interval.
long long getSampleCount(DataSetType t=DataSetType::FULL) const
Returns the sample count for the requested interval.
DataSetType
Which data points to return (all or only recent)
double getLastSampleValue() const
Accessor for the last sample value recorded.
bool enabled
Whether the MonitoredQuantity is collecting data.
double getValueRMS(DataSetType t=DataSetType::FULL) const
Returns the RMS of the values in the requested interval.
bool calculateStatistics(TIME_POINT_T currentTime=getCurrentTime())
Forces a calculation of the statistics for the monitored quantity.
std::vector< double > recentBinnedValueSums
Sums for each instance of calculateStatistics in _intervalForRecentStats (rolling window) ...
long long getFullSampleCount() const
Access the count of samples for the entire history of the MonitoredQuantity.
double recentValueAverage
The average of the "recent" samples.
struct containing MonitoredQuantity data
double fullValueMax
The largest value of all sampels.
double getLastValueRate() const
Accessor for the lastValueRate (Sum of last samples over interval between calculateStatisics calls) ...
double recentValueMax
The largest value of the "recent" samples.
double lastSampleValue
Value of the most recent sample.
double getValueRate(DataSetType t=DataSetType::FULL) const
Returns the sum of the values in the requested interval, divided by the duration of the requested int...
double getValueAverage(DataSetType t=DataSetType::FULL) const
Returns the average of the values in the requested interval.
This class keeps track of statistics for a set of sample values and provides timing information on th...
bool isEnabled() const
Tests whether the monitor is currently enabled.
double getValueMin(DataSetType t=DataSetType::FULL) const
Returns the smallest of the values in the requested interval.
static TIME_POINT_T getCurrentTime()
Returns the current point in time.
double recentSampleRate
The number of samples in the "recent" time window, divided by the length of that window.
double fullValueAverage
The average of all samples.
double getValueMax(DataSetType t=DataSetType::FULL) const
Returns the largest of the values in the requested interval.
long long recentSampleCount
The number of samples in the "recent" time window.
DURATION_T getDuration(DataSetType t=DataSetType::FULL) const
Returns the duration of the requested interval.
double fullValueSumOfSquares
The sum of the squares of all samples.
std::vector< TIME_POINT_T > recentBinnedEndTimes
Last sample time in each instance of calculateStatistics in _intervalForRecentStats (rolling window) ...
MonitoredQuantity(DURATION_T expectedCalculationInterval, DURATION_T timeWindowForRecentResults)
Instantiates a MonitoredQuantity object.
DURATION_T fullDuration
The full duration of sampling.
DURATION_T ExpectedCalculationInterval() const
Returns the expected interval between calculateStatistics calls.
bool waitUntilAccumulatorsHaveBeenFlushed(DURATION_T timeout) const
Blocks while the MonitoredQuantity is flushed, up to timeout duration.
long long fullSampleCount
The total number of samples represented.
double DURATION_T
A Duration.
DURATION_T recentDuration
The length of the "recent" time window.
void addSample(const double value=1.0)
Adds the specified doubled valued sample value to the monitor instance.
double TIME_POINT_T
A point in time.
TIME_POINT_T getLastCalculationTime() const
Access the last calculation time.
std::vector< DURATION_T > recentBinnedDurations
Duration between each instance of calcualteStatistics in _intervalForRecentStats (rolling window) ...
double getSampleLatency(DataSetType t=DataSetType::FULL) const
double fullValueRate
The sum of all samples over the full duration of sampling.
double lastValueRate
Latest rate point (sum of values over calculateStatistics interval)
double getValueSum(DataSetType t=DataSetType::FULL) const
Returns the sum of values in the requested interval.
TIME_POINT_T lastCalculationTime
Last time calculateStatistics was called.
the full data set (all samples)
double recentValueSumOfSquares
The sum of the squares of the "recent" samples.
double recentValueSum
The sum of the "recent" samples.
double recentValueRate
The sum of the "recent" samples, divided by the length of the "recent" time window.
double recentValueMin
The smallest value of the "recent" samples.
double getRecentValueAverage() const
Access the average of the value samples in the "recent" time span.
double recentValueRMS
The RMS of the 'recent" samples.
DURATION_T getTimeWindowForRecentResults() const
Returns the length of the time window that has been specified for recent results. ...
double getRecentValueSum() const
Access the sum of the value samples in the "recent" time span.
double fullValueMin
The smallest value of all samples.
double fullSampleRate
The total number of samples over the full duration of sampling.
double fullValueRMS
The RMS of all samples.
void getStats(MonitoredQuantityStats &stats) const
Write all our collected statistics into the given Stats struct.
std::vector< long long > recentBinnedSampleCounts
Sample counts for each instance of calculateStatistics in _intervalForRecentStats (rolling window) ...
bool isEnabled() const
Access the enable flag.
double fullValueSum
The sum of all samples.
void setNewTimeWindowForRecentResults(DURATION_T interval)
Specifies a new time interval to be used when calculating "recent" statistics.
DURATION_T getFullDuration() const
Access the full duration of the statistics.