$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "artdaq/Application/StatisticsHelper.hh" 00002 00003 // This class is really nothing more than a collection of code that 00004 // would be repeated throughout artdaq "application" classes if it 00005 // weren't centralized here. So, we should be careful not to put 00006 // too much intelligence in this class. (KAB, 07-Jan-2015) 00007 00008 artdaq::StatisticsHelper:: 00009 StatisticsHelper() : monitored_quantity_name_list_(0) 00010 , primary_stat_ptr_(0) 00011 , previous_reporting_index_(0) 00012 , previous_stats_calc_time_(0.0) {} 00013 00014 void artdaq::StatisticsHelper:: 00015 addMonitoredQuantityName(std::string const& statKey) 00016 { 00017 monitored_quantity_name_list_.push_back(statKey); 00018 } 00019 00020 void artdaq::StatisticsHelper::addSample(std::string const& statKey, 00021 double value) const 00022 { 00023 artdaq::MonitoredQuantityPtr mqPtr = 00024 artdaq::StatisticsCollection::getInstance().getMonitoredQuantity(statKey); 00025 if (mqPtr.get() != 0) { mqPtr->addSample(value); } 00026 } 00027 00028 bool artdaq::StatisticsHelper:: 00029 createCollectors(fhicl::ParameterSet const& pset, int defaultReportIntervalFragments, 00030 double defaultReportIntervalSeconds, double defaultMonitorWindow, 00031 std::string const& primaryStatKeyName) 00032 { 00033 reporting_interval_fragments_ = 00034 pset.get<int>("reporting_interval_fragments", defaultReportIntervalFragments); 00035 reporting_interval_seconds_ = 00036 pset.get<double>("reporting_interval_seconds", defaultReportIntervalSeconds); 00037 00038 double monitorWindow = pset.get<double>("monitor_window", defaultMonitorWindow); 00039 double monitorBinSize = 00040 pset.get<double>("monitor_binsize", 00041 1.0 + static_cast<int>((monitorWindow - 1) / 100.0)); 00042 00043 if (monitorBinSize < 1.0) { monitorBinSize = 1.0; } 00044 if (monitorWindow >= 1.0) 00045 { 00046 for (size_t idx = 0; idx < monitored_quantity_name_list_.size(); ++idx) 00047 { 00048 artdaq::MonitoredQuantityPtr 00049 mqPtr(new artdaq::MonitoredQuantity(monitorBinSize, 00050 monitorWindow)); 00051 artdaq::StatisticsCollection::getInstance(). 00052 addMonitoredQuantity(monitored_quantity_name_list_[idx], mqPtr); 00053 } 00054 } 00055 00056 primary_stat_ptr_ = artdaq::StatisticsCollection::getInstance(). 00057 getMonitoredQuantity(primaryStatKeyName); 00058 return (primary_stat_ptr_.get() != 0); 00059 } 00060 00061 void artdaq::StatisticsHelper::resetStatistics() 00062 { 00063 previous_reporting_index_ = 0; 00064 previous_stats_calc_time_ = 0.0; 00065 for (size_t idx = 0; idx < monitored_quantity_name_list_.size(); ++idx) 00066 { 00067 artdaq::MonitoredQuantityPtr mqPtr = artdaq::StatisticsCollection::getInstance(). 00068 getMonitoredQuantity(monitored_quantity_name_list_[idx]); 00069 if (mqPtr.get() != nullptr) { mqPtr->reset(); } 00070 } 00071 } 00072 00073 bool artdaq::StatisticsHelper:: 00074 readyToReport(size_t currentCount) 00075 { 00076 if (primary_stat_ptr_.get() != 0 && 00077 (currentCount % reporting_interval_fragments_) == 0) 00078 { 00079 double fullDuration = primary_stat_ptr_->getFullDuration(); 00080 size_t reportIndex = (size_t)(fullDuration / reporting_interval_seconds_); 00081 if (reportIndex > previous_reporting_index_) 00082 { 00083 previous_reporting_index_ = reportIndex; 00084 return true; 00085 } 00086 } 00087 00088 return false; 00089 } 00090 00091 bool artdaq::StatisticsHelper::statsRollingWindowHasMoved() 00092 { 00093 if (primary_stat_ptr_.get() != 0) 00094 { 00095 auto lastCalcTime = primary_stat_ptr_->getLastCalculationTime(); 00096 if (lastCalcTime > previous_stats_calc_time_) 00097 { 00098 auto now = MonitoredQuantity::getCurrentTime(); 00099 previous_stats_calc_time_ = std::min(lastCalcTime, now); 00100 return true; 00101 } 00102 } 00103 00104 return false; 00105 }