SST 15.0
Structural Simulation Toolkit
statsInfo.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_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
20namespace SST::ELI {
21
22template <typename, typename = void>
24{
25 static const std::vector<SST::ElementInfoStatistic>& get()
26 {
27 static std::vector<SST::ElementInfoStatistic> var = {};
28 return var;
29 }
30};
31
32template <typename T>
33struct InfoStats<T, std::void_t<decltype(T::ELI_getStatistics())>>
34{
35 static const std::vector<SST::ElementInfoStatistic>& get() { return T::ELI_getStatistics(); }
36};
37
38class ProvidesStats
39{
40private:
41 std::vector<std::string> statnames;
42 std::vector<ElementInfoStatistic> stats_;
43
44 void init()
45 {
46 for ( auto& item : stats_ ) {
47 statnames.push_back(item.name);
48 }
49 }
50
51protected:
52 template <class T>
53 explicit ProvidesStats(T* UNUSED(t)) :
54 stats_(InfoStats<T>::get())
55 {
56 init();
57 }
58
59public:
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 SST::ELI
85
86// clang-format off
87#define SST_ELI_DOCUMENT_STATISTICS(...) \
88 static const std::vector<SST::ElementInfoStatistic>& ELI_getStatistics() \
89 { \
90 static std::vector<SST::ElementInfoStatistic> var = { __VA_ARGS__ }; \
91 auto parent = SST::ELI::InfoStats< \
92 std::conditional_t<(__EliDerivedLevel > __EliBaseLevel), __LocalEliBase, __ParentEliBase>>::get(); \
93 SST::ELI::combineEliInfo(var, parent); \
94 return var; \
95 }
96// clang-format on
97
98#define SST_ELI_DELETE_STAT(stat) { stat, nullptr, nullptr, 0 }
99
100#endif
Definition statsInfo.h:24
Describes Statistics used by a Component.
Definition elibase.h:38