SST  10.1.0
StructuralSimulationToolkit
componentInfo.h
1 // Copyright 2009-2020 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-2020, 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/sst_types.h"
16 #include "sst/core/params.h"
17 
18 #include <unordered_set>
19 #include <map>
20 #include <string>
21 #include <functional>
22 
23 namespace SST {
24 
25 class LinkMap;
26 class BaseComponent;
27 
28 class ConfigComponent;
29 class ComponentInfoMap;
30 class TimeConverter;
31 
32 namespace Statistics {
33 class StatisticInfo;
34 }
35 
37 
38 public:
39  typedef std::vector<Statistics::StatisticInfo> statEnableList_t; /*!< List of Enabled Statistics */
40 
41 
42  // Share Flags for SubComponent loading
43  static const uint64_t SHARE_PORTS = 0x1;
44  static const uint64_t SHARE_STATS = 0x2;
45  static const uint64_t INSERT_STATS = 0x4;
46 
47 
48  static const uint64_t SHARE_NONE = 0x0;
49 
50 private:
51 
52  // Mask to make sure users are only setting the flags that are
53  // available to them
54  static const uint64_t USER_FLAGS = 0x7;
55 
56  // Friend classes
57  friend class Simulation;
58  friend class BaseComponent;
59  friend class ComponentInfoMap;
60 
61 
62  /**
63  Component ID.
64 
65  SubComponents share the lower bits (defined by macros in
66  sst_types.h) with their Component parent. However, every
67  SubComponent has a unique ID.
68  */
69  const ComponentId_t id;
70 
71 
72  ComponentInfo* parent_info;
73  /**
74  Name of the Component/SubComponent.
75  */
76  const std::string name;
77 
78  /**
79  Type of the Component/SubComponent.
80  */
81  const std::string type;
82 
83  /**
84  LinkMap containing the links assigned to this
85  Component/SubComponent in the python file.
86 
87  This field is not used for SubComponents loaded with
88  loadAnonymousSubComponent().
89  */
90  LinkMap* link_map;
91 
92  /**
93  Pointer to the Component created using this ComponentInfo.
94  */
95  BaseComponent* component;
96 
97  /**
98  SubComponents loaded into the Component/SubComponent.
99  */
100  std::map<ComponentId_t,ComponentInfo> subComponents;
101 
102  /**
103  Parameters defined in the python file for the (Sub)Component.
104 
105  This field is used for only a short time while loading for
106  SubComponents loaded with loadAnonymousSubComponent().
107  For python defined SubComponents, this field is created during
108  python execution.
109  */
110  const Params *params;
111 
112  TimeConverter* defaultTimeBase;
113 
114  statEnableList_t * enabledStats;
115 
116  uint8_t statLoadLevel;
117 
118  std::vector<double> coordinates;
119 
120  uint64_t subIDIndex;
121 
122 
123  // Variables only used by SubComponents
124 
125  /**
126  Name of the slot this SubComponent was loaded into. This field
127  is not used for Components.
128  */
129  const std::string slot_name;
130 
131  /**
132  Index in the slot this SubComponent was loaded into. This field
133  is not used for Components.
134  */
135  int slot_num;
136 
137  /**
138  Sharing flags.
139 
140  Determines whether various data is shared from parent to child.
141  */
142  uint64_t share_flags;
143 
144 
145  bool sharesPorts() {
146  return (share_flags & SHARE_PORTS) != 0;
147  }
148 
149  bool sharesStatistics() {
150  return (share_flags & SHARE_STATS) != 0;
151  }
152 
153  bool canInsertStatistics() {
154  return (share_flags & INSERT_STATS) != 0;
155  }
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,
167  uint64_t share_flags);
168 
169 
170 public:
171  /* Old ELI Style subcomponent constructor */
172  ComponentInfo(const std::string& type, const Params *params, const ComponentInfo *parent_info);
173 
174  /* Anonymous SubComponent */
175  ComponentInfo(ComponentId_t id, ComponentInfo* parent_info, const std::string& type, const std::string& slot_name,
176  int slot_num, uint64_t share_flags/*, const Params& params_in*/);
177 
178  /* New ELI Style */
179  ComponentInfo(ConfigComponent *ccomp, const std::string& name, ComponentInfo* parent_info, LinkMap* link_map);
180  ComponentInfo(ComponentInfo &&o);
181  ~ComponentInfo();
182 
183  bool isAnonymous() {
184  return COMPDEFINED_SUBCOMPONENT_ID_MASK(id);
185  }
186 
187  bool isUser() {
188  return !COMPDEFINED_SUBCOMPONENT_ID_MASK(id);
189  }
190 
191  inline ComponentId_t getID() const { return id; }
192 
193  inline const std::string& getName() const {
194  if ( name.empty() && parent_info ) return parent_info->getName();
195  return name;
196  }
197 
198  inline const std::string& getSlotName() const { return slot_name; }
199 
200  inline int getSlotNum() const { return slot_num; }
201 
202  inline const std::string& getType() const { return type; }
203 
204  inline BaseComponent* getComponent() const { return component; }
205 
206  LinkMap* getLinkMap();
207 
208  inline const Params* getParams() const { return params; }
209 
210  // inline std::map<std::string, ComponentInfo>& getSubComponents() { return subComponents; }
211  inline std::map<ComponentId_t,ComponentInfo>& getSubComponents() { return subComponents; }
212 
213  ComponentInfo* findSubComponent(const std::string& slot, int slot_num);
214  ComponentInfo* findSubComponent(ComponentId_t id);
215  std::vector<LinkId_t> getAllLinkIds() const;
216 
217  uint8_t getStatisticLoadLevel() { return statLoadLevel; }
218 
219  statEnableList_t* getStatEnableList() { return enabledStats; }
220 
221  struct HashName {
222  size_t operator() (const ComponentInfo* info) const {
223  std::hash<std::string> hash;
224  return hash(info->name);
225  }
226  };
227 
228  struct EqualsName {
229  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
230  return lhs->name == rhs->name;
231  }
232  };
233 
234  struct HashID {
235  size_t operator() (const ComponentInfo* info) const {
236  std::hash<ComponentId_t> hash;
237  return hash(info->id);
238  }
239  };
240 
241  struct EqualsID {
242  bool operator() (const ComponentInfo* lhs, const ComponentInfo* rhs) const {
243  return lhs->id == rhs->id;
244  }
245  };
246 
247 };
248 
249 
251 private:
252  std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
253 
254 public:
255  typedef std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID>::const_iterator const_iterator;
256 
257  const_iterator begin() const {
258  return dataByID.begin();
259  }
260 
261  const_iterator end() const {
262  return dataByID.end();
263  }
264 
265  ComponentInfoMap() {}
266 
267  void insert(ComponentInfo* info) {
268  dataByID.insert(info);
269  }
270 
271  ComponentInfo* getByID(const ComponentId_t key) const {
272  ComponentInfo infoKey(COMPONENT_ID_MASK(key), "");
273  auto value = dataByID.find(&infoKey);
274  if ( value == dataByID.end() ) return nullptr;
275  if ( SUBCOMPONENT_ID_MASK(key) != 0 ) {
276  // Looking for a subcomponent
277  return (*value)->findSubComponent(key);
278  }
279  return *value;
280  }
281 
282  bool empty() {
283  return dataByID.empty();
284  }
285 
286  void clear() {
287  for ( auto i : dataByID ) {
288  delete i;
289  }
290  dataByID.clear();
291  }
292 };
293 
294 } //namespace SST
295 
296 #endif // SST_CORE_COMPONENTINFO_H
Main control class for a SST Simulation.
Definition: simulation.h:73
std::vector< Statistics::StatisticInfo > statEnableList_t
Definition: componentInfo.h:39
Maps port names to the Links that are connected to it.
Definition: linkMap.h:28
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:25
Definition: componentInfo.h:241
Definition: componentInfo.h:250
Definition: componentInfo.h:221
Main component object for the simulation.
Definition: baseComponent.h:52
Definition: componentInfo.h:234
Definition: componentInfo.h:228
Parameter store.
Definition: params.h:44
Definition: componentInfo.h:36