00001 #ifndef STOR_ROLLING_SAMPLE_COUNTER_H 00002 #define STOR_ROLLING_SAMPLE_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 RollingSampleCounter : public BaseCounter 00020 { 00021 00022 public: 00023 00024 enum AccumulationStyle { INCLUDE_SAMPLES_AFTER_BINNING = 0, 00025 INCLUDE_SAMPLES_IMMEDIATELY = 1 }; 00026 00027 RollingSampleCounter(int windowSize = -1, int binSize = -1, 00028 int validSubWindowSize = -1, 00029 AccumulationStyle style = INCLUDE_SAMPLES_AFTER_BINNING); 00030 00031 void addSample(double value = 1.0, double currentTime = getCurrentTime()); 00032 bool hasValidResult(); 00033 int getSampleCount(); 00034 double getSampleRate(double currentTime = 0.0); 00035 double getValueSum(); 00036 double getValueAverage(); 00037 double getValueRate(); 00038 double getDuration(double currentTime = 0.0); 00039 00040 void dumpData(std::ostream& outStream); 00041 00042 private: 00043 00044 void shuffleBins(long long sampleCount); 00045 long long getBinId(long long sampleCount); 00046 00047 AccumulationStyle accumStyle_; 00048 00049 int windowSize_; 00050 int binSize_; 00051 int binCount_; 00052 int validBinCount_; 00053 00054 long long sampleCount_; 00055 long long processedBinCount_; 00056 00057 double workingBinSum_; 00058 double workingBinStartTime_; 00059 long long workingBinId_; 00060 00061 double currentTotal_; 00062 00063 boost::shared_ptr< std::vector<double> > binStartTimes_; 00064 boost::shared_ptr< std::vector<double> > binStopTimes_; 00065 boost::shared_ptr< std::vector<double> > binContents_; 00066 00067 boost::recursive_mutex dataMutex_; 00068 00069 }; 00070 } 00071 00072 #endif