12 #ifndef SST_CORE_FACTORY_H
13 #define SST_CORE_FACTORY_H
15 #include "sst/core/eli/elementinfo.h"
16 #include "sst/core/params.h"
17 #include "sst/core/sst_types.h"
23 extern int main(
int argc,
char** argv);
26 namespace Statistics {
27 class StatisticOutput;
36 class SSTElementPythonModule;
45 static Factory* getFactory() {
return instance; }
51 bool isPortNameValid(
const std::string& type,
const std::string& port_name);
85 bool doesSubComponentExist(
const std::string& type);
101 std::string elemlib, elem;
102 std::tie(elemlib, elem) = parseLoadName(type);
104 requireLibrary(elemlib);
105 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
107 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
109 auto map = lib->getMap();
110 auto* info = lib->getInfo(elem);
112 auto* builderLib = Base::getBuilderLibrary(elemlib);
114 auto* fact = builderLib->getBuilder(elem);
115 if ( fact ) {
return true; }
122 template <
class Base,
int index,
class InfoType>
123 const InfoType& getSimpleInfo(
const std::string& type)
125 static InfoType invalid_ret;
126 std::string elemlib, elem;
127 std::tie(elemlib, elem) = parseLoadName(type);
129 std::stringstream err_os;
130 requireLibrary(elemlib, err_os);
131 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
133 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
135 auto* info = lib->getInfo(elem);
140 if ( cast_info ) {
return cast_info->getSimpleInfo(); }
154 template <
class Base,
class... CtorArgs>
155 Base*
Create(
const std::string& type, CtorArgs&&... args)
157 std::string elemlib, elem;
158 std::tie(elemlib, elem) = parseLoadName(type);
160 std::stringstream err_os;
161 requireLibrary(elemlib, err_os);
162 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
164 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
166 auto* info = lib->getInfo(elem);
168 auto* builderLib = Base::getBuilderLibrary(elemlib);
170 auto* fact = builderLib->getBuilder(elem);
172 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
178 notFound(Base::ELI_baseName(), type, err_os.str());
193 template <
class Base,
class... CtorArgs>
196 std::string elemlib, elem;
197 std::tie(elemlib, elem) = parseLoadName(type);
199 std::stringstream err_os;
200 requireLibrary(elemlib, err_os);
201 std::lock_guard<std::recursive_mutex> lock(factoryMutex);
203 auto* lib = ELI::InfoDatabase::getLibrary<Base>(elemlib);
205 auto map = lib->getMap();
206 auto* info = lib->getInfo(elem);
208 auto* builderLib = Base::getBuilderLibrary(elemlib);
210 auto* fact = builderLib->getBuilder(elem);
213 Base* ret = fact->create(std::forward<CtorArgs>(args)...);
220 notFound(Base::ELI_baseName(), type, err_os.str());
232 template <
class T,
class... Args>
234 const std::string& type,
BaseComponent* comp,
const std::string& statName,
const std::string& stat,
235 Params& params, Args... args)
237 std::string elemlib, elem;
238 std::tie(elemlib, elem) = parseLoadName(type);
240 std::stringstream sstr;
241 requireLibrary(elemlib, sstr);
243 auto* lib = ELI::BuilderDatabase::getLibrary<Statistics::Statistic<T>, Args...>(elemlib);
245 auto* fact = lib->getFactory(elem);
246 if ( fact ) {
return fact->create(comp, statName, stat, params, std::forward<Args>(args)...); }
249 out.
fatal(CALL_INFO, -1,
"can't find requested statistic %s.\n%s\n", type.c_str(), sstr.str().c_str());
264 bool hasLibrary(
const std::string& elemlib, std::ostream& err_os);
265 void requireLibrary(
const std::string& elemlib, std::ostream& err_os);
270 void requireLibrary(
const std::string& elemlib);
272 void getLoadedLibraryNames(std::set<std::string>& lib_names);
273 void loadUnloadedLibraries(
const std::set<std::string>& lib_names);
289 const std::vector<std::string>& GetValidStatistics(
const std::string& compType);
306 friend int ::main(
int argc,
char** argv);
308 void notFound(
const std::string& baseName,
const std::string& type,
const std::string& errorMsg);
310 Factory(
const std::string& searchPaths);
315 void operator=(
Factory const&);
320 bool findLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
322 bool loadLibrary(
const std::string& name, std::ostream& err_os = std::cerr);
324 std::set<std::string> loaded_libraries;
326 std::string searchPaths;
329 std::string loadingComponentType;
331 std::pair<std::string, std::string> parseLoadName(
const std::string& wholename);
333 std::recursive_mutex factoryMutex;
341 #endif // SST_CORE_FACTORY_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:51
Module * CreateModule(const std::string &type, Params ¶ms)
Instantiate a new Module.
Definition: factory.cc:390
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:203
bool isSubComponentLoadableUsingAPI(const std::string &type)
Check to see if a given element type is loadable with a particular API.
Definition: factory.h:99
Base * Create(const std::string &type, CtorArgs &&...args)
General function to create a given base class.
Definition: factory.h:155
Main component object for the simulation.
Definition: component.h:30
bool DoesComponentInfoStatisticNameExist(const std::string &type, const std::string &statisticName)
Determine if a statistic is defined in a components ElementInfoStatistic.
Definition: factory.cc:307
SSTElementPythonModule * getPythonModule(const std::string &name)
Return Python Module creation function.
Definition: factory.cc:532
Forms the template defined base class for statistics gathering within SST.
Definition: elementinfo.h:42
std::string GetComponentInfoStatisticUnits(const std::string &type, const std::string &statisticName)
Get the units of a statistic defined in the component's ElementInfoStatistic.
Definition: factory.cc:361
Base * CreateWithParams(const std::string &type, SST::Params ¶ms, CtorArgs &&...args)
General function to create a given base class.
Definition: factory.h:194
Definition: simpleInfo.h:82
bool hasLibrary(const std::string &elemlib, std::ostream &err_os)
hasLibrary Checks to see if library exists and can be loaded
Definition: factory.cc:558
Module is a tag class used with the loadModule function.
Definition: module.h:21
Class to load Element Libraries.
Definition: elemLoader.h:23
uint8_t GetComponentInfoStatisticEnableLevel(const std::string &type, const std::string &statisticName)
Get the enable level of a statistic defined in the component's ElementInfoStatistic.
Definition: factory.cc:317
Component * CreateComponent(ComponentId_t id, const std::string &componentname, Params ¶ms)
Attempt to create a new Component instantiation.
Definition: factory.cc:189
void fatal(uint32_t line, const char *file, const char *func, int exit_code, const char *format,...) const
Output the fatal message with formatting as specified by the format parameter.
Definition: output.cc:155
Partition::SSTPartitioner * CreatePartitioner(const std::string &name, RankInfo total_ranks, RankInfo my_rank, int verbosity)
Return partitioner function.
Definition: factory.cc:499
void RequireEvent(const std::string &eventname)
Ensure that an element library containing the required event is loaded.
Definition: factory.cc:488
Definition: rankInfo.h:21
Main component object for the simulation.
Definition: baseComponent.h:49
const Params::KeySet_t & getParamNames(const std::string &type)
Get a list of allowed param keys for a given component type.
Definition: factory.cc:150
Base class for Partitioning graphs.
Definition: sstpart.h:31
Parameter store.
Definition: params.h:55
Module * CreateModuleWithComponent(const std::string &type, Component *comp, Params ¶ms)
Instantiate a new Module.
Definition: factory.cc:430
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:209
Class for instantiating Components, Links and the like out of element libraries.
Definition: factory.h:42
Base class for python modules in element libraries.
Definition: element_python.h:128
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:233
bool isPortNameValid(const std::string &type, const std::string &port_name)
Get a list of allowed ports for a given component type.
Definition: factory.cc:99
Statistics::Statistic< T > * CreateStatistic(const std::string &type, BaseComponent *comp, const std::string &statName, const std::string &stat, Params ¶ms, Args...args)
Instantiate a new Statistic.
Definition: factory.h:233
bool DoesSubComponentSlotExist(const std::string &type, const std::string &slotName)
Determine if a SubComponentSlot is defined in a components ElementInfoStatistic.
Definition: factory.cc:227