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