SST 15.0
Structural Simulation Toolkit
statuniquecount.h
1// Copyright 2009-2025 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-2025, 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
19namespace SST {
20class BaseComponent;
21namespace 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
31template <typename T>
32class UniqueCountStatistic : public Statistic<T>
33{
34public:
35 SST_ELI_DECLARE_STATISTIC_TEMPLATE(
36 UniqueCountStatistic,
37 "sst",
38 "UniqueCountStatistic",
39 SST_ELI_ELEMENT_VERSION(1, 0, 0),
40 "Track unique occurrences of statistic",
41 "SST::Statistic<T>")
42
43 UniqueCountStatistic(
44 BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
45 Statistic<T>(comp, stat_name, stat_sub_id, stat_params)
46 {}
47
48 ~UniqueCountStatistic() {};
49
50 UniqueCountStatistic() :
52 {}
53
54 virtual const std::string& getStatTypeName() const override { return stat_type_; }
55
57 {
59 SST_SER(unique_set_);
60 // unique_count_field_ will be reset by statistics output object
61 }
62
63protected:
64 /**
65 Present a new value to the Statistic to be included in the unique set
66 @param data New data item to be included in the unique set
67 */
68 void addData_impl(T data) override { unique_set_.insert(data); }
69
70private:
71 void clearStatisticData() override { unique_set_.clear(); }
72
73 void registerOutputFields(StatisticFieldsOutput* stat_output) override
74 {
75 unique_count_field_ = stat_output->registerField<uint64_t>("UniqueItems");
76 }
77
78 void outputStatisticFields(StatisticFieldsOutput* stat_output, bool UNUSED(end_of_sim_flag)) override
79 {
80 stat_output->outputField(unique_count_field_, (uint64_t)unique_set_.size());
81 }
82
83private:
84 std::set<T> unique_set_;
85 StatisticOutput::fieldHandle_t unique_count_field_;
86 inline static const std::string stat_type_ = "UniqueCount";
87};
88
89} // namespace Statistics
90} // namespace SST
91
92#endif // SST_CORE_STATAPI_STATUNIQUECOUNT_H
Main component object for the simulation.
Definition baseComponent.h:62
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Parameter store.
Definition params.h:58
Statistic(BaseComponent *comp, const std::string &stat_name, const std::string &stat_sub_id, Params &stat_params, bool null_stat=false)
Construct a Statistic.
Definition statbase.h:437
virtual void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statbase.h:420
void addData_impl(T data) override
Present a new value to the Statistic to be included in the unique set.
Definition statuniquecount.h:68
virtual const std::string & getStatTypeName() const override
Return the Statistic type name.
Definition statuniquecount.h:54
void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization.
Definition statuniquecount.h:56