SST  12.0.1
StructuralSimulationToolkit
statsInfo.h
1 // Copyright 2009-2022 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-2022, 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_ELI_STATS_INFO_H
13 #define SST_CORE_ELI_STATS_INFO_H
14 
15 #include "sst/core/eli/elibase.h"
16 
17 #include <string>
18 #include <vector>
19 
20 namespace SST {
21 namespace ELI {
22 
23 template <class T, class Enable = void>
24 struct InfoStats
25 {
26  static const std::vector<SST::ElementInfoStatistic>& get()
27  {
28  static std::vector<SST::ElementInfoStatistic> var = {};
29  return var;
30  }
31 };
32 
33 template <class T>
34 struct InfoStats<T, typename MethodDetect<decltype(T::ELI_getStatistics())>::type>
35 {
36  static const std::vector<SST::ElementInfoStatistic>& get() { return T::ELI_getStatistics(); }
37 };
38 
40 {
41 private:
42  std::vector<std::string> statnames;
43  std::vector<ElementInfoStatistic> stats_;
44 
45  void init()
46  {
47  for ( auto& item : stats_ ) {
48  statnames.push_back(item.name);
49  }
50  }
51 
52 protected:
53  template <class T>
54  ProvidesStats(T* UNUSED(t)) : stats_(InfoStats<T>::get())
55  {
56  init();
57  }
58 
59 public:
60  const std::vector<ElementInfoStatistic>& getValidStats() const { return stats_; }
61  const std::vector<std::string>& getStatnames() const { return statnames; }
62 
63  void toString(std::ostream& os) const;
64 
65  template <class XMLNode>
66  void outputXML(XMLNode* node) const
67  {
68  // Build the Element to Represent the Component
69  int idx = 0;
70  for ( const ElementInfoStatistic& stat : stats_ ) {
71  // Build the Element to Represent the Parameter
72  auto* XMLStatElement = new XMLNode("Statistic");
73  XMLStatElement->SetAttribute("Index", idx);
74  XMLStatElement->SetAttribute("Name", stat.name);
75  XMLStatElement->SetAttribute("Description", stat.description ? stat.description : "none");
76  XMLStatElement->SetAttribute("Units", stat.units ? stat.units : "none");
77  XMLStatElement->SetAttribute("EnableLevel", stat.enableLevel);
78  node->LinkEndChild(XMLStatElement);
79  ++idx;
80  }
81  }
82 };
83 
84 } // namespace ELI
85 } // namespace SST
86 
87 // clang-format off
88 #define SST_ELI_DOCUMENT_STATISTICS(...) \
89  static const std::vector<SST::ElementInfoStatistic>& ELI_getStatistics() \
90  { \
91  static std::vector<SST::ElementInfoStatistic> var = { __VA_ARGS__ }; \
92  auto parent = SST::ELI::InfoStats< \
93  std::conditional<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>::type>::get(); \
94  SST::ELI::combineEliInfo(var, parent); \
95  return var; \
96  }
97 // clang-format on
98 
99 #define SST_ELI_DELETE_STAT(stat) \
100  { \
101  stat, nullptr, nullptr, 0 \
102  }
103 
104 #endif
Definition: statsInfo.h:39
Definition: elibase.h:114
Describes Statistics used by a Component.
Definition: elibase.h:37
Definition: statsInfo.h:24