Skip to content
Snippets Groups Projects
Commit 9b7b5d9b authored by Joseph Boudreau's avatar Joseph Boudreau
Browse files

Derive the senstive detector plugin loader from the parameterized class, GeoPluginLoader

parent 842d35e0
No related branches found
No related tags found
No related merge requests found
......@@ -4,26 +4,6 @@
#ifndef FSLSDPLUGINLOADER_H_
#define FSLSDPLUGINLOADER_H_
#include <string>
class FSLSensitiveDetectorPlugin;
class FSLSDPluginLoader
{
public:
// Constructor:
FSLSDPluginLoader();
// Destructor:
~FSLSDPluginLoader();
// load G4Solid plugin
FSLSensitiveDetectorPlugin *load(const std::string & path) const;
private:
FSLSDPluginLoader(const FSLSDPluginLoader &)=delete;
FSLSDPluginLoader & operator=(const FSLSDPluginLoader &)=delete;
};
#include "GeoModelKernel/GeoPluginLoader.h"
typedef GeoPluginLoader<FSLSensitiveDetectorPlugin> FSLSDPluginLoader;
#endif
#include "FSLSDPluginLoader.h"
#include "FSLSensitiveDetectorPlugin.h"
#include <string>
#include <iostream>
#include <dlfcn.h>
#include <libgen.h>
FSLSDPluginLoader::FSLSDPluginLoader () {
}
FSLSDPluginLoader::~FSLSDPluginLoader () {
}
FSLSensitiveDetectorPlugin *FSLSDPluginLoader::load(const std::string & pString) const {
std::string bNameString=basename ((char *) pString.c_str()); // Strip off the directory
bNameString=bNameString.substr(3); // Strip off leading "lib"
bNameString=bNameString.substr(0,bNameString.find(".")); // Strip off extensions
std::string createFunctionName = std::string("create")+bNameString;
//
// Loads the library:
//
void *handle = dlopen(pString.c_str(),RTLD_NOW);
if (!handle) {
std::cerr << dlerror() << std::endl;
return nullptr;
}
//
// Gets the function
//
void *f = dlsym(handle,createFunctionName.c_str());
if (!f) {
std::cerr << dlerror() << std::endl;
return nullptr;
}
typedef void * (*CreationMethod) ();
CreationMethod F = (CreationMethod) f;
//
//
//
FSLSensitiveDetectorPlugin * factory = (FSLSensitiveDetectorPlugin *) F();
return factory;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment