![]() |
|
|
Generated: 18 Jul 2008 |
#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 <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <exception>
#include <ctime>
#include <set>
#include <vector>
#include "DsoUtils.h"
Include dependency graph for genconf.cpp:

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) |
Variables | |
| const std::string | py_tab = " " |
| typedef std::vector<fs::path> LibPathNames_t |
Definition at line 64 of file genconf.cpp.
| typedef std::vector<std::string> Strings_t |
Definition at line 63 of file genconf.cpp.
| int createAppMgr | ( | ) |
Definition at line 861 of file genconf.cpp.
References Gaudi::createApplicationMgr(), IID_IAppMgrUI, IID_IProperty, and SmartIFBase< TYPE >::isValid().
Referenced by configGenerator::genConfig().
00863 { 00864 IInterface* iface = Gaudi::createApplicationMgr(); 00865 SmartIF<IProperty> propMgr ( IID_IProperty, iface ); 00866 SmartIF<IAppMgrUI> appUI ( IID_IAppMgrUI, iface ); 00867 00868 if ( propMgr.isValid() && appUI.isValid() ) { 00869 propMgr->setProperty( "JobOptionsType", "NONE" ); // No joboptions 00870 propMgr->setProperty( "AppName", ""); // No initial printout message 00871 propMgr->setProperty( "OutputLevel", "7"); // No other printout messages 00872 appUI->configure(); 00873 return EXIT_SUCCESS; 00874 } 00875 else { 00876 return EXIT_FAILURE; 00877 } 00878 }
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 180 of file genconf.cpp.
References std::vector< _Tp, _Alloc >::begin(), copy(), cout, std::vector< _Tp, _Alloc >::empty(), std::basic_string< _CharT, _Traits, _Alloc >::empty(), std::vector< _Tp, _Alloc >::end(), endl(), std::find(), std::basic_string< _CharT, _Traits, _Alloc >::find(), flush(), std::ios_base::out, Gaudi::Utils::Histos::path(), std::vector< _Tp, _Alloc >::push_back(), std::vector< _Tp, _Alloc >::reserve(), std::basic_string< _CharT, _Traits, _Alloc >::substr(), std::ios_base::trunc, and std::exception::what().
00182 { 00183 fs::path::default_name_check(fs::native); 00184 fs::path pwd = fs::initial_path(); 00185 fs::path out; 00186 Strings_t libs; 00187 std::string pkgName; 00188 00189 // declare a group of options that will be allowed only on command line 00190 po::options_description generic("Generic options"); 00191 generic.add_options() 00192 ("help,h", 00193 "produce this help message") 00194 ("package-name,p", 00195 po::value<string>(), 00196 "name of the package for which we create the configurables file") 00197 ("input-libraries,i", 00198 po::value<string>(), 00199 "libraries to extract the component configurables from") 00200 ("input-cfg,c", 00201 po::value<string>(), 00202 "path to the cfg file holding the description of the Configurable base " 00203 "classes, the python module holding the Configurable definitions, etc...") 00204 ("output-dir,o", 00205 po::value<string>()->default_value("../genConf"), 00206 "output directory for genconf files.") 00207 ("debug-level,d", 00208 po::value<int>()->default_value(0), 00209 "debug level") 00210 ("load-library,l", 00211 po::value< Strings_t >()->composing(), 00212 "preloading library") 00213 ; 00214 00215 // declare a group of options that will be allowed both on command line 00216 // _and_ in configuration file 00217 po::options_description config("Configuration"); 00218 config.add_options() 00219 ("configurable-module", 00220 po::value<string>()->default_value("AthenaCommon"), 00221 "Name of the module holding the configurable classes") 00222 ("configurable-default-name", 00223 po::value<string>()->default_value("Configurable.DefaultName"), 00224 "Default name for the configurable instance") 00225 ("configurable-algorithm", 00226 po::value<string>()->default_value("ConfigurableAlgorithm"), 00227 "Name of the configurable base class for Algorithm components") 00228 ("configurable-algtool", 00229 po::value<string>()->default_value("ConfigurableAlgTool"), 00230 "Name of the configurable base class for AlgTool components") 00231 ("configurable-auditor", 00232 po::value<string>()->default_value("ConfigurableAuditor"), 00233 "Name of the configurable base class for Auditor components") 00234 ("configurable-service", 00235 po::value<string>()->default_value("ConfigurableService"), 00236 "Name of the configurable base class for Service components") 00237 ; 00238 00239 po::options_description cmdline_options; 00240 cmdline_options.add(generic).add(config); 00241 00242 po::options_description config_file_options; 00243 config_file_options.add(config); 00244 00245 po::options_description visible("Allowed options"); 00246 visible.add(generic).add(config); 00247 00248 po::variables_map vm; 00249 00250 try { 00251 po::store( po::command_line_parser(argc, argv). 00252 options(cmdline_options).run(), 00253 vm ); 00254 00255 po::notify(vm); 00256 00257 // try to read configuration from the optionnally given configuration file 00258 if( vm.count("input-cfg") ) { 00259 string cfgFileName = vm["input-cfg"].as<string>(); 00260 cfgFileName = fs::complete( fs::path( cfgFileName, 00261 fs::native ) ).string(); 00262 std::ifstream ifs( cfgFileName.c_str() ); 00263 po::store( parse_config_file( ifs, config_file_options ), vm ); 00264 } 00265 00266 po::notify(vm); 00267 } 00268 catch ( po::error& err ) { 00269 cout << "ERR0R: error detected while parsing command options: "<< err.what() << endl; 00270 return EXIT_FAILURE; 00271 } 00272 00273 //--- Process command options ----------------------------------------------- 00274 if( vm.count("help")) { 00275 cout << visible << endl; 00276 return EXIT_FAILURE; 00277 } 00278 00279 if( vm.count("package-name") ) { 00280 pkgName = vm["package-name"].as<string>(); 00281 } 00282 else { 00283 cout << "ERROR: 'package-name' required" << endl; 00284 cout << visible << endl; 00285 return EXIT_FAILURE; 00286 } 00287 00288 if( vm.count("input-libraries") ) { 00289 // re-shape the input arguments: 00290 // - removes spurious spaces, 00291 // - split into tokens. 00292 Strings_t inputLibs; 00293 { 00294 string tmp = vm["input-libraries"].as<string>(); 00295 boost::trim(tmp); 00296 boost::split( inputLibs, tmp, 00297 boost::is_any_of(" "), 00298 boost::token_compress_on ); 00299 } 00300 00301 // 00302 libs.reserve( inputLibs.size() ); 00303 for ( Strings_t::const_iterator iLib = inputLibs.begin(); 00304 iLib != inputLibs.end(); 00305 ++iLib ) { 00306 fs::path libPath = fs::path( *iLib, fs::native ); 00307 std::string lib = libPath.leaf().substr(0, libPath.leaf().find('.') ); 00308 if ( 0 == lib.find("lib") ) { 00309 lib = lib.substr(3); // For *NIX remove "lib" 00310 } 00311 // remove duplicates 00312 if ( !lib.empty() && 00313 std::find( libs.begin(), libs.end(), lib ) == libs.end() ) { 00314 libs.push_back( lib ); 00315 } 00316 } //> end loop over input-libraries 00317 if ( libs.empty() ) { 00318 cout << "ERROR: input component library(ies) required !\n" 00319 << "ERROR: 'input-libraries' argument was [" 00320 << vm["input-libraries"].as<string>() 00321 << "]" 00322 << endl; 00323 return EXIT_FAILURE; 00324 } 00325 } 00326 else { 00327 cout << "ERROR: input component library(ies) required" << endl; 00328 cout << visible << endl; 00329 return EXIT_FAILURE; 00330 } 00331 00332 if( vm.count("output-dir") ) { 00333 out = fs::complete( fs::path( vm["output-dir"].as<string>(), 00334 fs::native ) ); 00335 } 00336 00337 if ( vm.count("debug-level") ) { 00338 PluginService::SetDebug( vm["debug-level"].as<int>() ); 00339 } 00340 00341 if ( vm.count("load-library") ) { 00342 Strings_t lLib_list = vm["load-library"].as< Strings_t >(); 00343 for (Strings_t::const_iterator lLib=lLib_list.begin(); 00344 lLib != lLib_list.end(); 00345 ++lLib) { 00346 // load done through ROOT::Reflex helper class 00347 SharedLibrary tmplib(*lLib) ; 00348 tmplib.Load() ; 00349 } 00350 } 00351 00352 00353 if ( !fs::exists( out ) ) { 00354 try { 00355 fs::create_directory(out); 00356 } 00357 catch ( fs::filesystem_error err ) { 00358 cout << "ERR0R: error creating directory: "<< err.what() << endl; 00359 return EXIT_FAILURE; 00360 } 00361 } 00362 00363 cout << ":::::: libraries : [ "; 00364 copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") ); 00365 cout << "] ::::::" << endl; 00366 00367 configGenerator py( pkgName, out.string() ); 00368 py.setConfigurableModule (vm["configurable-module"].as<string>()); 00369 py.setConfigurableDefaultName(vm["configurable-default-name"].as<string>()); 00370 py.setConfigurableAlgorithm (vm["configurable-algorithm"].as<string>()); 00371 py.setConfigurableAlgTool (vm["configurable-algtool"].as<string>()); 00372 py.setConfigurableAuditor (vm["configurable-auditor"].as<string>()); 00373 py.setConfigurableService (vm["configurable-service"].as<string>()); 00374 00375 int sc = EXIT_FAILURE; 00376 try { 00377 sc = py.genConfig( libs ); 00378 } 00379 catch ( exception& e ) { 00380 cout << "ERROR: Could not generate Configurable(s) !\n" 00381 << "ERROR: Got exception: " << e.what() << endl; 00382 return EXIT_FAILURE; 00383 } 00384 00385 if ( EXIT_SUCCESS == sc ) { 00386 // create an empty __init__.py file in the output dir 00387 fstream initPy( ( out / fs::path( "__init__.py" ) ).string().c_str(), 00388 std::ios_base::out|std::ios_base::trunc ); 00389 initPy << "## Hook for " << pkgName << " genConf module\n" << flush; 00390 } 00391 00392 cout << ":::::: libraries : [ "; 00393 copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") ); 00394 cout << "] :::::: [DONE]" << endl; 00395 00396 return sc; 00397 }
const std::string py_tab = " " [static] |
Definition at line 67 of file genconf.cpp.
Referenced by configGenerator::genComponent(), configGenerator::genHeader(), configGenerator::genImport(), and configGenerator::genTrailer().