|
Gaudi Framework, version v21r8 |
| Home | Generated: 17 Mar 2010 |
#include "boost/program_options.hpp"#include "boost/filesystem/operations.hpp"#include "boost/filesystem/exception.hpp"#include "boost/filesystem/convenience.hpp"#include "boost/algorithm/string/split.hpp"#include "boost/algorithm/string/classification.hpp"#include "boost/algorithm/string/trim.hpp"#include "boost/algorithm/string/case_conv.hpp"#include "boost/format.hpp"#include "GaudiKernel/System.h"#include "GaudiKernel/ISvcLocator.h"#include "GaudiKernel/IProperty.h"#include "GaudiKernel/IAppMgrUI.h"#include "GaudiKernel/IAlgorithm.h"#include "GaudiKernel/IAlgTool.h"#include "GaudiKernel/IAuditor.h"#include "GaudiKernel/Service.h"#include "GaudiKernel/Bootstrap.h"#include "GaudiKernel/SmartIF.h"#include "GaudiKernel/HashMap.h"#include "GaudiKernel/GaudiHandle.h"#include "Reflex/PluginService.h"#include "Reflex/Reflex.h"#include "Reflex/SharedLibrary.h"#include "RVersion.h"#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <exception>#include <ctime>#include <set>#include <vector>#include "DsoUtils.h"

Go to the source code of this file.
Classes | |
| class | configGenerator |
Typedefs | |
| typedef std::vector< std::string > | Strings_t |
| typedef std::vector< fs::path > | LibPathNames_t |
Functions | |
| int | createAppMgr () |
| int | main (int argc, char **argv) |
| std::string | getId (const Member &m) |
| Given a Reflex::Member object, return the id for the configurable (name or id, if it is a string). | |
| template<class T> | |
| IProperty * | makeInstance (const Member &member, const vector< void * > &args) |
Variables | |
| const std::string | py_tab = " " |
| typedef std::vector<fs::path> LibPathNames_t |
Definition at line 72 of file genconf.cpp.
| typedef std::vector<std::string> Strings_t |
Definition at line 71 of file genconf.cpp.
| int createAppMgr | ( | ) |
Definition at line 885 of file genconf.cpp.
00887 { 00888 IInterface* iface = Gaudi::createApplicationMgr(); 00889 SmartIF<IProperty> propMgr ( iface ); 00890 SmartIF<IAppMgrUI> appUI ( iface ); 00891 00892 if ( propMgr.isValid() && appUI.isValid() ) { 00893 propMgr->setProperty( "JobOptionsType", "NONE" ); // No job options 00894 propMgr->setProperty( "AppName", ""); // No initial printout message 00895 propMgr->setProperty( "OutputLevel", "7"); // No other printout messages 00896 appUI->configure(); 00897 return EXIT_SUCCESS; 00898 } 00899 else { 00900 return EXIT_FAILURE; 00901 } 00902 }
| std::string getId | ( | const Member & | m | ) | [inline] |
Given a Reflex::Member object, return the id for the configurable (name or id, if it is a string).
non-string ids are used for the persistency (DataObjects)
Definition at line 409 of file genconf.cpp.
00409 { 00410 return (m.Properties().HasProperty("id") && (m.Properties().PropertyValue("id").TypeInfo() == typeid(std::string))) ? 00411 m.Properties().PropertyAsString("id") : 00412 m.Properties().PropertyAsString("name") ; 00413 }
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 188 of file genconf.cpp.
00190 { 00191 fs::path::default_name_check(fs::native); 00192 fs::path pwd = fs::initial_path(); 00193 fs::path out; 00194 Strings_t libs; 00195 std::string pkgName; 00196 00197 // declare a group of options that will be allowed only on command line 00198 po::options_description generic("Generic options"); 00199 generic.add_options() 00200 ("help,h", 00201 "produce this help message") 00202 ("package-name,p", 00203 po::value<string>(), 00204 "name of the package for which we create the configurables file") 00205 ("input-libraries,i", 00206 po::value<string>(), 00207 "libraries to extract the component configurables from") 00208 ("input-cfg,c", 00209 po::value<string>(), 00210 "path to the cfg file holding the description of the Configurable base " 00211 "classes, the python module holding the Configurable definitions, etc...") 00212 ("output-dir,o", 00213 po::value<string>()->default_value("../genConf"), 00214 "output directory for genconf files.") 00215 ("debug-level,d", 00216 po::value<int>()->default_value(0), 00217 "debug level") 00218 ("load-library,l", 00219 po::value< Strings_t >()->composing(), 00220 "preloading library") 00221 ; 00222 00223 // declare a group of options that will be allowed both on command line 00224 // _and_ in configuration file 00225 po::options_description config("Configuration"); 00226 config.add_options() 00227 ("configurable-module", 00228 po::value<string>()->default_value("AthenaCommon"), 00229 "Name of the module holding the configurable classes") 00230 ("configurable-default-name", 00231 po::value<string>()->default_value("Configurable.DefaultName"), 00232 "Default name for the configurable instance") 00233 ("configurable-algorithm", 00234 po::value<string>()->default_value("ConfigurableAlgorithm"), 00235 "Name of the configurable base class for Algorithm components") 00236 ("configurable-algtool", 00237 po::value<string>()->default_value("ConfigurableAlgTool"), 00238 "Name of the configurable base class for AlgTool components") 00239 ("configurable-auditor", 00240 po::value<string>()->default_value("ConfigurableAuditor"), 00241 "Name of the configurable base class for Auditor components") 00242 ("configurable-service", 00243 po::value<string>()->default_value("ConfigurableService"), 00244 "Name of the configurable base class for Service components") 00245 ; 00246 00247 po::options_description cmdline_options; 00248 cmdline_options.add(generic).add(config); 00249 00250 po::options_description config_file_options; 00251 config_file_options.add(config); 00252 00253 po::options_description visible("Allowed options"); 00254 visible.add(generic).add(config); 00255 00256 po::variables_map vm; 00257 00258 try { 00259 po::store( po::command_line_parser(argc, argv). 00260 options(cmdline_options).run(), 00261 vm ); 00262 00263 po::notify(vm); 00264 00265 // try to read configuration from the optionally given configuration file 00266 if( vm.count("input-cfg") ) { 00267 string cfgFileName = vm["input-cfg"].as<string>(); 00268 cfgFileName = fs::complete( fs::path( cfgFileName, 00269 fs::native ) ).string(); 00270 std::ifstream ifs( cfgFileName.c_str() ); 00271 po::store( parse_config_file( ifs, config_file_options ), vm ); 00272 } 00273 00274 po::notify(vm); 00275 } 00276 catch ( po::error& err ) { 00277 cout << "ERR0R: error detected while parsing command options: "<< err.what() << endl; 00278 return EXIT_FAILURE; 00279 } 00280 00281 //--- Process command options ----------------------------------------------- 00282 if( vm.count("help")) { 00283 cout << visible << endl; 00284 return EXIT_FAILURE; 00285 } 00286 00287 if( vm.count("package-name") ) { 00288 pkgName = vm["package-name"].as<string>(); 00289 } 00290 else { 00291 cout << "ERROR: 'package-name' required" << endl; 00292 cout << visible << endl; 00293 return EXIT_FAILURE; 00294 } 00295 00296 if( vm.count("input-libraries") ) { 00297 // re-shape the input arguments: 00298 // - removes spurious spaces, 00299 // - split into tokens. 00300 Strings_t inputLibs; 00301 { 00302 string tmp = vm["input-libraries"].as<string>(); 00303 boost::trim(tmp); 00304 boost::split( inputLibs, tmp, 00305 boost::is_any_of(" "), 00306 boost::token_compress_on ); 00307 } 00308 00309 // 00310 libs.reserve( inputLibs.size() ); 00311 for ( Strings_t::const_iterator iLib = inputLibs.begin(); 00312 iLib != inputLibs.end(); 00313 ++iLib ) { 00314 fs::path libPath = fs::path( *iLib, fs::native ); 00315 std::string lib = libPath.leaf().substr(0, libPath.leaf().find('.') ); 00316 if ( 0 == lib.find("lib") ) { 00317 lib = lib.substr(3); // For *NIX remove "lib" 00318 } 00319 // remove duplicates 00320 if ( !lib.empty() && 00321 std::find( libs.begin(), libs.end(), lib ) == libs.end() ) { 00322 libs.push_back( lib ); 00323 } 00324 } //> end loop over input-libraries 00325 if ( libs.empty() ) { 00326 cout << "ERROR: input component library(ies) required !\n" 00327 << "ERROR: 'input-libraries' argument was [" 00328 << vm["input-libraries"].as<string>() 00329 << "]" 00330 << endl; 00331 return EXIT_FAILURE; 00332 } 00333 } 00334 else { 00335 cout << "ERROR: input component library(ies) required" << endl; 00336 cout << visible << endl; 00337 return EXIT_FAILURE; 00338 } 00339 00340 if( vm.count("output-dir") ) { 00341 out = fs::complete( fs::path( vm["output-dir"].as<string>(), 00342 fs::native ) ); 00343 } 00344 00345 if ( vm.count("debug-level") ) { 00346 PluginService::SetDebug( vm["debug-level"].as<int>() ); 00347 } 00348 00349 if ( vm.count("load-library") ) { 00350 Strings_t lLib_list = vm["load-library"].as< Strings_t >(); 00351 for (Strings_t::const_iterator lLib=lLib_list.begin(); 00352 lLib != lLib_list.end(); 00353 ++lLib) { 00354 // load done through ROOT::Reflex helper class 00355 SharedLibrary tmplib(*lLib) ; 00356 tmplib.Load() ; 00357 } 00358 } 00359 00360 00361 if ( !fs::exists( out ) ) { 00362 try { 00363 fs::create_directory(out); 00364 } 00365 catch ( fs::filesystem_error err ) { 00366 cout << "ERR0R: error creating directory: "<< err.what() << endl; 00367 return EXIT_FAILURE; 00368 } 00369 } 00370 00371 cout << ":::::: libraries : [ "; 00372 copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") ); 00373 cout << "] ::::::" << endl; 00374 00375 configGenerator py( pkgName, out.string() ); 00376 py.setConfigurableModule (vm["configurable-module"].as<string>()); 00377 py.setConfigurableDefaultName(vm["configurable-default-name"].as<string>()); 00378 py.setConfigurableAlgorithm (vm["configurable-algorithm"].as<string>()); 00379 py.setConfigurableAlgTool (vm["configurable-algtool"].as<string>()); 00380 py.setConfigurableAuditor (vm["configurable-auditor"].as<string>()); 00381 py.setConfigurableService (vm["configurable-service"].as<string>()); 00382 00383 int sc = EXIT_FAILURE; 00384 try { 00385 sc = py.genConfig( libs ); 00386 } 00387 catch ( exception& e ) { 00388 cout << "ERROR: Could not generate Configurable(s) !\n" 00389 << "ERROR: Got exception: " << e.what() << endl; 00390 return EXIT_FAILURE; 00391 } 00392 00393 if ( EXIT_SUCCESS == sc ) { 00394 // create an empty __init__.py file in the output dir 00395 fstream initPy( ( out / fs::path( "__init__.py" ) ).string().c_str(), 00396 std::ios_base::out|std::ios_base::trunc ); 00397 initPy << "## Hook for " << pkgName << " genConf module\n" << flush; 00398 } 00399 00400 cout << ":::::: libraries : [ "; 00401 copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") ); 00402 cout << "] :::::: [DONE]" << endl; 00403 00404 return sc; 00405 }
| IProperty* makeInstance | ( | const Member & | member, | |
| const vector< void * > & | args | |||
| ) | [inline] |
Definition at line 416 of file genconf.cpp.
00417 { 00418 Object dummy; 00419 T* obj; 00420 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6) 00421 obj = static_cast<T*>(member.Invoke(dummy,args).Address()); 00422 #else 00423 member.Invoke(dummy,obj,args); 00424 #endif 00425 return dynamic_cast<IProperty*>(obj); 00426 }
const std::string py_tab = " " [static] |
Definition at line 75 of file genconf.cpp.