/// Manipulate geometry using facroy converter long LCDDImp::apply(const char* factory_type, int argc, char** argv) { string fac = factory_type; try { long result = PluginService::Create<long>(fac, (LCDD*) this, argc, argv); if (0 == result) { PluginDebug dbg; result = PluginService::Create<long>(fac, (LCDD*) this, argc, argv); if ( 0 == result ) { throw runtime_error("DD4hep: apply-plugin: Failed to locate plugin " + fac + ". " + dbg.missingFactory(fac)); } } result = *(long*) result; if (result != 1) { throw runtime_error("DD4hep: apply-plugin: Failed to execute plugin " + fac); } return result; } catch (const XML::XmlException& e) { throw runtime_error(XML::_toString(e.msg) + "\nDD4hep: XML-DOM Exception with plugin:" + fac); } catch (const exception& e) { throw runtime_error(string(e.what()) + "\nDD4hep: with plugin:" + fac); } catch (...) { throw runtime_error("UNKNOWN exception from plugin:" + fac); } return EINVAL; }
/// Create a solid shape using the plugin mechanism from the attributes of the XML element Solid dd4hep::xml::createShape(Detector& description, const std::string& shape_type, xml::Element element) { string fac = shape_type + "__shape_constructor"; xml::Handle_t solid_elt = element; Solid solid = Solid(PluginService::Create<TObject*>(fac, &description, &solid_elt)); if ( !solid.isValid() ) { PluginDebug dbg; PluginService::Create<TObject*>(fac, &description, &solid_elt); except("xml::createShape","Failed to create solid of type %s [%s]", shape_type.c_str(),dbg.missingFactory(shape_type).c_str()); } return solid; }
void* createPlugin(const std::string& factory, Geometry::LCDD& lcdd, int argc, char** argv, void* (*cast)(void*)) { void* object = PluginService::Create<void*>(factory, &lcdd, argc, argv); if ( !object ) { PluginDebug dbg; object = PluginService::Create<void*>(factory, &lcdd, argc, argv); if ( !object ) { except("ConditionsManager","DD4hep: plugin: Failed to locate plugin %s. [%s].", factory.c_str(), dbg.missingFactory(factory).c_str()); } } if ( cast ) { void* obj = cast(object); if ( obj ) return obj; invalidHandleAssignmentError(typeid(cast),typeid(*component(object))); } return object; }
void* createPlugin(const std::string& factory, Detector& description, int argc, char** argv, void* (*cast)(void*)) { void* object = PluginService::Create<void*>(factory, &description, argc, argv); if ( !object ) { PluginDebug dbg; object = PluginService::Create<void*>(factory, &description, argc, argv); if ( !object ) { except("ConditionsManager","dd4hep-plugins: Failed to locate plugin %s. \n%s.", factory.c_str(), dbg.missingFactory(factory).c_str()); } } if ( cast ) { void* obj = cast(object); if ( obj ) return obj; ComponentCast* c = component(object); invalidHandleAssignmentError(typeid(cast),typeid(*c)); } return object; }
/// Process a given DOM (sub-) tree void DetectorLoad::processXMLElement(const std::string& xmlfile, const xml::Handle_t& xml_root) { string tag = xml_root.tag(); string type = tag + "_XML_reader"; xml::Handle_t handle = xml_root; long result = PluginService::Create<long>(type, m_detDesc, &handle); if (0 == result) { PluginDebug dbg; result = PluginService::Create<long>(type, m_detDesc, &handle); if ( 0 == result ) { throw runtime_error("dd4hep: Failed to locate plugin to interprete files of type" " \"" + tag + "\" - no factory:" + type + ". " + dbg.missingFactory(type)); } } result = *(long*) result; if (result != 1) { throw runtime_error("dd4hep: Failed to parse the XML file " + xmlfile + " with the plugin " + type); } }
void* createProcessor(Detector& description, int argc, char** argv, void* (*cast)(void*)) { void* processor = 0; if ( argc < 2 ) { except("createProcessor","++ dd4hep-plugins: No processor creator name given!"); } for(int i=0; i<argc; ++i) { if ( 0 == ::strncmp(argv[i],"-processor",4) ) { std::vector<char*> args; std::string fac = argv[++i]; for(int j=++i; j<argc && argv[j] && 0 != ::strncmp(argv[j],"-processor",4) && 0 != ::strncmp(argv[j],"-end-processor",8); ++j) args.push_back(argv[j]); int num_arg = int(args.size()); args.push_back(0); processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]); if ( !processor ) { PluginDebug dbg; processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]); if ( !processor ) { except("createProcessor","dd4hep-plugins: Failed to locate plugin %s. \n%s %s", fac.c_str(), dbg.missingFactory(fac).c_str(), /* ::dlerror() ? ::dlerror() : */ ""); } } if ( cast ) { void* obj = cast(processor); if ( obj ) return obj; ComponentCast* c = component(processor); invalidHandleAssignmentError(typeid(cast),typeid(*c)); } } } if ( !processor ) { except("createProcessor", "dd4hep-plugins: Found arguments in plugin call, but could not make any sense of them: %s", arguments(argc,argv).c_str()); } return processor; }
/// Create a volume using the plugin mechanism from the attributes of the XML element Volume dd4hep::xml::createVolume(Detector& description, const std::string& typ, xml::Element element) { if ( !typ.empty() ) { xml_dim_t e(element); string fac = typ + "__volume_constructor"; xml::Handle_t elt = element; TObject* obj = PluginService::Create<TObject*>(fac, &description, &elt); Volume vol = Volume(dynamic_cast<TGeoVolume*>(obj)); if ( !vol.isValid() ) { PluginDebug dbg; PluginService::Create<TObject*>(fac, &description, &elt); except("xml::createShape","Failed to create volume of type %s [%s]", typ.c_str(),dbg.missingFactory(typ).c_str()); } if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr<string>(_U(name)).c_str()); vol.setAttributes(description,e.regionStr(),e.limitsStr(),e.visStr()); return vol; } except("xml::createVolume","Failed to create volume. No materiaWNo type specified!"); return Volume(); }