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