DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plugins.inl
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DD4HEP_PLUGINS_INL
15 #define DD4HEP_PLUGINS_INL
16 
17 #include "DD4hep/Plugins.h"
18 
19 #if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
20 #include <set>
21 #include <map>
22 #include <list>
23 #include <vector>
24 
25 #ifdef __APPLE__
26 #define Reflex_CollectionProxy 1
27 #endif
28 
29 #include "DD4hep/Printout.h"
30 #include "Reflex/PluginService.h"
31 #include "Reflex/Reflex.h"
32 #include "Reflex/Builder/ReflexBuilder.h"
33 
35 namespace DD4hep {
36 
43  template <typename R> R PluginService::Create(const std::string& name)
44  { return ROOT::Reflex::PluginService::Create<R>(name); }
45 
46  template <typename R, typename A0> R PluginService::Create(const std::string& name, A0 a0)
47  { return ROOT::Reflex::PluginService::Create<R>(name,a0); }
48 
49  template <typename R, typename A0, typename A1>
50  R PluginService::Create(const std::string& name, A0 a0, A1 a1)
51  { return ROOT::Reflex::PluginService::Create<R>(name, a0, a1); }
52 
53  template <typename R, typename A0, typename A1, typename A2>
54  R PluginService::Create(const std::string& name, A0 a0, A1 a1, A2 a2)
55  { return ROOT::Reflex::PluginService::Create<R>(name, a0, a1, a2); }
56 
57  template <typename R, typename A0, typename A1, typename A2, typename A3>
58  R PluginService::Create(const std::string& name, A0 a0, A1 a1, A2 a2, A3 a3)
59  { return ROOT::Reflex::PluginService::Create<R>(name, a0, a1, a2, a3); }
60 
61  template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
62  R PluginService::Create(const std::string& name, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4)
63  { return ROOT::Reflex::PluginService::Create<R>(name, a0, a1, a2, a3, a4); }
64 
65  template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
66  R PluginService::Create(const std::string& name, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
67  { return ROOT::Reflex::PluginService::Create<R>(name, a0, a1, a2, a3, a4, a5); }
68 
69 
77  namespace plugin_signatures_namespace {
78 
79  namespace {
80 
82 
86  template <typename T> union FuncPtr {
87  FuncPtr(T t) { fcn = t; }
88  void* ptr;
89  T fcn;
90  };
92  template <typename T> FuncPtr<T> __func(T t) { return FuncPtr<T>(t); }
93  }
94 
96 
103  template <typename R> void* instantiate_creator ()
104  { return __func(PluginService::Create<R>).ptr; }
105 
106  template <typename R, typename A0> void* instantiate_creator(A0)
107  { return __func(PluginService::Create<R,A0>).ptr; }
108 
109  template <typename R, typename A0, typename A1> void* instantiate_creator(A0,A1)
110  { return __func(PluginService::Create<R,A0,A1>).ptr; }
111 
112  template <typename R, typename A0, typename A1, typename A2>
113  void* instantiate_creator(A0,A1,A2)
114  { return __func(PluginService::Create<R,A0,A1,A2>).ptr; }
115 
116  template <typename R, typename A0, typename A1, typename A2, typename A3>
117  void* instantiate_creator(A0,A1,A2,A3)
118  { return __func(PluginService::Create<R,A0,A1,A2,A3>).ptr; }
119 
120  template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
121  void* instantiate_creator(A0,A1,A2,A3,A4)
122  { return __func(PluginService::Create<R,A0,A1,A2,A3,A4>).ptr; }
123 
124  template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
125  void* instantiate_creator(A0,A1,A2,A3,A4,A5)
126  { return __func(PluginService::Create<R,A0,A1,A2,A3,A4,A5>).ptr; }
127 
128  namespace {
129  template <typename SIGNATURE> static void reflex_plugin(const std::string& name, typename DD4hep::PluginRegistry<SIGNATURE>::stub_t stub) {
130  ROOT::Reflex::Type typ = ROOT::Reflex::TypeBuilder(name.c_str(),ROOT::Reflex::PUBLIC);
131  ROOT::Reflex::Type sig = ROOT::Reflex::FunctionDistiller < SIGNATURE > ::Get();
132  std::string fname = (std::string(PLUGINSVC_FACTORY_NS "::") + ROOT::Reflex::PluginService::FactoryName(name));
133  ROOT::Reflex::FunctionBuilder func(sig, fname.c_str(), stub, 0, "", ROOT::Reflex::PUBLIC);
134  func.AddProperty("name", name).AddProperty("id", name);
135  if ( PluginService::debug() ) {
136  std::string sig_name = sig.Name();
137  printout(INFO,"PluginService","+++ Declared factory for id %s with signature %s.",fname.c_str(),sig_name.c_str());
138  }
139  }
140  }
141 
142  }
143 }
144 
145 #define DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(R, ARGS) namespace DD4hep { \
146  template <> void PluginRegistry< R ARGS >::add(const char* n, stub_t f) \
147  { plugin_signatures_namespace::reflex_plugin< R ARGS >(n,f); } \
148  namespace plugin_signatures_namespace { template void* instantiate_creator<R> ARGS ; }}
149 
150 #endif
151 
152 #endif // DD4HEP_PLUGINS_INL
static bool debug()
Definition: Plugins.cpp:32
static R Create(const std::string &id, Args...args)
Definition: Plugins.h:138
Factory template for the plugin mechanism.
Definition: Plugins.h:146
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111