SST  11.1.0
StructuralSimulationToolkit
statuniquecount.h
1 // Copyright 2009-2021 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-2021, 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 #ifndef SST_CORE_STATAPI_STATUNIQUECOUNT_H
13 #define SST_CORE_STATAPI_STATUNIQUECOUNT_H
14 
15 #include "sst/core/sst_types.h"
16 #include "sst/core/statapi/statbase.h"
17 #include "sst/core/warnmacros.h"
18 
19 namespace SST {
20 class BaseComponent;
21 namespace Statistics {
22 
23 /**
24  \class UniqueCountStatistic
25 
26  Creates a Statistic which counts unique values provided to it.
27 
28  @tparam T A template for holding the main data type of this statistic
29 */
30 
31 template <typename T>
33 {
34 public:
35  SST_ELI_DECLARE_STATISTIC_TEMPLATE(
37  "sst",
38  "UniqueCountStatistic",
39  SST_ELI_ELEMENT_VERSION(1, 0, 0),
40  "Track unique occurrences of statistic",
41  "SST::Statistic<T>")
42 
44  BaseComponent* comp, const std::string& statName, const std::string& statSubId, Params& statParams) :
45  Statistic<T>(comp, statName, statSubId, statParams)
46  {
47  // Set the Name of this Statistic
48  this->setStatisticTypeName("UniqueCount");
49  }
50 
52 
53 protected:
54  /**
55  Present a new value to the Statistic to be included in the unique set
56  @param data New data item to be included in the unique set
57  */
58  void addData_impl(T data) override { uniqueSet.insert(data); }
59 
60 private:
61  void clearStatisticData() override { uniqueSet.clear(); }
62 
63  void registerOutputFields(StatisticFieldsOutput* statOutput) override
64  {
65  uniqueCountField = statOutput->registerField<uint64_t>("UniqueItems");
66  }
67 
68  void outputStatisticFields(StatisticFieldsOutput* statOutput, bool UNUSED(EndOfSimFlag)) override
69  {
70  statOutput->outputField(uniqueCountField, (uint64_t)uniqueSet.size());
71  }
72 
73 private:
74  std::set<T> uniqueSet;
75  StatisticOutput::fieldHandle_t uniqueCountField;
76 };
77 
78 } // namespace Statistics
79 } // namespace SST
80 
81 #endif // SST_CORE_STATAPI_STATUNIQUECOUNT_H
Creates a Statistic which counts unique values provided to it.
Definition: statuniquecount.h:32
void setStatisticTypeName(const char *typeName)
Set an optional Statistic Type Name.
Definition: statbase.h:213
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
Main component object for the simulation.
Definition: baseComponent.h:51
void addData_impl(T data) override
Present a new value to the Statistic to be included in the unique set.
Definition: statuniquecount.h:58
Parameter store.
Definition: params.h:43