SST  15.1.0
StructuralSimulationToolkit
statnull.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_STATNULL_H
13 #define SST_CORE_STATAPI_STATNULL_H
14 
15 #include "sst/core/sst_types.h"
16 #include "sst/core/statapi/statbase.h"
17 #include "sst/core/warnmacros.h"
18 
19 #include <tuple>
20 
21 namespace SST::Statistics {
22 
23 // NOTE: When calling base class members of classes derived from
24 // a templated base class. The user must use "this->" in
25 // order to call base class members (to avoid a compiler
26 // error) because they are "nondependant named" and the
27 // templated base class is a "dependant named". The
28 // compiler will not look in dependant named base classes
29 // when looking up indepenedent names.
30 // See: http://www.parashift.com/c++-faq-lite/nondependent-name-lookup-members.html
31 
32 /**
33  \class NullStatistic
34 
35  An empty statistic place holder.
36 
37  @tparam T A template for holding the main data type of this statistic
38 */
39 template <class T, bool = std::is_arithmetic_v<T>>
41 
42 template <class T>
43 class NullStatisticBase<T, true> : public Statistic<T>
44 {
45 public:
47  BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
48  Statistic<T>(comp, stat_name, stat_sub_id, stat_params)
49  {}
50 
51  void addData_impl(T UNUSED(data)) override {}
52 
53  void addData_impl_Ntimes(uint64_t UNUSED(N), T UNUSED(data)) override {}
54 
55  virtual const std::string& getStatTypeName() const override { return stat_type_; }
56 
57 private:
58  inline static const std::string stat_type_ = "NULL";
59 };
60 
61 template <class... Args>
62 class NullStatisticBase<std::tuple<Args...>, false> : public Statistic<std::tuple<Args...>>
63 {
64 public:
66  BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
67  Statistic<std::tuple<Args...>>(comp, stat_name, stat_sub_id, stat_params)
68  {}
69 
70  void addData_impl(Args... UNUSED(data)) override {}
71 
72  void addData_impl_Ntimes(uint64_t UNUSED(N), Args... UNUSED(data)) override {}
73 
74  virtual const std::string& getStatTypeName() const override { return stat_type_; }
75 
76 private:
77  inline static const std::string stat_type_ = "NULL";
78 };
79 
80 template <class T>
81 class NullStatisticBase<T, false> : public Statistic<T>
82 {
83 public:
85  BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
86  Statistic<T>(comp, stat_name, stat_sub_id, stat_params)
87  {}
88 
89  void addData_impl(T&& UNUSED(data)) override {}
90  void addData_impl(const T& UNUSED(data)) override {}
91 
92  void addData_impl_Ntimes(uint64_t UNUSED(N), T&& UNUSED(data)) override {}
93  void addData_impl_Ntimes(uint64_t UNUSED(N), const T& UNUSED(data)) override {}
94 
95  virtual const std::string& getStatTypeName() const override { return stat_type_; }
96 
97 private:
98  inline static const std::string stat_type_ = "NULL";
99 };
100 
101 template <class T>
103 {
104 public:
105  SST_ELI_DECLARE_STATISTIC_TEMPLATE(
107  "sst",
108  "NullStatistic",
109  SST_ELI_ELEMENT_VERSION(1,0,0),
110  "Null object that ignores all collections",
111  "SST::Statistic<T>"
112  )
113 
115  BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
116  NullStatisticBase<T>(comp, stat_name, stat_sub_id, stat_params)
117  {}
118 
119  ~NullStatistic() {}
120 
121  void clearStatisticData() override
122  {
123  // Do Nothing
124  }
125 
126  void registerOutputFields(StatisticFieldsOutput* UNUSED(stat_output)) override
127  {
128  // Do Nothing
129  }
130 
131  void outputStatisticFields(StatisticFieldsOutput* UNUSED(stat_output), bool UNUSED(end_of_sim_flag)) override
132  {
133  // Do Nothing
134  }
135 
136  bool isReady() const override { return true; }
137 
138  bool isNullStatistic() const override { return true; }
139 
140  static bool isLoaded() { return true; }
141 };
142 
143 template <>
144 class NullStatistic<void> : public Statistic<void>
145 {
146 public:
147  SST_ELI_REGISTER_DERIVED(
150  "sst",
151  "NullStatistic",
152  SST_ELI_ELEMENT_VERSION(1,0,0),
153  "Null statistic for custom (void) stats"
154  )
155 
156  SST_ELI_INTERFACE_INFO("Statistic<void>")
157 
159  BaseComponent* comp, const std::string& stat_name, const std::string& stat_sub_id, Params& stat_params) :
160  Statistic<void>(comp, stat_name, stat_sub_id, stat_params)
161  {}
162 
163  virtual std::string getELIName() const override { return "sst.NullStatistic"; }
164 
165  virtual const std::string& getStatTypeName() const override { return stat_type_; }
166 
167 private:
168  inline static const std::string stat_type_ = "NULL";
169 };
170 
171 } // namespace SST::Statistics
172 
173 #endif // SST_CORE_STATAPI_STATNULL_H
virtual const std::string & getStatTypeName() const override
Return the Statistic type name.
Definition: statnull.h:55
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:46
void Statistic has special meaning in that it does not collect fields in the usual way through the ad...
Definition: statbase.h:448
virtual const std::string & getStatTypeName() const override
Return the Statistic type name.
Definition: statnull.h:74
virtual const std::string & getStatTypeName() const override
Return the Statistic type name.
Definition: statnull.h:95
Definition: statoutput.h:170
Main component object for the simulation.
Definition: baseComponent.h:64
Parameter store.
Definition: params.h:63
Definition: statnull.h:144
Definition: elementinfo.h:44
Definition: statnull.h:40
An empty statistic place holder.
Definition: statnull.h:102