SST  14.1.0
StructuralSimulationToolkit
statfieldinfo.h
1 // Copyright 2009-2024 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-2024, 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_STATFIELDINFO_H
13 #define SST_CORE_STATAPI_STATFIELDINFO_H
14 
15 #include "sst/core/sst_types.h"
16 
17 #include <map>
18 #include <string>
19 
20 namespace SST {
21 namespace Statistics {
22 
23 using fieldType_t = uint32_t;
24 
25 /**
26  \class StatisticFieldInfo
27 
28  The class for representing Statistic Output Fields
29 */
30 
32 {
33 public:
34  virtual const char* fieldName() const = 0;
35  virtual const char* shortName() const = 0;
36 
37  virtual ~StatisticFieldTypeBase() {}
38 
39  static StatisticFieldTypeBase* getField(fieldType_t fieldType);
40 
41  // This is not a quick lookup; intended for checkpoint/restart only
42  static fieldType_t getField(const char* fieldShortName);
43 
44  static void checkRegisterConflict(const char* oldName, const char* newName);
45 
46  static fieldType_t allocateFieldEnum();
47 
48 protected:
49  static void addField(fieldType_t id, StatisticFieldTypeBase* base);
50 
51 private:
52  static std::map<fieldType_t, StatisticFieldTypeBase*>* fields_;
53  static fieldType_t enumCounter_;
54 };
55 
56 template <class T>
58 {
59 public:
60  // constructor for initializing data
61  StatisticFieldType(const char* name, const char* shortName)
62  {
63  checkRegisterConflict(fieldName_, name);
64  checkRegisterConflict(shortName_, shortName);
65  fieldName_ = name;
66  shortName_ = shortName;
67  if ( fieldEnum_ == 0 ) { fieldEnum_ = allocateFieldEnum(); }
68 
69  fieldName_ = name;
70  shortName_ = shortName;
71  addField(fieldEnum_, this);
72  }
73 
74  static const char* getFieldName() { return fieldName_; }
75 
76  static const char* getShortName() { return shortName_; }
77 
78  static fieldType_t id() { return fieldEnum_; }
79 
80  const char* fieldName() const override { return getFieldName(); }
81 
82  const char* shortName() const override { return getShortName(); }
83 
84 private:
85  static Statistics::fieldType_t fieldEnum_;
86  static const char* fieldName_;
87  static const char* shortName_;
88 };
89 template <class T>
90 fieldType_t StatisticFieldType<T>::fieldEnum_ = 0;
91 template <class T>
92 const char* StatisticFieldType<T>::fieldName_ = nullptr;
93 template <class T>
94 const char* StatisticFieldType<T>::shortName_ = nullptr;
95 
97 {
98 public:
99  using fieldType_t = ::SST::Statistics::fieldType_t;
100  using fieldHandle_t = int32_t;
101 
102 public:
103  /** Construct a StatisticFieldInfo
104  * @param statName - Name of the statistic registering this field.
105  * @param fieldName - Name of the Field to be assigned.
106  * @param fieldType - Data type of the field.
107  */
108  StatisticFieldInfo(const char* statName, const char* fieldName, fieldType_t fieldType);
109 
110  // Get Field Data
111  /** Return the statistic name related to this field info */
112  inline const std::string& getStatName() const { return m_statName; }
113  /** Return the field name related to this field info */
114  inline const std::string& getFieldName() const { return m_fieldName; }
115  /** Return the field type related to this field info */
116  fieldType_t getFieldType() const { return m_fieldType; }
117  /** Return the field type related to this field info */
118  std::string getFieldUniqueName() const;
119 
120  /** Compare two field info structures
121  * @param FieldInfo1 - a FieldInfo to compare against.
122  * @return True if the Field Info structures are the same.
123  */
124  bool operator==(StatisticFieldInfo& FieldInfo1);
125 
126  /** Set the field handle
127  * @param handle - The assigned field handle for this FieldInfo
128  */
129  void setFieldHandle(fieldHandle_t handle) { m_fieldHandle = handle; }
130 
131  /** Get the field handle
132  * @return The assigned field handle.
133  */
134  fieldHandle_t getFieldHandle() { return m_fieldHandle; }
135 
136  static const char* getFieldTypeShortName(fieldType_t type)
137  {
138  return StatisticFieldTypeBase::getField(type)->shortName();
139  }
140 
141  static const char* getFieldTypeFullName(fieldType_t type)
142  {
143  return StatisticFieldTypeBase::getField(type)->fieldName();
144  }
145 
146  template <typename T>
147  static fieldType_t getFieldTypeFromTemplate()
148  {
149  return StatisticFieldType<T>::id();
150  }
151 
152 protected:
153  StatisticFieldInfo() {} // For serialization only
154 
155 private:
156  std::string m_statName;
157  std::string m_fieldName;
158  fieldType_t m_fieldType;
159  fieldHandle_t m_fieldHandle;
160 };
161 
162 } // namespace Statistics
163 } // namespace SST
164 
165 #endif // SST_CORE_STATAPI_STATFIELDINFO_H
The class for representing Statistic Output Fields.
Definition: statfieldinfo.h:96
const std::string & getStatName() const
Return the statistic name related to this field info.
Definition: statfieldinfo.h:112
Definition: action.cc:18
fieldHandle_t getFieldHandle()
Get the field handle.
Definition: statfieldinfo.h:134
std::string getFieldUniqueName() const
Return the field type related to this field info.
Definition: statfieldinfo.cc:41
void setFieldHandle(fieldHandle_t handle)
Set the field handle.
Definition: statfieldinfo.h:129
fieldType_t getFieldType() const
Return the field type related to this field info.
Definition: statfieldinfo.h:116
bool operator==(StatisticFieldInfo &FieldInfo1)
Compare two field info structures.
Definition: statfieldinfo.cc:35
StatisticFieldInfo(const char *statName, const char *fieldName, fieldType_t fieldType)
Construct a StatisticFieldInfo.
Definition: statfieldinfo.cc:26
const std::string & getFieldName() const
Return the field name related to this field info.
Definition: statfieldinfo.h:114
Definition: statfieldinfo.h:31
Definition: statfieldinfo.h:57