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