CMS 3D CMS Logo

ForeverAverageCounter.cc

Go to the documentation of this file.
00001 
00005 #include "EventFilter/StorageManager/interface/ForeverAverageCounter.h"
00006 #include <math.h>
00007 
00008 using namespace stor;
00009 
00013 ForeverAverageCounter::ForeverAverageCounter():
00014   sampleCount_(0),
00015   currentTotal_(0.0),
00016   currentTotalSquares_(0.0),
00017   currentMin_(9999999999.0),
00018   currentMax_(-1.0)
00019 {
00020 }
00021 
00025 void ForeverAverageCounter::addSample(double value)
00026 {
00027   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00028 
00029   currentTotal_ += value;
00030   currentTotalSquares_ += value*value;
00031   ++sampleCount_;
00032   if(value < currentMin_) currentMin_ = value;
00033   if(value > currentMax_) currentMax_ = value;
00034 }
00035 
00039 void ForeverAverageCounter::reset()
00040 {
00041   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00042 
00043   sampleCount_ = 0;
00044   currentTotal_ = 0.0;
00045   currentTotalSquares_ = 0.0;
00046   currentMin_ = 9999999999.0;
00047   currentMax_ = -1.0;
00048 }
00049 
00053 long long ForeverAverageCounter::getSampleCount()
00054 {
00055   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00056 
00057   return sampleCount_;
00058 }
00059 
00063 double ForeverAverageCounter::getValueSum() {
00064   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00065 
00066   return currentTotal_;
00067 }
00068 
00072 double ForeverAverageCounter::getValueSumSquares() {
00073   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00074 
00075   return currentTotalSquares_;
00076 }
00077 
00082 double ForeverAverageCounter::getValueAverage()
00083 {
00084   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00085 
00086   if (sampleCount_ > 0) {
00087     return ((double) currentTotal_) / ((double) sampleCount_);
00088   }
00089   else {
00090     return 0.0;
00091   }
00092 }
00093 
00098 double ForeverAverageCounter::getValueRMS()
00099 {
00100   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00101 
00102   if (sampleCount_ > 0) {
00103     double ave_squares = (currentTotalSquares_ / (double) sampleCount_);
00104     double ave = (currentTotal_ / (double) sampleCount_);
00105     double sig_squared = ave_squares - ave*ave;
00106     if(sig_squared > 0.0) 
00107        return sqrt(sig_squared);
00108     else
00109        return 0.0;
00110   }
00111   else {
00112     return 0.0;
00113   }
00114 }
00115 
00119 double ForeverAverageCounter::getValueMin() {
00120   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00121 
00122   return currentMin_;
00123 }
00124 
00128 double ForeverAverageCounter::getValueMax() {
00129   boost::recursive_mutex::scoped_lock sl(dataMutex_);
00130 
00131   return currentMax_;
00132 }
00133 

Generated on Tue Jun 9 17:34:56 2009 for CMSSW by  doxygen 1.5.4