LDMX Software
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
framework::PluginFactory Class Reference

Singleton module factory that creates EventProcessor objects. More...

#include <PluginFactory.h>

Classes

struct  PluginInfo
 info container to hold classname, class type and maker. More...
 

Public Member Functions

void registerEventProcessor (const std::string &classname, int classtype, EventProcessorMaker *maker)
 Register the event processor.
 
void registerConditionsObjectProvider (const std::string &classname, int classtype, ConditionsObjectProviderMaker *maker)
 Register a conditions object provider.
 
std::vector< std::string > getEventProcessorClasses () const
 Get the classes associated with the processor.
 
int getEventProcessorClasstype (const std::string &) const
 Get the class type for the event processor.
 
EventProcessorcreateEventProcessor (const std::string &classname, const std::string &moduleInstanceName, Process &process)
 Make an event processor.
 
ConditionsObjectProvidercreateConditionsObjectProvider (const std::string &classname, const std::string &objName, const std::string &tagname, const framework::config::Parameters &params, Process &process)
 Make a conditions object provider.
 
void loadLibrary (const std::string &libname)
 Load a library.
 

Static Public Member Functions

static PluginFactorygetInstance ()
 Get the factory instance.
 

Private Member Functions

 PluginFactory ()
 Constructor.
 

Private Attributes

std::map< std::string, PluginInfomoduleInfo_
 A map of names to processor containers.
 
std::set< std::string > librariesLoaded_
 A set of names of loaded libraries.
 

Static Private Attributes

static PluginFactory theFactory_
 Factory for creating the plugin objects.
 

Detailed Description

Singleton module factory that creates EventProcessor objects.

Definition at line 26 of file PluginFactory.h.

Constructor & Destructor Documentation

◆ PluginFactory()

framework::PluginFactory::PluginFactory ( )
private

Constructor.

Definition at line 12 of file PluginFactory.cxx.

12{}

Member Function Documentation

◆ createConditionsObjectProvider()

ConditionsObjectProvider * framework::PluginFactory::createConditionsObjectProvider ( const std::string &  classname,
const std::string &  objName,
const std::string &  tagname,
const framework::config::Parameters params,
Process process 
)

Make a conditions object provider.

Parameters
classnameClass name of conditions object provider
objNameName of the object provided (may be overriden internally!)
paramsParameters for the conditoons object provider
processThe process handle

Definition at line 76 of file PluginFactory.cxx.

79 {
80 auto ptr = moduleInfo_.find(classname);
81 if (ptr == moduleInfo_.end() || ptr->second.cop_maker == 0) {
82 return 0;
83 }
84 return ptr->second.cop_maker(objName, tagname, params, process);
85}
std::map< std::string, PluginInfo > moduleInfo_
A map of names to processor containers.

References moduleInfo_.

Referenced by framework::Conditions::createConditionsObjectProvider().

◆ createEventProcessor()

EventProcessor * framework::PluginFactory::createEventProcessor ( const std::string &  classname,
const std::string &  moduleInstanceName,
Process process 
)

Make an event processor.

Parameters
classnameClass name of event processor.
moduleInstanceNameTODO.
processThe process handle

Definition at line 66 of file PluginFactory.cxx.

68 {
69 auto ptr = moduleInfo_.find(classname);
70 if (ptr == moduleInfo_.end() || ptr->second.ep_maker == 0) {
71 return 0;
72 }
73 return ptr->second.ep_maker(moduleInstanceName, process);
74}

References moduleInfo_.

Referenced by framework::Process::Process().

◆ getEventProcessorClasses()

std::vector< std::string > framework::PluginFactory::getEventProcessorClasses ( ) const

Get the classes associated with the processor.

Returns
a vector of strings corresponding to processor classes.

Definition at line 48 of file PluginFactory.cxx.

48 {
49 std::vector<std::string> classes;
50 for (auto ptr : moduleInfo_) {
51 if (ptr.second.ep_maker != 0) classes.push_back(ptr.first);
52 }
53 return classes;
54}

References moduleInfo_.

◆ getEventProcessorClasstype()

int framework::PluginFactory::getEventProcessorClasstype ( const std::string &  ct) const

Get the class type for the event processor.

Parameters
TODO.

Definition at line 56 of file PluginFactory.cxx.

56 {
57 auto ptr = moduleInfo_.find(ct);
58 if (ptr == moduleInfo_.end() || ptr->second.ep_maker == 0) {
59 return 0;
60
61 } else {
62 return ptr->second.classtype;
63 }
64}

References moduleInfo_.

◆ getInstance()

static PluginFactory & framework::PluginFactory::getInstance ( )
inlinestatic

Get the factory instance.

Returns
The factory.

Definition at line 32 of file PluginFactory.h.

32{ return theFactory_; }
static PluginFactory theFactory_
Factory for creating the plugin objects.

References theFactory_.

Referenced by framework::Conditions::createConditionsObjectProvider(), framework::ConditionsObjectProvider::declare(), framework::EventProcessor::declare(), and framework::Process::Process().

◆ loadLibrary()

void framework::PluginFactory::loadLibrary ( const std::string &  libname)

Load a library.

Parameters
libnameThe library to load.

Definition at line 87 of file PluginFactory.cxx.

87 {
88 if (librariesLoaded_.find(libname) != librariesLoaded_.end()) {
89 return; // already loaded
90 }
91
92 void* handle = dlopen(libname.c_str(), RTLD_NOW);
93 if (handle == nullptr) {
94 EXCEPTION_RAISE("LibraryLoadFailure",
95 "Error loading library '" + libname + "':" + dlerror());
96 }
97
98 librariesLoaded_.insert(libname);
99}
std::set< std::string > librariesLoaded_
A set of names of loaded libraries.

References librariesLoaded_.

◆ registerConditionsObjectProvider()

void framework::PluginFactory::registerConditionsObjectProvider ( const std::string &  classname,
int  classtype,
ConditionsObjectProviderMaker maker 
)

Register a conditions object provider.

Parameters
classnameThe name of the class associated with the conditions object provider.
classtypeThe type of class associated with conditions object provider.
makerTODO.

Definition at line 31 of file PluginFactory.cxx.

33 {
34 auto ptr = moduleInfo_.find(classname);
35 if (ptr != moduleInfo_.end()) {
36 EXCEPTION_RAISE("ExistingEventProcessorDefinition",
37 "Already have a module registered with the classname '" +
38 classname + "'");
39 }
40 PluginInfo mi;
41 mi.classname = classname;
42 mi.classtype = classtype;
43 mi.cop_maker = maker;
44 mi.ep_maker = 0;
45 moduleInfo_[classname] = mi;
46}

References moduleInfo_.

Referenced by framework::ConditionsObjectProvider::declare().

◆ registerEventProcessor()

void framework::PluginFactory::registerEventProcessor ( const std::string &  classname,
int  classtype,
EventProcessorMaker maker 
)

Register the event processor.

Parameters
classnameThe name of the class associated with processor.
classtypeThe type of class associated with processor.
makerTODO.

Definition at line 14 of file PluginFactory.cxx.

16 {
17 auto ptr = moduleInfo_.find(classname);
18 if (ptr != moduleInfo_.end()) {
19 EXCEPTION_RAISE("ExistingEventProcessorDefinition",
20 "Already have a module registered with the classname '" +
21 classname + "'");
22 }
23 PluginInfo mi;
24 mi.classname = classname;
25 mi.classtype = classtype;
26 mi.ep_maker = maker;
27 mi.cop_maker = 0;
28 moduleInfo_[classname] = mi;
29}

References moduleInfo_.

Referenced by framework::EventProcessor::declare().

Member Data Documentation

◆ librariesLoaded_

std::set<std::string> framework::PluginFactory::librariesLoaded_
private

A set of names of loaded libraries.

Definition at line 116 of file PluginFactory.h.

Referenced by loadLibrary().

◆ moduleInfo_

std::map<std::string, PluginInfo> framework::PluginFactory::moduleInfo_
private

◆ theFactory_

PluginFactory framework::PluginFactory::theFactory_
staticprivate

Factory for creating the plugin objects.

Definition at line 119 of file PluginFactory.h.

Referenced by getInstance().


The documentation for this class was generated from the following files: