LDMX Software
PluginFactory.cxx
2
3#include <dlfcn.h>
4
6
8 __attribute((init_priority(500)));
9
10namespace framework {
11
13
14void PluginFactory::registerEventProcessor(const std::string& classname,
15 int classtype,
16 EventProcessorMaker* maker) {
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}
30
32 const std::string& classname, int classtype,
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}
47
48std::vector<std::string> PluginFactory::getEventProcessorClasses() const {
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}
55
56int PluginFactory::getEventProcessorClasstype(const std::string& ct) const {
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}
65
67 const std::string& classname, const std::string& moduleInstanceName,
68 Process& process) {
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}
75
77 const std::string& classname, const std::string& objName,
78 const std::string& tagname, const framework::config::Parameters& params,
79 Process& process) {
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}
86
87void PluginFactory::loadLibrary(const std::string& libname) {
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}
100
101} // namespace framework
Base classes for all user event processing components to extend.
Class which provides a singleton module factory that creates EventProcessor objects.
Base class for all providers of conditions objects.
Base class for all event processing components.
Singleton module factory that creates EventProcessor objects.
void registerConditionsObjectProvider(const std::string &classname, int classtype, ConditionsObjectProviderMaker *maker)
Register a conditions object provider.
ConditionsObjectProvider * 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.
static PluginFactory theFactory_
Factory for creating the plugin objects.
int getEventProcessorClasstype(const std::string &) const
Get the class type for the event processor.
std::vector< std::string > getEventProcessorClasses() const
Get the classes associated with the processor.
std::map< std::string, PluginInfo > moduleInfo_
A map of names to processor containers.
EventProcessor * createEventProcessor(const std::string &classname, const std::string &moduleInstanceName, Process &process)
Make an event processor.
std::set< std::string > librariesLoaded_
A set of names of loaded libraries.
void loadLibrary(const std::string &libname)
Load a library.
void registerEventProcessor(const std::string &classname, int classtype, EventProcessorMaker *maker)
Register the event processor.
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45
EventProcessor * EventProcessorMaker(const std::string &name, Process &process)
Typedef for EventProcessorFactory use.
ConditionsObjectProvider * ConditionsObjectProviderMaker(const std::string &objname, const std::string &tagname, const framework::config::Parameters &params, Process &process)
Typedef for PluginFactory use.
info container to hold classname, class type and maker.