17 #if defined(DD4HEP_ROOT_VERSION_5)
23 using namespace DD4hep;
26 inline int* s_debug_value() {
27 static int s_debug_value = ::getenv(
"DD4HEP_TRACE") == 0 ? 0 : 1;
28 return &s_debug_value;
32 bool PluginService::debug() {
33 return *s_debug_value() ?
true :
false;
36 bool PluginService::setDebug(
bool new_value) {
37 int *ptr = s_debug_value();
38 bool old_value = *ptr;
39 *ptr = new_value ? 1 : 0;
43 #if !defined(DD4HEP_PARSERS_NO_ROOT) && DD4HEP_ROOT_VERSION_5
46 PluginDebug::PluginDebug(
int dbg)
48 m_debug = ROOT::Reflex::PluginService::Debug();
49 ROOT::Reflex::PluginService::SetDebug(dbg);
54 ROOT::Reflex::PluginService::SetDebug (
m_debug);
59 ROOT::Reflex::Scope factories = ROOT::Reflex::Scope::ByName(PLUGINSVC_FACTORY_NS);
60 string factoryname = ROOT::Reflex::PluginService::FactoryName(name);
61 string msg =
"\t\tNo factory with name " + factoryname +
" for type " + name +
" found.\n"
62 "\t\tPlease check library load path and/or plugin factory name.";
70 #else // ROOT 6 or no ROOT at all
72 #if !defined(DD4HEP_PARSERS_NO_ROOT)
80 struct PluginInterface {
82 int (*setDebug)(
int new_value);
83 void* (*create)(
const char* identifier,
const char* signature);
84 void (*add)(
const char* identifier,
86 const char* signature,
87 const char* return_type);
89 static PluginInterface& instance() {
90 static PluginInterface s_instance;
96 static inline T get_func(
void*
handle,
const char* plugin,
const char* entry) {
97 #if !defined(DD4HEP_PARSERS_NO_ROOT)
103 if ( !fp.fptr.ptr ) fp.fptr.ptr = ::dlsym(0, entry);
105 if ( 0 == fp.fptr.ptr ) {
106 string err =
"DD4hep:PluginService: Failed to access symbol "
107 "\""+string(entry)+
"\" in plugin library "+string(plugin)+
108 " ["+string(::strerror(errno))+
"]";
109 throw runtime_error(err);
114 PluginInterface::PluginInterface() : getDebug(0), setDebug(0), create(0), add(0) {
116 const char* plugin_name = ::getenv(
"DD4HEP_PLUGINMGR");
117 if ( 0 == plugin_name ) {
118 plugin_name =
"libDD4hepGaudiPluginMgr";
120 #if !defined(DD4HEP_PARSERS_NO_ROOT)
121 gSystem->Load(plugin_name);
123 handle = ::dlopen(plugin_name, RTLD_LAZY | RTLD_GLOBAL);
125 getDebug = get_func< int (*) ()>(
handle, plugin_name,
"dd4hep_pluginmgr_getdebug");
126 setDebug = get_func< int (*) (int)>(
handle, plugin_name,
"dd4hep_pluginmgr_getdebug");
127 create = get_func<
void* (*) (
const char*,
128 const char*)>(handle, plugin_name,
"dd4hep_pluginmgr_create");
129 add = get_func< void (*) (
const char* identifier,
131 const char* signature,
132 const char* return_type)>(handle, plugin_name,
"dd4hep_pluginmgr_add_factory");
138 m_debug = PluginInterface::instance().setDebug(dbg);
143 PluginInterface::instance().setDebug(
m_debug);
148 string factoryname =
"Create("+name+
")";
149 string msg =
"\t\tNo factory with name " + factoryname +
" for type " + name +
" found.\n"
150 "\t\tPlease check library load path and/or plugin factory name.";
155 return PluginInterface::instance().create(
id.c_str(), info.name());
159 const std::type_info& signature_type,
160 const std::type_info& return_type)
163 printout(
INFO,
"PluginService",
"+++ Declared factory[%s] with signature %s type:%s.",
164 id.c_str(),signature_type.name(),return_type.name());
166 PluginInterface::instance().add(
id.c_str(),stub,signature_type.name(),return_type.name());
170 #if !defined(DD4HEP_PARSERS_NO_ROOT)
std::string missingFactory(const std::string &name) const
Helper to check factory existence.
#define DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(X, Y)
static bool setDebug(bool new_value)
Implementation of a named object.
~PluginDebug()
Default destructor.
static void * getCreator(const std::string &id, const std::type_info &info)
The base class for all DD4hep geometry crawlers.
static void addFactory(const std::string &id, stub_t func, const std::type_info &signature_type, const std::type_info &return_type)
PluginDebug(int dbg=2)
Default constructor.
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
The main interface to the DD4hep detector description package.
Class to easily access the properties of single XmlElements.
void handle(const O *o, const C &c, F pmf)
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.