SST  7.1.0
StructuralSimulationToolkit
statuniquecount.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-NA0003525 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 
13 #ifndef _H_SST_CORE_UNIQUE_COUNT_STATISTIC_
14 #define _H_SST_CORE_UNIQUE_COUNT_STATISTIC_
15 
16 #include <sst/core/sst_types.h>
17 #include <sst/core/warnmacros.h>
18 
19 #include <sst/core/statapi/statbase.h>
20 
21 namespace SST {
22 class BaseComponent;
23 namespace Statistics {
24 
25 /**
26  \class UniqueCountStatistic
27 
28  Creates a Statistic which counts unique values provided to it.
29 
30  @tparam T A template for holding the main data type of this statistic
31 */
32 
33 template <typename T>
35 {
36 public:
37 
38  UniqueCountStatistic(BaseComponent* comp, const std::string& statName, const std::string& statSubId, Params& statParams)
39  : Statistic<T>(comp, statName, statSubId, statParams)
40  {
41  // Set the Name of this Statistic
42  this->setStatisticTypeName("UniqueCount");
43  }
44 
46 
47 protected:
48  /**
49  Present a new value to the Statistic to be included in the unique set
50  @param data New data item to be included in the unique set
51  */
52  void addData_impl(T data) override {
53  uniqueSet.insert(data);
54  }
55 
56 private:
57  void clearStatisticData() override
58  {
59  uniqueSet.clear();
60  }
61 
62  void registerOutputFields(StatisticOutput* statOutput) override
63  {
64  uniqueCountField = statOutput->registerField<uint64_t>("UniqueItems");
65  }
66 
67  void outputStatisticData(StatisticOutput* statOutput, bool UNUSED(EndOfSimFlag)) override
68  {
69  statOutput->outputField(uniqueCountField, (uint64_t) uniqueSet.size());
70  }
71 
72 private:
73  std::set<T> uniqueSet;
74  StatisticOutput::fieldHandle_t uniqueCountField;
75 
76 };
77 
78 } //namespace Statistics
79 } //namespace SST
80 
81 #endif
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:47
fieldHandle_t registerField(const char *fieldName)
Register a field to be output (templated function)
Definition: statoutput.h:85
Creates a Statistic which counts unique values provided to it.
Definition: statuniquecount.h:34
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:202
Definition: action.cc:17
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:294
Main component object for the simulation.
Definition: baseComponent.h:104
void addData_impl(T data) override
Present a new value to the Statistic to be included in the unique set.
Definition: statuniquecount.h:52
Parameter store.
Definition: params.h:45
void outputField(fieldHandle_t fieldHandle, int32_t data)
Output field data.
Definition: statoutput.cc:166