CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonitoredQuantity.h
Go to the documentation of this file.
1 // $Id: MonitoredQuantity.h,v 1.10 2011/03/07 15:31:32 mommsen Exp $
3 
4 #ifndef EventFilter_StorageManager_MonitoredQuantity_h
5 #define EventFilter_StorageManager_MonitoredQuantity_h
6 
7 #include "boost/shared_ptr.hpp"
8 #include "boost/thread/mutex.hpp"
9 
10 #include <math.h>
11 #include <stdint.h>
12 #include <vector>
13 
15 
16 
17 namespace stor
18 {
19 
30  {
31 
32  public:
33  class Stats;
34 
35  enum DataSetType { FULL = 0, // the full data set (all samples)
36  RECENT = 1 }; // recent data only
37 
38  explicit MonitoredQuantity
39  (
40  utils::Duration_t expectedCalculationInterval,
41  utils::Duration_t timeWindowForRecentResults
42  );
43 
47  void addSample(const double& value = 1);
48 
52  void addSample(const int& value = 1);
53 
57  void addSample(const unsigned int& value = 1);
58 
62  void addSample(const long& value = 1);
63 
67  void addSample(const unsigned long& value = 1);
68 
72  void addSample(const long long& value = 1);
73 
77  void addSample(const unsigned long long& value = 1);
78 
83  void addSampleIfLarger(const double& value);
84 
92  void calculateStatistics(const utils::TimePoint_t& currentTime =
94 
99  void reset();
100 
105  void enable();
106 
110  void disable();
111 
115  bool isEnabled() const {return enabled_;}
116 
122 
132  {
134  }
135 
137  {
139  }
140 
144  void getStats(Stats& stats) const;
145 
146  private:
147 
148  // Prevent copying of the MonitoredQuantity
151 
152  // Helper functions.
153  void resetAccumulators();
154  void resetResults();
155 
163 
165 
166  uint32_t binCount_;
167  uint32_t workingBinId_;
168  std::vector<uint64_t> binSampleCount_;
169  std::vector<double> binValueSum_;
170  std::vector<double> binValueSumOfSquares_;
171  std::vector<double> binValueMin_;
172  std::vector<double> binValueMax_;
173  std::vector<utils::Duration_t> binDuration_;
174  std::vector<utils::TimePoint_t> binSnapshotTime_;
175 
186 
199 
201 
202  bool enabled_;
205  };
206 
208  {
211  double fullValueSum;
214  double fullValueRMS;
215  double fullValueMin;
216  double fullValueMax;
220 
232  std::vector<uint64_t> recentBinnedSampleCounts;
233  std::vector<double> recentBinnedValueSums;
234  std::vector<utils::Duration_t> recentBinnedDurations;
235  std::vector<utils::TimePoint_t> recentBinnedSnapshotTimes;
236 
239  bool enabled;
240 
242  double getValueSum(DataSetType t = FULL) const { return t == RECENT ? recentValueSum : fullValueSum; }
245  double getValueRMS(DataSetType t = FULL) const { return t == RECENT ? recentValueRMS : fullValueRMS; }
246  double getValueMin(DataSetType t = FULL) const { return t == RECENT ? recentValueMin : fullValueMin; }
247  double getValueMax(DataSetType t = FULL) const { return t == RECENT ? recentValueMax : fullValueMax; }
250  double getSampleLatency(DataSetType t = FULL) const { double v=getSampleRate(t); return v ? 1e6/v : INFINITY;}
251  double getLastSampleValue() const { return lastSampleValue; }
252  double getLastValueRate() const { return lastValueRate; }
253  bool isEnabled() const { return enabled; }
254  };
255 
256  typedef boost::shared_ptr<MonitoredQuantity> MonitoredQuantityPtr;
257 
258 } // namespace stor
259 
260 #endif // EventFilter_StorageManager_MonitoredQuantity_h
261 
262 
263 
TimePoint_t getCurrentTime()
Definition: Utils.h:158
double getValueRate(DataSetType t=FULL) const
utils::Duration_t intervalForRecentStats_
utils::Duration_t ExpectedCalculationInterval() const
utils::Duration_t recentDuration_
std::vector< utils::TimePoint_t > binSnapshotTime_
void setNewTimeWindowForRecentResults(const utils::Duration_t &interval)
tuple interval
Definition: MergeJob_cfg.py:20
boost::shared_ptr< MonitoredQuantity > MonitoredQuantityPtr
static boost::mutex mutex
Definition: LHEProxy.cc:11
void addSample(const double &value=1)
std::vector< uint64_t > recentBinnedSampleCounts
std::vector< uint64_t > binSampleCount_
uint64_t getSampleCount(DataSetType t=FULL) const
void getStats(Stats &stats) const
double getValueMin(DataSetType t=FULL) const
std::vector< double > binValueSum_
std::vector< utils::TimePoint_t > recentBinnedSnapshotTimes
const utils::Duration_t expectedCalculationInterval_
std::vector< utils::Duration_t > binDuration_
std::vector< double > binValueMax_
utils::Duration_t getDuration(DataSetType t=FULL) const
void calculateStatistics(const utils::TimePoint_t &currentTime=utils::getCurrentTime())
utils::Duration_t fullDuration_
double getValueRMS(DataSetType t=FULL) const
boost::posix_time::time_duration Duration_t
Definition: Utils.h:41
boost::posix_time::ptime TimePoint_t
Definition: Utils.h:35
double getSampleRate(DataSetType t=FULL) const
std::vector< double > recentBinnedValueSums
double getValueAverage(DataSetType t=FULL) const
utils::TimePoint_t lastCalculationTime_
unsigned long long uint64_t
Definition: Time.h:15
double getValueMax(DataSetType t=FULL) const
std::vector< utils::Duration_t > recentBinnedDurations
void addSampleIfLarger(const double &value)
utils::Duration_t getTimeWindowForRecentResults() const
MonitoredQuantity(utils::Duration_t expectedCalculationInterval, utils::Duration_t timeWindowForRecentResults)
double getValueSum(DataSetType t=FULL) const
double getSampleLatency(DataSetType t=FULL) const
mathSSE::Vec4< T > v
std::vector< double > binValueMin_
std::vector< double > binValueSumOfSquares_
MonitoredQuantity & operator=(MonitoredQuantity const &)