SST  15.1.0
StructuralSimulationToolkit
componentInfo.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_COMPONENTINFO_H
13 #define SST_CORE_COMPONENTINFO_H
14 
15 #include "sst/core/params.h"
16 #include "sst/core/serialization/serializer_fwd.h"
17 #include "sst/core/sst_types.h"
18 #include "sst/core/timeConverter.h"
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <functional>
23 #include <map>
24 #include <string>
25 #include <unordered_set>
26 #include <vector>
27 
28 namespace SST {
29 
30 class BaseComponent;
31 class ComponentInfoMap;
32 class LinkMap;
33 
34 class ConfigPortModule;
35 class ConfigComponent;
36 class ConfigStatistic;
37 
38 class Simulation_impl;
39 
40 namespace Core::Serialization::pvt {
41 class SerializeBaseComponentHelper;
42 } // namespace Core::Serialization::pvt
43 
45 {
46 
47 public:
48  using statEnableList_t = std::vector<ConfigStatistic>; /*!< List of Enabled Statistics */
49 
50  // Share Flags for SubComponent loading
51  static const uint64_t SHARE_PORTS = 0x1;
52  static const uint64_t SHARE_STATS = 0x2;
53  static const uint64_t INSERT_STATS = 0x4;
54  static const uint64_t SHARE_NONE = 0x0;
55 
56 private:
57  // Mask to make sure users are only setting the flags that are
58  // available to them
59  static const uint64_t USER_FLAGS = 0x7;
60 
61  // Friend classes
62  friend class Simulation_impl;
63  friend class BaseComponent;
64  friend class ComponentInfoMap;
66 
67  /**
68  Component ID.
69 
70  SubComponents share the lower bits (defined by macros in
71  sst_types.h) with their Component parent. However, every
72  SubComponent has a unique ID.
73  */
74  const ComponentId_t id_;
75 
76  ComponentInfo* parent_info;
77  /**
78  Name of the Component/SubComponent.
79  */
80  const std::string name;
81 
82  /**
83  Type of the Component/SubComponent.
84  */
85  const std::string type;
86 
87  /**
88  LinkMap containing the links assigned to this
89  Component/SubComponent in the python file.
90 
91  This field is not used for SubComponents loaded with
92  loadAnonymousSubComponent().
93  */
94  LinkMap* link_map;
95 
96  /**
97  Pointer to the Component created using this ComponentInfo.
98  */
99  BaseComponent* component;
100 
101  /**
102  SubComponents loaded into the Component/SubComponent.
103  */
104  std::map<ComponentId_t, ComponentInfo> subComponents;
105 
106  /**
107  Parameters defined in the python file for the (Sub)Component.
108 
109  This field is used for only a short time while loading
110  SubComponents via loadUserSubComponent().
111 
112  This pointer is invalid after simulation wire-up.
113  */
114  Params* params;
115 
116  TimeConverter defaultTimeBase;
117 
118  std::map<std::string, std::vector<ConfigPortModule>>* port_modules_ = nullptr;
119  std::map<StatisticId_t, ConfigStatistic>* stat_configs_ = nullptr;
120  std::map<std::string, StatisticId_t>* enabled_stat_names_ = nullptr;
121  bool enabled_all_stats_ = false;
122  ConfigStatistic* all_stat_config_ = nullptr;
123 
124  uint8_t statLoadLevel;
125 
126  std::vector<double> coordinates;
127 
128  uint64_t subIDIndex;
129 
130  // Variables only used by SubComponents
131 
132  /**
133  Name of the slot this SubComponent was loaded into. This field
134  is not used for Components.
135  */
136  const std::string slot_name;
137 
138  /**
139  Index in the slot this SubComponent was loaded into. This field
140  is not used for Components.
141  */
142  int slot_num;
143 
144  /**
145  Sharing flags.
146 
147  Determines whether various data is shared from parent to child.
148  */
149  uint64_t share_flags;
150 
151  bool sharesPorts() { return (share_flags & SHARE_PORTS) != 0; }
152 
153  bool sharesStatistics() { return (share_flags & SHARE_STATS) != 0; }
154 
155  bool canInsertStatistics() { return (share_flags & INSERT_STATS) != 0; }
156 
157  inline void setComponent(BaseComponent* comp) { component = comp; }
158  // inline void setParent(BaseComponent* comp) { parent = comp; }
159 
160  /* Lookup Key style constructor */
161  ComponentInfo(ComponentId_t id, const std::string& name);
162  void finalizeLinkConfiguration() const;
163  void prepareForComplete() const;
164 
165  ComponentId_t addAnonymousSubComponent(ComponentInfo* parent_info, const std::string& type,
166  const std::string& slot_name, int slot_num, uint64_t share_flags);
167 
168 public:
169  /**
170  Constructor used only for serialization
171  */
172  ComponentInfo();
173 
174  /**
175  Function used to serialize the class
176  */
178  void serialize_comp(SST::Core::Serialization::serializer& ser);
179 
180  /* Old ELI Style subcomponent constructor */
181  ComponentInfo(const std::string& type, const Params* params, const ComponentInfo* parent_info);
182 
183  /* Anonymous SubComponent */
184  ComponentInfo(ComponentId_t id, ComponentInfo* parent_info, const std::string& type, const std::string& slot_name,
185  int slot_num, uint64_t share_flags /*, const Params& params_in*/);
186 
187  /* New ELI Style */
188  ComponentInfo(ConfigComponent* ccomp, const std::string& name, ComponentInfo* parent_info, LinkMap* link_map);
190  ~ComponentInfo();
191 
192  bool isAnonymous() { return COMPDEFINED_SUBCOMPONENT_ID_MASK(id_); }
193 
194  bool isUser() { return !COMPDEFINED_SUBCOMPONENT_ID_MASK(id_); }
195 
196  inline ComponentId_t getID() const { return id_; }
197 
198  inline const std::string& getName() const
199  {
200  if ( name.empty() && parent_info ) return parent_info->getName();
201  return name;
202  }
203 
204  inline const std::string& getParentComponentName() const
205  {
206  // First, get the actual component (parent pointer will be
207  // nullptr).
208  const ComponentInfo* real_comp = this;
209  while ( real_comp->parent_info != nullptr )
210  real_comp = real_comp->parent_info;
211  return real_comp->getName();
212  }
213 
214  /**
215  Get the short name for this SubComponent (name not including
216  any parents, so just slot_name[index])
217  */
218  inline std::string getShortName() const { return name.substr(name.find_last_of(':') + 1); }
219 
220  inline const std::string& getSlotName() const { return slot_name; }
221 
222  inline int getSlotNum() const { return slot_num; }
223 
224  inline const std::string& getType() const { return type; }
225 
226  inline BaseComponent* getComponent() const { return component; }
227 
228  LinkMap* getLinkMap();
229 
230  inline const Params* getParams() const { return params; }
231 
232  // inline std::map<std::string, ComponentInfo>& getSubComponents() { return subComponents; }
233  inline std::map<ComponentId_t, ComponentInfo>& getSubComponents() { return subComponents; }
234 
235  ComponentInfo* findSubComponent(const std::string& slot, int slot_num);
236  ComponentInfo* findSubComponent(ComponentId_t id);
237  bool hasLinks() const;
238 
239  uint8_t getStatisticLoadLevel() { return statLoadLevel; }
240 
241  struct HashName
242  {
243  size_t operator()(const ComponentInfo* info) const
244  {
245  std::hash<std::string> hash;
246  return hash(info->name);
247  }
248  };
249 
250  struct EqualsName
251  {
252  bool operator()(const ComponentInfo* lhs, const ComponentInfo* rhs) const { return lhs->name == rhs->name; }
253  };
254 
255  struct HashID
256  {
257  size_t operator()(const ComponentInfo* info) const
258  {
259  std::hash<ComponentId_t> hash;
260  return hash(info->id_);
261  }
262  };
263 
264  struct EqualsID
265  {
266  bool operator()(const ComponentInfo* lhs, const ComponentInfo* rhs) const { return lhs->id_ == rhs->id_; }
267  };
268 
269  //// Functions used only for testing, they will not create valid
270  //// ComponentInfos for simulation
271 
272  /**
273  (DO NOT USE) Constructor used only for serialization testing
274  */
276  ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter tv = TimeConverter());
277 
278  ComponentInfo* test_addSubComponentInfo(
279  const std::string& name, const std::string& slot_name, TimeConverter tv = TimeConverter());
280 
281  void test_printComponentInfoHierarchy(int index = 0);
282 };
283 
285 {
286 private:
287  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
288 
289 public:
290  using const_iterator =
291  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID>::const_iterator;
292 
293  const_iterator begin() const { return dataByID.begin(); }
294 
295  const_iterator end() const { return dataByID.end(); }
296 
297  ComponentInfoMap() {}
298 
299  void insert(ComponentInfo* info) { dataByID.insert(info); }
300 
301  ComponentInfo* getByID(const ComponentId_t key) const
302  {
303  ComponentInfo infoKey(COMPONENT_ID_MASK(key), "");
304  auto value = dataByID.find(&infoKey);
305  if ( value == dataByID.end() ) return nullptr;
306  if ( SUBCOMPONENT_ID_MASK(key) != 0 ) {
307  // Looking for a subcomponent
308  return (*value)->findSubComponent(key);
309  }
310  return *value;
311  }
312 
313  bool empty() { return dataByID.empty(); }
314 
315  void clear()
316  {
317  for ( auto i : dataByID ) {
318  delete i;
319  }
320  dataByID.clear();
321  }
322 
323  size_t size() { return dataByID.size(); }
324 };
325 
326 } // namespace SST
327 
328 #endif // SST_CORE_COMPONENTINFO_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
Maps port names to the Links that are connected to it.
Definition: linkMap.h:29
std::string getShortName() const
Get the short name for this SubComponent (name not including any parents, so just slot_name[index]) ...
Definition: componentInfo.h:218
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
void serialize_order(SST::Core::Serialization::serializer &ser)
Function used to serialize the class.
Definition: componentInfo.cc:206
Definition: configGraph.h:241
Definition: action.cc:18
std::vector< ConfigStatistic > statEnableList_t
Definition: componentInfo.h:48
Definition: componentInfo.h:264
Definition: componentInfo.h:284
Definition: componentInfo.h:241
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
Main component object for the simulation.
Definition: baseComponent.h:64
Definition: componentInfo.h:255
Definition: componentInfo.h:250
Parameter store.
Definition: params.h:63
ComponentInfo()
Constructor used only for serialization.
Definition: componentInfo.cc:46
Definition: componentInfo.h:44