00001 #ifndef STOR_ROLLING_INTERVAL_COUNTER_H 00002 #define STOR_ROLLING_INTERVAL_COUNTER_H 00003 00012 #include "EventFilter/StorageManager/interface/BaseCounter.h" 00013 #include "boost/shared_ptr.hpp" 00014 #include "boost/thread/recursive_mutex.hpp" 00015 #include <vector> 00016 00017 namespace stor 00018 { 00019 class RollingIntervalCounter : public BaseCounter 00020 { 00021 00022 public: 00023 00024 enum AccumulationStyle { INCLUDE_SAMPLES_AFTER_BINNING = 0, 00025 INCLUDE_SAMPLES_IMMEDIATELY = 1 }; 00026 00027 RollingIntervalCounter(double timeWindowSize = -1.0, 00028 double timeBinSize = -1.0, 00029 double validSubWindowSize = -1.0, 00030 AccumulationStyle style = INCLUDE_SAMPLES_AFTER_BINNING); 00031 00032 void addSample(double value = 1.0, double currentTime = getCurrentTime()); 00033 bool hasValidResult(double currentTime = getCurrentTime()); 00034 unsigned int getSampleCount(double currentTime = getCurrentTime()); 00035 double getSampleRate(double currentTime = getCurrentTime()); 00036 double getValueSum(double currentTime = getCurrentTime()); 00037 double getValueAverage(double currentTime = getCurrentTime()); 00038 double getValueRate(double currentTime = getCurrentTime()); 00039 double getDuration(double currentTime = getCurrentTime()); 00040 00041 void dumpData(std::ostream& outStream); 00042 00043 private: 00044 00045 void shuffleBins(double currentTime); 00046 long long getBinId(double currentTime); 00047 00048 AccumulationStyle accumStyle_; 00049 00050 double windowSize_; 00051 double binSize_; 00052 int binCount_; 00053 int validBinCount_; 00054 00055 double startTime_; 00056 long long processedBinCount_; 00057 00058 double workingBinSum_; 00059 unsigned int workingBinSampleCount_; 00060 long long workingBinId_; 00061 00062 double currentTotal_; 00063 unsigned int currentSampleCount_; 00064 00065 boost::shared_ptr< std::vector<double> > binContents_; 00066 boost::shared_ptr< std::vector<unsigned int> > binSamples_; 00067 00068 boost::recursive_mutex dataMutex_; 00069 00070 }; 00071 } 00072 00073 #endif