13 #ifndef _H_SST_CORE_HISTOGRAM_STATISTIC_
14 #define _H_SST_CORE_HISTOGRAM_STATISTIC_
16 #include <sst/core/sst_types.h>
18 #include <sst/core/statapi/statbase.h>
21 namespace Statistics {
37 #define CountType uint64_t
38 #define NumBinsType uint32_t
40 template<
class BinDataType>
51 allowedKeySet.insert(
"minvalue");
52 allowedKeySet.insert(
"binwidth");
53 allowedKeySet.insert(
"numbins");
54 allowedKeySet.insert(
"dumpbinsonoutput");
55 allowedKeySet.insert(
"includeoutofbounds");
59 m_minValue = statParams.
find<BinDataType>(
"minvalue", 0);
60 m_binWidth = statParams.
find<NumBinsType>(
"binwidth", 5000);
61 m_numBins = statParams.
find<NumBinsType>(
"numbins", 100);
62 m_dumpBinsOnOutput = statParams.
find<
bool>(
"dumpbinsonoutput",
true);
63 m_includeOutOfBounds = statParams.
find<
bool>(
"includeoutofbounds",
true);
70 m_itemsBinnedCount = 0;
87 if (value < getBinsMinValue()) {
91 if (value > getBinsMaxValue()) {
98 m_totalSummed += value;
99 m_totalSummedSqr += (value * value);
102 m_itemsBinnedCount++;
108 double calc1 = (double)value / (
double)m_binWidth;
109 double calc2 = floor(calc1);
110 double calc3 = m_binWidth * calc2;
111 BinDataType bin_start = (BinDataType)calc3;
114 HistoMapItr_t bin_itr = m_binsMap.find(bin_start);
117 if(bin_itr == m_binsMap.end()) {
119 m_binsMap.insert(std::pair<BinDataType, CountType>(bin_start, (CountType) 1));
128 NumBinsType getActiveBinCount()
130 return m_binsMap.size();
134 NumBinsType getNumBins()
140 NumBinsType getBinWidth()
149 CountType getBinCountByBinStart(BinDataType binStartValue)
152 HistoMapItr_t bin_itr = m_binsMap.find(binStartValue);
155 if(bin_itr == m_binsMap.end()) {
157 return (CountType) 0;
160 return m_binsMap[binStartValue];
167 BinDataType getBinsMinValue()
175 BinDataType getBinsMaxValue()
178 return (m_binWidth * m_numBins) + m_minValue - 1;
185 uint64_t getStatCollectionCount()
195 CountType getItemsBinnedCount()
198 return m_itemsBinnedCount;
205 BinDataType getValuesSummed()
207 return m_totalSummed;
214 BinDataType getValuesSquaredSummed() {
215 return m_totalSummedSqr;
218 void clearStatisticData()
221 m_totalSummedSqr = 0;
224 m_itemsBinnedCount = 0;
229 void registerOutputFields(StatisticOutput* statOutput)
232 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMinValue"));
233 m_Fields.push_back(statOutput->registerField<BinDataType>(
"BinsMaxValue"));
234 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"BinWidth"));
235 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"TotalNumBins"));
236 m_Fields.push_back(statOutput->registerField<BinDataType>(
"Sum"));
237 m_Fields.push_back(statOutput->registerField<BinDataType>(
"SumSQ"));
238 m_Fields.push_back(statOutput->registerField<NumBinsType>(
"NumActiveBins"));
239 m_Fields.push_back(statOutput->registerField<CountType> (
"NumItemsCollected"));
240 m_Fields.push_back(statOutput->registerField<CountType> (
"NumItemsBinned"));
242 if (
true == m_includeOutOfBounds) {
243 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MinValue"));
244 m_Fields.push_back(statOutput->registerField<CountType>(
"NumOutOfBounds-MaxValue"));
248 if (
true == m_dumpBinsOnOutput) {
252 for (uint32_t y = 0; y < getNumBins(); y++) {
254 binLL = (y * (uint64_t)getBinWidth()) + getBinsMinValue();
255 binUL = binLL + getBinWidth() - 1;
257 std::stringstream ss;
258 ss <<
"Bin" << y <<
":" << binLL <<
"-" << binUL;
259 m_Fields.push_back(statOutput->registerField<CountType>(ss.str().c_str()));
264 void outputStatisticData(StatisticOutput* statOutput,
bool EndOfSimFlag)
267 statOutput->outputField(m_Fields[x++], getBinsMinValue());
268 statOutput->outputField(m_Fields[x++], getBinsMaxValue());
269 statOutput->outputField(m_Fields[x++], getBinWidth());
270 statOutput->outputField(m_Fields[x++], getNumBins());
271 statOutput->outputField(m_Fields[x++], getValuesSummed());
272 statOutput->outputField(m_Fields[x++], getValuesSquaredSummed());
273 statOutput->outputField(m_Fields[x++], getActiveBinCount());
274 statOutput->outputField(m_Fields[x++], getStatCollectionCount());
275 statOutput->outputField(m_Fields[x++], getItemsBinnedCount());
277 if (
true == m_includeOutOfBounds) {
278 statOutput->outputField(m_Fields[x++], m_OOBMinCount);
279 statOutput->outputField(m_Fields[x++], m_OOBMaxCount);
283 if (
true == m_dumpBinsOnOutput) {
284 BinDataType currentBinValue = getBinsMinValue();
285 for (uint32_t y = 0; y < getNumBins(); y++) {
286 statOutput->outputField(m_Fields[x++], getBinCountByBinStart(currentBinValue));
288 currentBinValue += getBinWidth();
295 if (mode == StatisticBase::STAT_MODE_COUNT) {
298 if (mode == StatisticBase::STAT_MODE_PERIODIC) {
306 typedef std::map<BinDataType, CountType> HistoMap_t;
309 typedef typename HistoMap_t::iterator HistoMapItr_t;
312 BinDataType m_minValue;
315 NumBinsType m_binWidth;
318 NumBinsType m_numBins;
321 CountType m_OOBMinCount;
322 CountType m_OOBMaxCount;
326 CountType m_itemsBinnedCount;
330 BinDataType m_totalSummed;
334 BinDataType m_totalSummedSqr;
337 HistoMap_t m_binsMap;
340 std::vector<uint32_t> m_Fields;
341 bool m_dumpBinsOnOutput;
342 bool m_includeOutOfBounds;
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.h:409
Main component object for the simulation.
Definition: component.h:56
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:177
uint64_t getCollectionCount() const
Return the current collection count.
Definition: statbase.h:120
Holder of data grouped into pre-determined width bins.
Definition: stathistogram.h:41
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:263
void addData_impl(BinDataType value)
Adds a new value to the histogram.
Definition: stathistogram.h:84
T find(const std::string &k, T default_value, bool &found) const
Find a Parameter value in the set, and return its value as a type T.
Definition: params.h:164
StatMode_t
Statistic collection mode.
Definition: statbase.h:40
Parameter store.
Definition: params.h:46
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:95
virtual void setCollectionCount(uint64_t newCount)
Set the current collection count to a defined value.
Definition: statbase.cc:41