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