//----------------------------------------------------------------------------- int configGenerator::genConfig( const Strings_t& libs, const string& userModule ) //----------------------------------------------------------------------------- { //--- Disable checking StatusCode ------------------------------------------- StatusCode::disableChecking(); const Strings_t::const_iterator endLib = libs.end(); const std::string gaudiSvc = "GaudiCoreSvc"; const bool isGaudiSvc = ( std::find( libs.begin(), endLib, gaudiSvc ) != endLib ); //--- Instantiate ApplicationMgr -------------------------------------------- if ( !isGaudiSvc && createAppMgr() ) { cout << "ERROR: ApplicationMgr can not be created. Check environment" << endl; return EXIT_FAILURE; } //--- Iterate over component factories -------------------------------------- Scope factories = Scope::ByName(PLUGINSVC_FACTORY_NS); if ( !factories ) { cout << "ERROR: No PluginSvc factory namespace could be found" << endl; return EXIT_FAILURE; } ISvcLocator* svcLoc = Gaudi::svcLocator(); IInterface* dummySvc = new Service( "DummySvc", svcLoc ); dummySvc->addRef(); bool allGood = true; // iterate over all the requested libraries for ( Strings_t::const_iterator iLib=libs.begin(); iLib != endLib; ++iLib ) { std::cout << ":::: processing library: " << *iLib << "..." << std::endl; // reset state m_importGaudiHandles = false; m_pyBuf.str(""); m_dbBuf.str(""); // Scan the pluginSvc namespace and store the "background" of already // alive components, so we can extract our signal later on set<string> bkgNames; if ( !isGaudiSvc ) { for ( Member_Iterator it = factories.FunctionMember_Begin(); it != factories.FunctionMember_End(); ++it ) { string ident = getId(*it); if ( PluginService::Debug() > 0 ) { cout << "::: " << ident << endl; } bkgNames.insert( ident ); } } const set<string>::const_iterator bkgNamesEnd = bkgNames.end(); //--- Load component library ---------------------------------------------- System::ImageHandle handle; unsigned long err = System::loadDynamicLib( *iLib, &handle ); if ( err != 1 ) { cout << "ERROR: " << System::getLastErrorString() << endl; allGood = false; continue; } for ( Member_Iterator it = factories.FunctionMember_Begin(); it != factories.FunctionMember_End(); ++it ) { const string ident = getId(*it); if ( bkgNames.find(ident) != bkgNamesEnd ) { if ( PluginService::Debug() > 0 ) { cout << "\t==> skipping [" << ident << "]..." << endl; } continue; } // Atlas contributed code (patch #1247) // Skip the generation of configurables if the component does not come // from the same library we are processing (i.e. we found a symbol that // is coming from a library loaded by the linker). // Windows implementation is empty. if ( !DsoUtils::inDso( *it, DsoUtils::libNativeName(*iLib) ) ) { cout << "WARNING: library [" << *iLib << "] requested factory " << "from another library [" << DsoUtils::dsoName(*it) << "]" << " ==> [" << ident << "] !!" << endl; continue; } const string rtype = it->TypeOf().ReturnType().Name(); string type; bool known = true; if ( ident == "ApplicationMgr" ) type = "ApplicationMgr"; else if ( rtype == "IInterface*" ) type = "IInterface"; else if ( rtype == "IAlgorithm*" ) type = "Algorithm"; else if ( rtype == "IService*" ) type = "Service"; else if ( rtype == "IAlgTool*" ) type = "AlgTool"; else if ( rtype == "IAuditor*" ) type = "Auditor"; else if ( rtype == "IConverter*" ) type = "Converter"; else if ( rtype == "DataObject*" ) type = "DataObject"; else type = "Unknown", known = false; string name = ident; // handle possible problems with templated components boost::trim(name); cout << " - component: " << name << endl; if ( type == "IInterface" ) { /// not enough information... /// skip it continue; } if ( type == "Converter" || type == "DataObject" ) { /// no Properties, so don't bother create Configurables... continue; } //if ( type == "ApplicationMgr" ) { /// @FIXME: no Configurable for this component. yet... /// continue; //} if ( !known ) { cout << "WARNING: Unknown (return) type [" << rtype << "] !!\n" << "WARNING: component [" << ident << "] is skipped !" << endl; allGood = false; continue; } string cname = "DefaultName"; vector<void*> args; args.reserve( 3 ); if ( type == "AlgTool" ) { args.resize( 3 ); args[0] = &cname; args[1] = &type; args[2] = dummySvc; } else { args.resize( 2 ); args[0] = &cname; args[1] = svcLoc; } IProperty* prop = 0; try { if ( type == "Algorithm" ) { prop = makeInstance<IAlgorithm>(*it,args); } else if ( type == "Service") { prop = makeInstance<IService>(*it,args); } else if ( type == "AlgTool") { prop = makeInstance<IAlgTool>(*it,args); } else if ( type == "Auditor") { prop = makeInstance<IAuditor>(*it,args); } else if ( type == "ApplicationMgr") { //svcLoc->queryInterface(IProperty::interfaceID(), pp_cast<void>(&prop)); svcLoc->queryInterface(IProperty::interfaceID(), (void**)(&prop)); } else { prop = makeInstance<IInterface>(*it,args); } } catch ( exception& e ) { cout << "ERROR: Error instantiating " << name << " from " << *iLib << endl; cout << "ERROR: Got exception: " << e.what() << endl; allGood = false; continue; } catch ( ... ) { cout << "ERROR: Error instantiating " << name << " from " << *iLib << endl; allGood = false; continue; } if( prop ) { if (genComponent( *iLib, name, type, prop->getProperties() )) { allGood = false; } prop->release(); } else { cout << "ERROR: could not cast IInterface* object to an IProperty* !\n" << "ERROR: return type from PluginSvc is [" << rtype << "]...\n" << "ERROR: NO Configurable will be generated for [" << name << "] !" << endl; allGood = false; } } //> end loop over factories /// /// write-out files for this library /// const std::string pyName = ( fs::path(m_outputDirName) / fs::path(*iLib+"Conf.py") ).string(); const std::string dbName = ( fs::path(m_outputDirName) / fs::path(*iLib+"_confDb.py") ).string(); std::fstream py( pyName.c_str(), std::ios_base::out|std::ios_base::trunc ); std::fstream db( dbName.c_str(), std::ios_base::out|std::ios_base::trunc ); genHeader ( py, db ); if (!userModule.empty()) py << "from " << userModule << " import *" <<endl; genBody ( py, db ); genTrailer( py, db ); } //> end loop over libraries dummySvc->release(); dummySvc = 0; return allGood ? EXIT_SUCCESS : EXIT_FAILURE; }
//----------------------------------------------------------------------------- int configGenerator::genConfig( const Strings_t& libs, const string& userModule ) //----------------------------------------------------------------------------- { //--- Disable checking StatusCode ------------------------------------------- StatusCode::disableChecking(); const Strings_t::const_iterator endLib = libs.end(); const std::string gaudiSvc = "GaudiCoreSvc"; const bool isGaudiSvc = ( std::find( libs.begin(), endLib, gaudiSvc ) != endLib ); //--- Instantiate ApplicationMgr -------------------------------------------- if ( !isGaudiSvc && createAppMgr() ) { cout << "ERROR: ApplicationMgr can not be created. Check environment" << endl; return EXIT_FAILURE; } //--- Iterate over component factories -------------------------------------- using Gaudi::PluginService::Details::Registry; Registry& registry = Registry::instance(); std::set<std::string> bkgNames = registry.loadedFactories(); ISvcLocator* svcLoc = Gaudi::svcLocator(); IInterface* dummySvc = new Service( "DummySvc", svcLoc ); dummySvc->addRef(); bool allGood = true; // iterate over all the requested libraries for ( Strings_t::const_iterator iLib=libs.begin(); iLib != endLib; ++iLib ) { std::cout << ":::: processing library: " << *iLib << "..." << std::endl; // reset state m_importGaudiHandles = false; m_pyBuf.str(""); m_dbBuf.str(""); //--- Load component library ---------------------------------------------- System::ImageHandle handle; unsigned long err = System::loadDynamicLib( *iLib, &handle ); if ( err != 1 ) { cout << "ERROR: " << System::getLastErrorString() << endl; allGood = false; continue; } std::set<std::string> factories = registry.loadedFactories(); for ( std::set<std::string>::iterator it = factories.begin(); it != factories.end(); ++it ) { const string ident = *it; if ( bkgNames.find(ident) != bkgNames.end() ) { if ( Gaudi::PluginService::Details::logger().level() <= 1 ) { cout << "\t==> skipping [" << ident << "]..." << endl; } continue; } const Registry::FactoryInfo info = registry.getInfo(*it); const string rtype = info.rtype; // do not generate configurables for the Reflex-compatible aliases if (info.properties.find("ReflexName") != info.properties.end()) continue; // Atlas contributed code (patch #1247) // Skip the generation of configurables if the component does not come // from the same library we are processing (i.e. we found a symbol that // is coming from a library loaded by the linker). if ( !DsoUtils::inDso( info.ptr, DsoUtils::libNativeName(*iLib) ) ) { cout << "WARNING: library [" << *iLib << "] exposes factory [" << ident << "] which is declared in [" << DsoUtils::dsoName(info.ptr) << "] !!" << endl; continue; } string type; bool known = true; if ( ident == "ApplicationMgr" ) type = "ApplicationMgr"; else if ( rtype == typeid(IInterface*).name() ) type = "IInterface"; else if ( rtype == typeid(IAlgorithm*).name() ) type = "Algorithm"; else if ( rtype == typeid(IService* ).name() ) type = "Service"; else if ( rtype == typeid(IAlgTool* ).name() ) type = "AlgTool"; else if ( rtype == typeid(IAuditor* ).name() ) type = "Auditor"; else if ( rtype == typeid(IConverter*).name() ) type = "Converter"; else if ( rtype == typeid(DataObject*).name() ) type = "DataObject"; else type = "Unknown", known = false; string name = ident; // handle possible problems with templated components boost::trim(name); if ( type == "IInterface" ) { /// not enough information... /// skip it continue; } if ( type == "Converter" || type == "DataObject" ) { /// no Properties, so don't bother create Configurables... continue; } if ( !known ) { cout << "WARNING: Unknown (return) type [" << System::typeinfoName(rtype.c_str()) << "] !!" << " Component [" << ident << "] is skipped !" << endl; continue; } cout << " - component: " << info.className << " ("; if (info.className != name) cout << name << ": "; cout << type << ")" << endl; string cname = "DefaultName"; SmartIF<IProperty> prop; try { if ( type == "Algorithm" ) { prop = SmartIF<IAlgorithm>(Algorithm::Factory::create(ident, cname, svcLoc)); } else if ( type == "Service") { prop = SmartIF<IService>(Service::Factory::create(ident, cname, svcLoc)); } else if ( type == "AlgTool") { prop = SmartIF<IAlgTool>(AlgTool::Factory::create(ident, cname, type, dummySvc)); // FIXME: AlgTool base class increase artificially by 1 the refcount. prop->release(); } else if ( type == "Auditor") { prop = SmartIF<IAuditor>(Auditor::Factory::create(ident, cname, svcLoc)); } else if ( type == "ApplicationMgr") { prop = SmartIF<ISvcLocator>(svcLoc); } else { continue; // unknown } } catch ( exception& e ) { cout << "ERROR: Error instantiating " << name << " from " << *iLib << endl; cout << "ERROR: Got exception: " << e.what() << endl; allGood = false; continue; } catch ( ... ) { cout << "ERROR: Error instantiating " << name << " from " << *iLib << endl; allGood = false; continue; } if( prop ) { if (genComponent( *iLib, name, type, prop->getProperties() )) { allGood = false; } prop.reset(); } else { cout << "ERROR: could not cast IInterface* object to an IProperty* !\n" << "ERROR: return type from PluginSvc is [" << rtype << "]...\n" << "ERROR: NO Configurable will be generated for [" << name << "] !" << endl; allGood = false; } } //> end loop over factories /// /// write-out files for this library /// const std::string pyName = ( fs::path(m_outputDirName) / fs::path(*iLib+"Conf.py") ).string(); const std::string dbName = ( fs::path(m_outputDirName) / fs::path(*iLib+".confdb") ).string(); std::fstream py( pyName.c_str(), std::ios_base::out|std::ios_base::trunc ); std::fstream db( dbName.c_str(), std::ios_base::out|std::ios_base::trunc ); genHeader ( py, db ); if (!userModule.empty()) py << "from " << userModule << " import *" <<endl; genBody ( py, db ); genTrailer( py, db ); } //> end loop over libraries dummySvc->release(); dummySvc = 0; return allGood ? EXIT_SUCCESS : EXIT_FAILURE; }