hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ProcessorFactory.cxx
Go to the documentation of this file.
1
8#include "ProcessorFactory.h"
9
10#include <dlfcn.h>
11
12void ProcessorFactory::registerProcessor(const std::string& classname, ProcessorMaker* maker) {
13 auto ptr = module_info_.find(classname);
14 if (ptr != module_info_.end()) {
15 std::cout << "Error: " << std::endl;
16 }
18 mi.classname = classname;
19 mi.maker = maker;
20 module_info_[classname] = mi;
21}
22
23/*
24std::vector<std::string> ProcessorFactory::getProcessorClasses() const {
25 std::vector<std::string> classes;
26 for (auto ptr : module_info_) {
27 classes.push_back(ptr.first);
28 }
29 return classes;
30}
31*/
32
33Processor* ProcessorFactory::createProcessor(const std::string& classname, const std::string& module_instance_name, Process& process) {
34 auto ptr = module_info_.find(classname);
35 if (ptr == module_info_.end()) {
36 return 0;
37 }
38 return ptr->second.maker(module_instance_name, process);
39}
40
41void ProcessorFactory::loadLibrary(const std::string& libname) {
42
43 std::cout << "[ ProcessorFactory ]: Loading library " << libname << std::endl;
44
45 if (libs_loaded_.find(libname) != libs_loaded_.end()) {
46 return; // already loaded
47 }
48 void* handle = dlopen(libname.c_str(), RTLD_NOW);
49 if (handle == NULL) {
50 std::cout << dlerror() << std::endl;
51 throw std::runtime_error("[ ProcessorFactory ]: Error loading library " + libname + ": " + dlerror());
52 }
53
54 libs_loaded_.insert(libname);
55}
56
Class which provides a singleton module factory that creates Processor objects.
Processor * ProcessorMaker(const std::string &name, Process &process)
Definition Processor.h:28
void loadLibrary(const std::string &libname)
Load a library.
std::map< std::string, ProcessorInfo > module_info_
std::set< std::string > libs_loaded_
void registerProcessor(const std::string &classname, ProcessorMaker *maker)
Register the event processor.
Processor * createProcessor(const std::string &classname, const std::string &module_instance_name, Process &process)
Make an event processor.
Base class for all event processing components.
Definition Processor.h:34
Processor info container to hold classname, class type and maker.