DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
PluginCreators.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
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 // Framework include files
15 #include <DD4hep/PluginCreators.h>
16 #include <DD4hep/Primitives.h>
17 #include <DD4hep/Printout.h>
18 #include <DD4hep/Plugins.h>
19 
20 // C/C++ include files
21 #include <cstring>
22 //#include <dlfcn.h>
23 
25 namespace dd4hep {
26 
27  static inline ComponentCast* component(void* p) { return (ComponentCast*)p; }
28 
29  void* createProcessor(Detector& description, int argc, char** argv, void* (*cast)(void*)) {
30  void* processor = 0;
31  if ( argc < 2 ) {
32  except("createProcessor","++ dd4hep-plugins: No processor creator name given!");
33  }
34  for(int i=0; i<argc; ++i) {
35  if ( 0 == ::strncmp(argv[i],"-processor",4) ) {
36  std::vector<char*> args;
37  std::string fac = argv[++i];
38  for(int j=++i; j<argc && argv[j] &&
39  0 != ::strncmp(argv[j],"-processor",4) &&
40  0 != ::strncmp(argv[j],"-end-processor",8); ++j)
41  args.emplace_back(argv[j]);
42  int num_arg = int(args.size());
43  args.emplace_back(nullptr);
44  processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]);
45  if ( !processor ) {
46  PluginDebug dbg;
47  processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]);
48  if ( !processor ) {
49  except("createProcessor","dd4hep-plugins: Failed to locate plugin %s. \n%s %s",
50  fac.c_str(), dbg.missingFactory(fac).c_str(),
51  /* ::dlerror() ? ::dlerror() : */ "");
52  }
53  }
54  if ( cast ) {
55  void* obj = cast(processor);
56  if ( obj ) return obj;
57  ComponentCast* c = component(processor);
58  invalidHandleAssignmentError(typeid(cast),typeid(*c));
59  }
60  }
61  }
62  if ( !processor ) {
63  except("createProcessor",
64  "dd4hep-plugins: Found arguments in plugin call, but could not make any sense of them: %s",
65  arguments(argc,argv).c_str());
66  }
67  return processor;
68  }
69 
70  void* createPlugin(const std::string& factory, Detector& description, int argc, char** argv, void* (*cast)(void*)) {
71  void* object = PluginService::Create<void*>(factory, &description, argc, argv);
72  if ( !object ) {
73  PluginDebug dbg;
74  object = PluginService::Create<void*>(factory, &description, argc, argv);
75  if ( !object ) {
76  except("createPlugin","dd4hep-plugins: Failed to locate plugin %s. \n%s.",
77  factory.c_str(), dbg.missingFactory(factory).c_str());
78  }
79  }
80  if ( cast ) {
81  void* obj = cast(object);
82  if ( obj ) return obj;
83  ComponentCast* c = component(object);
84  invalidHandleAssignmentError(typeid(cast),typeid(*c));
85  }
86  return object;
87  }
88 
90  void* createPlugin(const std::string& factory, Detector& description, void* (*cast)(void*)) {
91  char* argv[] = {0};
92  int argc = 0;
93  return createPlugin(factory, description, argc, argv, cast);
94  }
96  void* createPlugin(const std::string& factory,
97  Detector& description,
98  const std::string& arg,
99  void* (*cast)(void*)) {
100  char* argv[] = { (char*)arg.c_str(), 0 };
101  int argc = 1;
102  return createPlugin(factory, description, argc, argv, cast);
103  }
104 
105 }
dd4hep::createProcessor
void * createProcessor(Detector &description, int argc, char **argv, void *(*cast)(void *))
Definition: PluginCreators.cpp:29
dd4hep::createPlugin
void * createPlugin(const std::string &factory, Detector &description, void *(*cast)(void *))
Handler for factories of type: ConstructionFactory.
Definition: PluginCreators.cpp:90
Plugins.h
dd4hep::PluginDebug
Helper to debug plugin manager calls.
Definition: Plugins.h:74
dd4hep::PluginDebug::missingFactory
std::string missingFactory(const std::string &name) const
Helper to check factory existence.
Definition: Plugins.cpp:147
Primitives.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
Printout.h
PluginCreators.h