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