13 #ifndef DD4HEP_PLUGINS_H
14 #define DD4HEP_PLUGINS_H
22 #ifndef DD4HEP_PARSERS_NO_ROOT
24 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
25 #define DD4HEP_ROOT_VERSION_5 1
33 template <
typename T>
class Handle;
55 template <
typename T>
static T*
ptr(
const T* p) {
return (
T*)p; }
56 template <
typename T>
static T&
ref(
const T* p) {
return *(
T*)p; }
57 template <
typename T>
static T val(
const T* p) {
return T(*p); }
58 template <
typename T>
static T value(
const void* p) {
return (
T)p; }
59 static const char*
value(
const void* p) {
return (
const char*)(p); }
62 template <>
inline int PluginFactoryBase::value<int>(
const void* p) {
return *(
int*)(p); }
63 template <>
inline long PluginFactoryBase::value<long>(
const void* p) {
return *(
long*)(p); }
64 template <>
inline std::string PluginFactoryBase::value<std::string>(
const void* p) {
return *(std::string*)(p); }
65 template <>
inline const std::string& PluginFactoryBase::value<const std::string&>(
const void* p) {
return *(std::string*)(p); }
100 FUNCTION
function()
const {
return fptr.func; }
110 static bool setDebug(
bool new_value);
112 static void*
getCreator(
const std::string&
id,
const std::type_info& info);
114 const std::type_info& signature_type,
115 const std::type_info& return_type);
117 #if defined(DD4HEP_ROOT_VERSION_5)
118 template <
typename R>
static R
Create(
const std::string& name);
120 template <
typename R,
typename A0>
121 static R
Create(
const std::string& name,A0 a0);
123 template <
typename R,
typename A0,
typename A1>
124 static R
Create(
const std::string& name, A0 a0, A1 a1);
126 template <
typename R,
typename A0,
typename A1,
typename A2>
127 static R
Create(
const std::string& name, A0 a0, A1 a1, A2 a2);
129 template <
typename R,
typename A0,
typename A1,
typename A2,
typename A3>
130 static R
Create(
const std::string& name, A0 a0, A1 a1, A2 a2, A3 a3);
132 template <
typename R,
typename A0,
typename A1,
typename A2,
typename A3,
typename A4>
133 static R
Create(
const std::string& name, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4);
135 template <
typename R,
typename A0,
typename A1,
typename A2,
typename A3,
typename A4,
typename A5>
136 static R
Create(
const std::string& name, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5);
138 template <
typename R,
typename... Args>
static R
Create(
const std::string&
id, Args... args) {
140 return f.
fptr.
ptr ? (*f.
fptr.
fcn)(std::forward<Args>(args)...) : 0;
150 #if defined(DD4HEP_ROOT_VERSION_5)
151 typedef void (*stub_t)(
void *retaddr,
void*,
const std::vector<void*>& arg,
void*);
152 static void add(
const char* name, stub_t stub);
154 template <
typename R,
typename... Args>
static void add(
const std::string&
id, R(*func)(Args...)) {
163 template <
typename P,
typename S>
class Factory {};
166 #if defined(DD4HEP_ROOT_VERSION_5)
167 #define DD4HEP_FACTORY_CALL(type,name,signature) DD4hep::PluginRegistry<signature>::add(name,Factory<type,signature>::wrapper);
172 #define DD4HEP_FACTORY_CALL(type,name,signature) DD4hep::PluginRegistry<signature>::add(name,Factory<type,signature>::call)
173 #define DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(X,Y)
176 #define DD4HEP_OPEN_PLUGIN(ns,name) namespace ns { namespace { struct name {}; } } namespace DD4hep
177 #define DD4HEP_PLUGINSVC_CNAME(name, serial) name##_dict_##serial
178 #define DD4HEP_PLUGINSVC_FACTORY(type,name,signature,serial) \
180 struct DD4HEP_PLUGINSVC_CNAME(__typeFactory__,serial) { \
181 DD4HEP_PLUGINSVC_CNAME(__typeFactory__,serial)() { DD4HEP_FACTORY_CALL(type,#name,signature); } \
182 } DD4HEP_PLUGINSVC_CNAME(s____typeFactory__,serial); \
186 #define DD4HEP_PLUGIN_FACTORY_ARGS_0(R) \
187 template <typename P> class Factory<P, R()> \
188 : public DD4hep::PluginFactoryBase { \
190 static void wrapper(void *ret,void*,const std::vector<void*>& ,void*) { \
191 *(void**)ret = (void*)call(); \
195 template <typename P> inline R Factory<P,R()>::call()
197 #define DD4HEP_PLUGIN_FACTORY_ARGS_1(R,A0) \
198 template <typename P> class Factory<P, R(A0)> \
199 : public DD4hep::PluginFactoryBase { \
201 static void wrapper(void *ret,void*,const std::vector<void*>& a,void*) { \
202 *(void**)ret = (void*)call(value<A0>(a[0])); \
204 static R call(A0 a0); \
206 template <typename P> inline R Factory<P,R(A0)>::call(A0 a0)
208 #define DD4HEP_PLUGIN_FACTORY_ARGS_2(R,A0,A1) \
209 template <typename P> class Factory<P, R(A0,A1)> \
210 : public DD4hep::PluginFactoryBase { \
212 static void wrapper(void *ret,void*,const std::vector<void*>& a,void*) { \
213 *(void**)ret = (void*)call(value<A0>(a[0]),value<A1>(a[1])); \
215 static R call(A0 a0,A1 a1); \
217 template <typename P> inline R Factory<P,R(A0,A1)>::call(A0 a0, A1 a1)
219 #define DD4HEP_PLUGIN_FACTORY_ARGS_3(R,A0,A1,A2) \
220 template <typename P> class Factory<P, R(A0,A1,A2)> \
221 : public DD4hep::PluginFactoryBase { \
223 static void wrapper(void *ret,void*,const std::vector<void*>& a,void*) { \
224 *(void**)ret = (void*)call(value<A0>(a[0]),value<A1>(a[1]),value<A2>(a[2])); \
226 static R call(A0 a0,A1 a1,A2 a2); \
228 template <typename P> inline R Factory<P,R(A0,A1,A2)>::call(A0 a0, A1 a1, A2 a2)
230 #define DD4HEP_PLUGIN_FACTORY_ARGS_4(R,A0,A1,A2,A3) \
231 template <typename P> class Factory<P, R(A0,A1,A2,A3)> \
232 : public DD4hep::PluginFactoryBase { \
234 static void wrapper(void *ret,void*,const std::vector<void*>& a,void*) { \
235 *(void**)ret = (void*)call(value<A0>(a[0]),value<A1>(a[1]),value<A2>(a[2]),value<A3>(a[3])); \
237 static R call(A0 a0,A1 a1,A2 a2, A3 a3); \
239 template <typename P> inline R Factory<P,R(A0,A1,A2,A3)>::call(A0 a0, A1 a1, A2 a2, A3 a3)
241 #define DD4HEP_PLUGIN_FACTORY_ARGS_5(R,A0,A1,A2,A3,A4) \
242 template <typename P> class Factory<P, R(A0,A1,A2,A3,A4)> \
243 : public DD4hep::PluginFactoryBase { \
245 static void wrapper(void *ret,void*,const std::vector<void*>& a,void*) { \
246 *(void**)ret = (void*)call(value<A0>(a[0]),value<A1>(a[1]),value<A2>(a[2]),value<A3>(a[3]),value<A4>(a[4])); \
248 static R call(A0 a0,A1 a1,A2 a2, A3 a3, A4 a4); \
250 template <typename P> inline R Factory<P,R(A0,A1,A2,A3,A4)>::call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4)
std::string missingFactory(const std::string &name) const
Helper to check factory existence.
static FuncPointer< FUNCTION > function(FUNCTION func)
static T & ref(const T *p)
static T make_return(const T &p)
User abstraction class to manipulate XML elements within a document.
static bool setDebug(bool new_value)
static T value(const void *p)
FuncPointer(const FuncPointer &c)
static void add(const std::string &id, R(*func)(Args...))
Factory base class implementing some utilities.
~PluginDebug()
Default destructor.
union DD4hep::PluginService::FuncPointer::@5 fptr
static void * getCreator(const std::string &id, const std::type_info &info)
static R Create(const std::string &id, Args...args)
static void addFactory(const std::string &id, stub_t func, const std::type_info &signature_type, const std::type_info &return_type)
Helper to debug plugin manager calls.
Factory template for the plugin mechanism.
PluginDebug(int dbg=2)
Default constructor.
FuncPointer & operator=(const FuncPointer &c)
static T * ptr(const T *p)
static const char * value(const void *p)
Factory template for the plugin mechanism.
The main interface to the DD4hep detector description package.
Class to easily access the properties of single XmlElements.
FuncPointer(FUNCTION func)
Handle< NamedObject > ref_t