File indexing completed on 2025-01-18 09:13:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/PluginCreators.h>
0016 #include <DD4hep/Primitives.h>
0017 #include <DD4hep/Printout.h>
0018 #include <DD4hep/Plugins.h>
0019
0020
0021 #include <cstring>
0022
0023
0024
0025 namespace dd4hep {
0026
0027 static inline ComponentCast* component(void* p) { return (ComponentCast*)p; }
0028
0029 void* createProcessor(Detector& description, int argc, char** argv, void* (*cast)(void*)) {
0030 void* processor = 0;
0031 if ( argc < 2 ) {
0032 except("createProcessor","++ dd4hep-plugins: No processor creator name given!");
0033 }
0034 for(int i=0; i<argc; ++i) {
0035 if ( 0 == ::strncmp(argv[i],"-processor",4) ) {
0036 std::vector<char*> args;
0037 std::string fac = argv[++i];
0038 for(int j=++i; j<argc && argv[j] &&
0039 0 != ::strncmp(argv[j],"-processor",4) &&
0040 0 != ::strncmp(argv[j],"-end-processor",8); ++j)
0041 args.emplace_back(argv[j]);
0042 int num_arg = int(args.size());
0043 args.emplace_back(nullptr);
0044 processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]);
0045 if ( !processor ) {
0046 PluginDebug dbg;
0047 processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]);
0048 if ( !processor ) {
0049 except("createProcessor","dd4hep-plugins: Failed to locate plugin %s. \n%s %s",
0050 fac.c_str(), dbg.missingFactory(fac).c_str(),
0051 "");
0052 }
0053 }
0054 if ( cast ) {
0055 void* obj = cast(processor);
0056 if ( obj ) return obj;
0057 ComponentCast* c = component(processor);
0058 invalidHandleAssignmentError(typeid(cast),typeid(*c));
0059 }
0060 }
0061 }
0062 if ( !processor ) {
0063 except("createProcessor",
0064 "dd4hep-plugins: Found arguments in plugin call, but could not make any sense of them: %s",
0065 arguments(argc,argv).c_str());
0066 }
0067 return processor;
0068 }
0069
0070 void* createPlugin(const std::string& factory, Detector& description, int argc, char** argv, void* (*cast)(void*)) {
0071 void* object = PluginService::Create<void*>(factory, &description, argc, argv);
0072 if ( !object ) {
0073 PluginDebug dbg;
0074 object = PluginService::Create<void*>(factory, &description, argc, argv);
0075 if ( !object ) {
0076 except("createPlugin","dd4hep-plugins: Failed to locate plugin %s. \n%s.",
0077 factory.c_str(), dbg.missingFactory(factory).c_str());
0078 }
0079 }
0080 if ( cast ) {
0081 void* obj = cast(object);
0082 if ( obj ) return obj;
0083 ComponentCast* c = component(object);
0084 invalidHandleAssignmentError(typeid(cast),typeid(*c));
0085 }
0086 return object;
0087 }
0088
0089
0090 void* createPlugin(const std::string& factory, Detector& description, void* (*cast)(void*)) {
0091 char* argv[] = {0};
0092 int argc = 0;
0093 return createPlugin(factory, description, argc, argv, cast);
0094 }
0095
0096 void* createPlugin(const std::string& factory,
0097 Detector& description,
0098 const std::string& arg,
0099 void* (*cast)(void*)) {
0100 char* argv[] = { (char*)arg.c_str(), 0 };
0101 int argc = 1;
0102 return createPlugin(factory, description, argc, argv, cast);
0103 }
0104
0105 }