SST  6.0.0
StructuralSimulationToolkit
statuniquecount.h
1 // Copyright 2009-2016 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2016, 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 
18 #include <sst/core/statapi/statbase.h>
19 
20 namespace SST {
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 private:
35  friend class SST::Component;
36 
37  UniqueCountStatistic(Component* comp, std::string& statName, std::string& statSubId, Params& statParams)
38  : Statistic<T>(comp, statName, statSubId, statParams)
39  {
40  // Set the Name of this Statistic
41  this->setStatisticTypeName("UniqueCount");
42  }
43 
45 
46 protected:
47  /**
48  Present a new value to the Statistic to be included in the unique set
49  @param data New data item to be included in the unique set
50  */
51  void addData_impl(T data) {
52  uniqueSet.insert(data);
53  }
54 
55 private:
56  void clearStatisticData()
57  {
58  uniqueSet.clear();
59  }
60 
61  void registerOutputFields(StatisticOutput* statOutput)
62  {
63  uniqueCountField = statOutput->registerField<uint64_t>("UniqueItems");
64  }
65 
66  void outputStatisticData(StatisticOutput* statOutput, bool EndOfSimFlag)
67  {
68  statOutput->outputField(uniqueCountField, (uint64_t) uniqueSet.size());
69  }
70 
71 private:
72  std::set<T> uniqueSet;
73  StatisticOutput::fieldHandle_t uniqueCountField;
74 
75 };
76 
77 } //namespace Statistics
78 } //namespace SST
79 
80 #endif
Main component object for the simulation.
Definition: component.h:56
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:177
Definition: action.cc:17
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:263
void addData_impl(T data)
Present a new value to the Statistic to be included in the unique set.
Definition: statuniquecount.h:51
Parameter store.
Definition: params.h:46