00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _SST_CORE_FACTORY_H
00013 #define _SST_CORE_FACTORY_H
00014
00015 #include <sst/core/sst_types.h>
00016 #include <sst/core/serialization.h>
00017
00018 #include <stdio.h>
00019 #include <boost/foreach.hpp>
00020
00021 #include <sst/core/params.h>
00022 #include <sst/core/elemLoader.h>
00023 #include <sst/core/element.h>
00024 #include <sst/core/statapi/statoutput.h>
00025
00026 using namespace SST::Statistics;
00027
00028 namespace SST {
00029
00030 class Component;
00031 class Introspector;
00032 class SimulationBase;
00033
00034
00035
00036
00037
00038 class Factory {
00039 public:
00040
00041
00042
00043
00044
00045 const std::vector<std::string>* GetComponentAllowedPorts(std::string type);
00046
00047
00048
00049
00050
00051
00052
00053
00054 Component* CreateComponent(ComponentId_t id, std::string componentname,
00055 Params& params);
00056
00057
00058
00059
00060
00061
00062 Introspector* CreateIntrospector(std::string introspectorname,
00063 Params& params);
00064
00065
00066
00067
00068 void RequireEvent(std::string eventname);
00069
00070
00071
00072
00073
00074 Module* CreateModule(std::string type, Params& params);
00075
00076
00077
00078
00079
00080
00081 Module* CreateModuleWithComponent(std::string type, Component* comp, Params& params);
00082
00083
00084
00085
00086
00087 Module* CreateCoreModule(std::string type, Params& params);
00088
00089
00090
00091
00092
00093 Module* CreateCoreModuleWithComponent(std::string type, Component* comp, Params& params);
00094
00095
00096
00097
00098
00099
00100 SubComponent* CreateSubComponent(std::string type, Component* comp, Params& params);
00101
00102
00103
00104
00105 partitionFunction GetPartitioner(std::string name);
00106
00107
00108
00109
00110 generateFunction GetGenerator(std::string name);
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 genPythonModuleFunction getPythonModule(std::string name);
00152
00153 bool hasLibrary(std::string elemlib);
00154
00155 void getLoadedLibraryNames(std::set<std::string>& lib_names);
00156 void loadUnloadedLibraries(const std::set<std::string>& lib_names);
00157
00158
00159
00160
00161
00162
00163 StatisticOutput* CreateStatisticOutput(std::string& statOutputType, Params& statOutputParams);
00164
00165
00166
00167
00168
00169
00170 bool DoesComponentInfoStatisticNameExist(const std::string& type, const std::string& statisticName);
00171
00172
00173
00174
00175
00176
00177 bool DoesSubComponentInfoStatisticNameExist(const std::string& type, const std::string& statisticName);
00178
00179
00180
00181
00182
00183
00184 uint8_t GetComponentInfoStatisticEnableLevel(const std::string& type, const std::string& statisticName);
00185
00186
00187
00188
00189
00190
00191 std::string GetComponentInfoStatisticUnits(const std::string& type, const std::string& statisticName);
00192
00193 private:
00194 Module* LoadCoreModule_StatisticOutputs(std::string& type, Params& params);
00195
00196 friend class SST::SimulationBase;
00197
00198 struct ComponentInfo {
00199 const ElementInfoComponent* component;
00200 Params::KeySet_t params;
00201 std::vector<std::string> ports;
00202 std::vector<std::string> statNames;
00203 std::vector<std::string> statUnits;
00204 std::vector<uint8_t> statEnableLevels;
00205
00206 ComponentInfo() {}
00207
00208 ComponentInfo(const ElementInfoComponent *component, Params::KeySet_t params) :
00209 component(component), params(params)
00210 {
00211 const ElementInfoPort *p = component->ports;
00212 while ( NULL != p && NULL != p->name ) {
00213 ports.push_back(p->name);
00214 p++;
00215 }
00216
00217 const ElementInfoStatistic *s = component->stats;
00218 while ( NULL != s && NULL != s->name ) {
00219 statNames.push_back(s->name);
00220 statUnits.push_back(s->units);
00221 statEnableLevels.push_back(s->enableLevel);
00222 s++;
00223 }
00224 }
00225
00226 ComponentInfo(const ComponentInfo& old) : component(old.component), params(old.params), ports(old.ports),
00227 statNames(old.statNames), statUnits(old.statUnits), statEnableLevels(old.statEnableLevels)
00228 { }
00229
00230 ComponentInfo& operator=(const ComponentInfo& old)
00231 {
00232 component = old.component;
00233 params = old.params;
00234 ports = old.ports;
00235 statNames = old.statNames;
00236 statUnits = old.statUnits;
00237 statEnableLevels = old.statEnableLevels;
00238 return *this;
00239 }
00240 };
00241
00242 struct IntrospectorInfo {
00243 const ElementInfoIntrospector* introspector;
00244 Params::KeySet_t params;
00245
00246 IntrospectorInfo() {}
00247
00248 IntrospectorInfo(const ElementInfoIntrospector *introspector,
00249 Params::KeySet_t params) : introspector(introspector), params(params)
00250 { }
00251
00252 IntrospectorInfo(const IntrospectorInfo& old) : introspector(old.introspector), params(old.params)
00253 { }
00254
00255 IntrospectorInfo& operator=(const IntrospectorInfo& old)
00256 {
00257 introspector = old.introspector;
00258 params = old.params;
00259 return *this;
00260 }
00261 };
00262
00263
00264 struct ModuleInfo {
00265 const ElementInfoModule* module;
00266 Params::KeySet_t params;
00267
00268 ModuleInfo() {}
00269
00270 ModuleInfo(const ElementInfoModule *module,
00271 Params::KeySet_t params) : module(module), params(params)
00272 { }
00273
00274 ModuleInfo(const ModuleInfo& old) : module(old.module), params(old.params)
00275 { }
00276
00277 ModuleInfo& operator=(const ModuleInfo& old)
00278 {
00279 module = old.module;
00280 params = old.params;
00281 return *this;
00282 }
00283 };
00284
00285 struct SubComponentInfo {
00286 const ElementInfoSubComponent* subcomponent;
00287 Params::KeySet_t params;
00288 std::vector<std::string> statNames;
00289 std::vector<std::string> statUnits;
00290 std::vector<uint8_t> statEnableLevels;
00291
00292 SubComponentInfo() {}
00293
00294 SubComponentInfo(const ElementInfoSubComponent *subcomponent,
00295 Params::KeySet_t params) : subcomponent(subcomponent), params(params)
00296 {
00297 const ElementInfoStatistic *s = subcomponent->stats;
00298 while ( NULL != s && NULL != s->name ) {
00299 statNames.push_back(s->name);
00300 statUnits.push_back(s->units);
00301 statEnableLevels.push_back(s->enableLevel);
00302 s++;
00303 }
00304 }
00305
00306 SubComponentInfo(const SubComponentInfo& old) : subcomponent(old.subcomponent), params(old.params), statNames(old.statNames), statUnits(old.statUnits), statEnableLevels(old.statEnableLevels)
00307 { }
00308
00309 SubComponentInfo& operator=(const SubComponentInfo& old)
00310 {
00311 subcomponent = old.subcomponent;
00312 params = old.params;
00313 statNames = old.statNames;
00314 statUnits = old.statUnits;
00315 statEnableLevels = old.statEnableLevels;
00316 return *this;
00317 }
00318 };
00319
00320 typedef std::map<std::string, const ElementLibraryInfo*> eli_map_t;
00321 typedef std::map<std::string, ComponentInfo> eic_map_t;
00322 typedef std::map<std::string, const ElementInfoEvent*> eie_map_t;
00323 typedef std::map<std::string, IntrospectorInfo> eii_map_t;
00324 typedef std::map<std::string, ModuleInfo> eim_map_t;
00325 typedef std::map<std::string, SubComponentInfo> eis_map_t;
00326 typedef std::map<std::string, const ElementInfoPartitioner*> eip_map_t;
00327 typedef std::map<std::string, const ElementInfoGenerator*> eig_map_t;
00328
00329 Factory(std::string searchPaths);
00330 ~Factory();
00331
00332 Factory();
00333 Factory(Factory const&);
00334 void operator=(Factory const&);
00335
00336 Params::KeySet_t create_params_set(const ElementInfoParam *params);
00337
00338
00339 const ElementLibraryInfo* findLibrary(std::string name, bool showErrors=true);
00340
00341 const ElementLibraryInfo* loadLibrary(std::string name, bool showErrors=true);
00342
00343 eli_map_t loaded_libraries;
00344 eic_map_t found_components;
00345 eii_map_t found_introspectors;
00346 eie_map_t found_events;
00347 eim_map_t found_modules;
00348 eis_map_t found_subcomponents;
00349 eip_map_t found_partitioners;
00350 eig_map_t found_generators;
00351 std::string searchPaths;
00352 ElemLoader *loader;
00353 std::string loadingComponentType;
00354
00355 std::pair<std::string, std::string> parseLoadName(const std::string& wholename);
00356
00357 friend class boost::serialization::access;
00358 template<class Archive>
00359 void save(Archive & ar, const unsigned int version) const
00360 {
00361 std::vector<std::string> loaded_element_libraries;
00362 loaded_element_libraries.reserve(loaded_libraries.size());
00363 for (eli_map_t::const_iterator i = loaded_libraries.begin() ;
00364 i != loaded_libraries.end() ;
00365 ++i) {
00366 loaded_element_libraries.push_back(i->first);
00367 }
00368 ar & BOOST_SERIALIZATION_NVP(loaded_element_libraries);
00369 }
00370
00371 template<class Archive>
00372 void load(Archive & ar, const unsigned int version)
00373 {
00374 std::vector<std::string> loaded_element_libraries;
00375 ar & BOOST_SERIALIZATION_NVP(loaded_element_libraries);
00376 BOOST_FOREACH(std::string type, loaded_element_libraries) {
00377 if (NULL == findLibrary(type)) {
00378 fprintf(stderr,
00379 "factory::load() failed to load %s\n",
00380 type.c_str());
00381 abort();
00382 }
00383 }
00384 }
00385
00386 template<class Archive>
00387 friend void save_construct_data(Archive & ar,
00388 const Factory * t,
00389 const unsigned int file_version)
00390 {
00391 std::string search_path = t->searchPaths;
00392 ar << BOOST_SERIALIZATION_NVP(search_path);
00393 }
00394
00395 template<class Archive>
00396 friend void load_construct_data(Archive & ar,
00397 Factory * t,
00398 const unsigned int file_version)
00399 {
00400 std::string search_path;
00401 ar >> BOOST_SERIALIZATION_NVP(search_path);
00402 ::new(t)Factory(search_path);
00403 }
00404
00405 BOOST_SERIALIZATION_SPLIT_MEMBER()
00406
00407 protected:
00408 Output &out;
00409 };
00410
00411 }
00412
00413 BOOST_CLASS_EXPORT_KEY(SST::Factory)
00414
00415 #endif // SST_CORE_FACTORY_H