SST  9.0.0
StructuralSimulationToolkit
statuniquecount.h
1 // Copyright 2009-2019 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2019, NTESS
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  SST_ELI_DECLARE_STATISTIC_TEMPLATE(
39  "sst",
40  "UniqueCountStatistic",
41  SST_ELI_ELEMENT_VERSION(1,0,0),
42  "Track unique occurrences of statistic",
43  "SST::Statistic<T>")
44 
45  UniqueCountStatistic(BaseComponent* comp, const std::string& statName, const std::string& statSubId, Params& statParams)
46  : Statistic<T>(comp, statName, statSubId, statParams)
47  {
48  // Set the Name of this Statistic
49  this->setStatisticTypeName("UniqueCount");
50  }
51 
53 
54 protected:
55  /**
56  Present a new value to the Statistic to be included in the unique set
57  @param data New data item to be included in the unique set
58  */
59  void addData_impl(T data) override {
60  uniqueSet.insert(data);
61  }
62 
63 private:
64  void clearStatisticData() override
65  {
66  uniqueSet.clear();
67  }
68 
69  void registerOutputFields(StatisticOutput* statOutput) override
70  {
71  uniqueCountField = statOutput->registerField<uint64_t>("UniqueItems");
72  }
73 
74  void outputStatisticData(StatisticOutput* statOutput, bool UNUSED(EndOfSimFlag)) override
75  {
76  statOutput->outputField(uniqueCountField, (uint64_t) uniqueSet.size());
77  }
78 
79 private:
80  std::set<T> uniqueSet;
81  StatisticOutput::fieldHandle_t uniqueCountField;
82 
83 };
84 
85 
86 } //namespace Statistics
87 } //namespace SST
88 
89 #endif
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:207
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:43
Main component object for the simulation.
Definition: baseComponent.h:52
void addData_impl(T data) override
Present a new value to the Statistic to be included in the unique set.
Definition: statuniquecount.h:59
Parameter store.
Definition: params.h:45