| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

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

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

Definition at line 65 of file genconf.cpp.

## Function Documentation

int createAppMgr | ( |  | ) |

Definition at line 879 of file genconf.cpp.

    00881 {
    00882   IInterface* iface = Gaudi::createApplicationMgr();
    00883   SmartIF<IProperty> propMgr ( iface );
    00884   SmartIF<IAppMgrUI> appUI  ( iface );
    00885
    00886   if ( propMgr.isValid() && appUI.isValid() ) {
    00887     propMgr->setProperty( "JobOptionsType", "NONE" );  // No joboptions
    00888     propMgr->setProperty( "AppName", "");              // No initial printout message
    00889     propMgr->setProperty( "OutputLevel", "7");         // No other printout messages
    00890     appUI->configure();
    00891     return EXIT_SUCCESS;
    00892   }
    00893   else {
    00894     return EXIT_FAILURE;
    00895   }
    00896 }

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

    00403                                          {
    00404       return (m.Properties().HasProperty("id") && (m.Properties().PropertyValue("id").TypeInfo() == typeid(std::string))) ?
    00405              m.Properties().PropertyAsString("id") :
    00406              m.Properties().PropertyAsString("name") ;
    00407 }

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

Definition at line 182 of file genconf.cpp.

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

template<class T>

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

Definition at line 410 of file genconf.cpp.

    00411 {
    00412   Object dummy;
    00413   T* obj;
    00414 #if ROOT_VERSION_CODE < ROOT_VERSION(5,21,6)
    00415   obj = static_cast<T*>(member.Invoke(dummy,args).Address());
    00416 #else
    00417   member.Invoke(dummy,obj,args);
    00418 #endif
    00419   return dynamic_cast<IProperty*>(obj);
    00420 }

## Variable Documentation

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

Definition at line 69 of file genconf.cpp.