| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# genconf.cpp File Reference

`#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"`

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)
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 Documentation

typedef std::vector<fs::path> LibPathNames_t

Definition at line 76 of file genconf.cpp.

typedef std::vector<std::string> Strings_t

Definition at line 75 of file genconf.cpp.

## Function Documentation

int createAppMgr | ( |  | ) |

Definition at line 889 of file genconf.cpp.

    00891 {
    00892   IInterface* iface = Gaudi::createApplicationMgr();
    00893   SmartIF<IProperty> propMgr ( iface );
    00894   SmartIF<IAppMgrUI> appUI  ( iface );
    00895
    00896   if ( propMgr.isValid() && appUI.isValid() ) {
    00897     propMgr->setProperty( "JobOptionsType", "NONE" );  // No job options
    00898     propMgr->setProperty( "AppName", "");              // No initial printout message
    00899     propMgr->setProperty( "OutputLevel", "7");         // No other printout messages
    00900     appUI->configure();
    00901     return EXIT_SUCCESS;
    00902   }
    00903   else {
    00904     return EXIT_FAILURE;
    00905   }
    00906 }

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 413 of file genconf.cpp.

    00413                                          {
    00414       return (m.Properties().HasProperty("id") && (m.Properties().PropertyValue("id").TypeInfo() == typeid(std::string))) ?
    00415              m.Properties().PropertyAsString("id") :
    00416              m.Properties().PropertyAsString("name") ;
    00417 }

int main | ( | int | argc,
|  | char ** | argv |
| ) |  |  |

Definition at line 192 of file genconf.cpp.

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

template<class T>

IProperty* makeInstance | ( | const Member & | member,
|  | const vector< void * > & | args |
| ) |  |  | `[inline]`

Definition at line 420 of file genconf.cpp.

    00421 {
    00422   Object dummy;
    00423   T* obj;
    00424 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6)
    00425   obj = static_cast<T*>(member.Invoke(dummy,args).Address());
    00426 #else
    00427   member.Invoke(dummy,obj,args);
    00428 #endif
    00429   return dynamic_cast<IProperty*>(obj);
    00430 }

## Variable Documentation

const std::string py_tab = " "`[static]`

Definition at line 79 of file genconf.cpp.