Go to the documentation of this file.00001
00002
00003
00004
00005 #include <assert.h>
00006
00007 #include <sstream>
00008 #include <limits>
00009 #include <stdexcept>
00010
00011 #include <rmol/bom/StatAggregatorStruct.hpp>
00012 #include <rmol/service/Logger.hpp>
00013
00014 namespace RMOL {
00015
00016
00017 StatAggregatorStruct_T::
00018 StatAggregatorStruct_T (const StudyStatManager& iStudyStatMgr,
00019 const std::string& iKey) :
00020 _studyStatMgr (iStudyStatMgr), _key (iKey),
00021 _nbOfEvents (0),
00022 _minimal (std::numeric_limits<int>::max()),
00023 _maximal (std::numeric_limits<int>::min()),
00024 _average (0.0),
00025 _totalTime (0.0){
00026 }
00027
00028
00029 StatAggregatorStruct_T::StatAggregatorStruct_T
00030 (const StatAggregatorStruct_T& iStatAggregatorStruct)
00031 : _studyStatMgr (iStatAggregatorStruct.getStudyStatMgr()),
00032 _key (iStatAggregatorStruct.getPrimaryKey()),
00033 _nbOfEvents (iStatAggregatorStruct.getNumberOfEvents()),
00034 _minimal (iStatAggregatorStruct.getMinimum()),
00035 _maximal (iStatAggregatorStruct.getMaximum()),
00036 _average (iStatAggregatorStruct.getAverage()),
00037 _totalTime (iStatAggregatorStruct.getTotalTime()){
00038 }
00039
00040
00041 const std::string StatAggregatorStruct_T::describeCurrentSimu() const {
00042 std::ostringstream ostr;
00043 ostr << describeKey() << " - nb of events: " << _nbOfEvents << ", min: "
00044 << _minimal << ", max: " << _maximal << ", average :" << _average
00045 << ", total time: " << _totalTime;
00046 return ostr.str();
00047 }
00048
00049
00050 const std::string StatAggregatorStruct_T::describe() const {
00051 std::ostringstream ostr;
00052 ostr << describeKey() << " - nb of events: " << _nbOfEvents << ", min: "
00053 << _minimal << ", max: " << _maximal << ", average :" << _average
00054 << ", average total time: " << _totalTime;
00055 return ostr.str();
00056 }
00057
00058
00059 const std::string StatAggregatorStruct_T::describeKey() const {
00060 return _key;
00061 }
00062
00063
00064 void StatAggregatorStruct_T::display() const {
00065 RMOL_LOG_DEBUG (describe());
00066 }
00067
00068
00069 void StatAggregatorStruct_T::addMeasure (const double iMeasure) {
00070
00071 if (iMeasure < _minimal) {
00072 _minimal = iMeasure;
00073 }
00074
00075
00076 if (iMeasure > _maximal) {
00077 _maximal = iMeasure;
00078 }
00079
00080
00081 _average = (_average * _nbOfEvents + iMeasure ) / (_nbOfEvents+1);
00082
00083
00084 _totalTime += iMeasure;
00085
00086
00087 _nbOfEvents++;
00088 }
00089
00090 }