| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Typedefs | Functions
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/algorithm/string/replace.hpp"`
`#include "boost/format.hpp"`
`#include "boost/regex.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 "GaudiKernel/Auditor.h"`
`#include "GaudiKernel/AlgTool.h"`
`#include "GaudiKernel/Algorithm.h"`
`#include "GaudiKernel/Time.h"`
`#include <Gaudi/PluginService.h>`
`#include <algorithm>`
`#include <iostream>`
`#include <fstream>`
`#include <sstream>`
`#include <exception>`
`#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)

## Typedef Documentation

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

Definition at line 81 of file genconf.cpp.

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

Definition at line 77 of file genconf.cpp.

## Function Documentation

int createAppMgr | ( |  | ) |

Definition at line 879 of file genconf.cpp.

{
IInterface* iface = Gaudi::createApplicationMgr();
SmartIF<IProperty> propMgr ( iface );
SmartIF<IAppMgrUI> appUI ( iface );
if ( propMgr.isValid() && appUI.isValid() ) {
propMgr->setProperty( "JobOptionsType", "NONE" ); // No job options
propMgr->setProperty( "AppName", ""); // No initial printout message
propMgr->setProperty( "OutputLevel", "7"); // No other printout messages
appUI->configure();
return EXIT_SUCCESS;
}
else {
return EXIT_FAILURE;
}
}

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

Definition at line 201 of file genconf.cpp.

{
fs::path pwd = fs::initial_path();
fs::path out;
Strings_t libs;
std::string pkgName;
std::string userModule;
// declare a group of options that will be allowed only on command line
po::options_description generic("Generic options");
generic.add_options()
("help,h",
"produce this help message")
("package-name,p",
po::value<string>(),
"name of the package for which we create the configurables file")
("input-libraries,i",
po::value<string>(),
"libraries to extract the component configurables from")
("input-cfg,c",
po::value<string>(),
"path to the cfg file holding the description of the Configurable base "
"classes, the python module holding the Configurable definitions, etc...")
("output-dir,o",
po::value<string>()->default_value("../genConf"),
"output directory for genconf files.")
("debug-level,d",
po::value<int>()->default_value(0),
"debug level")
("load-library,l",
po::value< Strings_t >()->composing(),
"preloading library")
("user-module,m",
po::value<string>(),
"user-defined module to be imported by the genConf-generated one")
;
// declare a group of options that will be allowed both on command line
// _and_ in configuration file
po::options_description config("Configuration");
config.add_options()
("configurable-module",
po::value<string>()->default_value("AthenaCommon"),
"Name of the module holding the configurable classes")
("configurable-default-name",
po::value<string>()->default_value("Configurable.DefaultName"),
"Default name for the configurable instance")
("configurable-algorithm",
po::value<string>()->default_value("ConfigurableAlgorithm"),
"Name of the configurable base class for Algorithm components")
("configurable-algtool",
po::value<string>()->default_value("ConfigurableAlgTool"),
"Name of the configurable base class for AlgTool components")
("configurable-auditor",
po::value<string>()->default_value("ConfigurableAuditor"),
"Name of the configurable base class for Auditor components")
("configurable-service",
po::value<string>()->default_value("ConfigurableService"),
"Name of the configurable base class for Service components")
;
po::options_description cmdline_options;
cmdline_options.add(generic).add(config);
po::options_description config_file_options;
config_file_options.add(config);
po::options_description visible("Allowed options");
visible.add(generic).add(config);
po::variables_map vm;
try {
po::store( po::command_line_parser(argc, argv).
options(cmdline_options).run(),
vm );
po::notify(vm);
// try to read configuration from the optionally given configuration file
if( vm.count("input-cfg") ) {
string cfgFileName = vm["input-cfg"].as<string>();
cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
std::ifstream ifs( cfgFileName.c_str() );
po::store( parse_config_file( ifs, config_file_options ), vm );
}
po::notify(vm);
}
catch ( po::error& err ) {
cout << "ERR0R: error detected while parsing command options: "<< err.what() << endl;
return EXIT_FAILURE;
}
//--- Process command options -----------------------------------------------
if( vm.count("help")) {
cout << visible << endl;
return EXIT_FAILURE;
}
if( vm.count("package-name") ) {
pkgName = vm["package-name"].as<string>();
}
else {
cout << "ERROR: 'package-name' required" << endl;
cout << visible << endl;
return EXIT_FAILURE;
}
if( vm.count("user-module") ) {
userModule = vm["user-module"].as<string>();
cout << "INFO: will import user module " << userModule << endl;
}
if( vm.count("input-libraries") ) {
// re-shape the input arguments:
// - removes spurious spaces,
// - split into tokens.
Strings_t inputLibs;
{
string tmp = vm["input-libraries"].as<string>();
boost::trim(tmp);
boost::split( inputLibs, tmp,
boost::is_any_of(" "),
boost::token_compress_on );
}
//
libs.reserve( inputLibs.size() );
for ( Strings_t::const_iterator iLib = inputLibs.begin();
iLib != inputLibs.end();
++iLib ) {
std::string lib = fs::path(*iLib).stem().string();
if ( 0 == lib.find("lib") ) {
lib = lib.substr(3); // For *NIX remove "lib"
}
// remove duplicates
if ( !lib.empty() &&
std::find( libs.begin(), libs.end(), lib ) == libs.end() ) {
libs.push_back( lib );
}
} //> end loop over input-libraries
if ( libs.empty() ) {
cout << "ERROR: input component library(ies) required !\n"
<< "ERROR: 'input-libraries' argument was ["
<< vm["input-libraries"].as<string>()
<< "]"
<< endl;
return EXIT_FAILURE;
}
}
else {
cout << "ERROR: input component library(ies) required" << endl;
cout << visible << endl;
return EXIT_FAILURE;
}
if( vm.count("output-dir") ) {
out = fs::system_complete( fs::path( vm["output-dir"].as<string>() ) );
}
if ( vm.count("debug-level") ) {
Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() );
}
if ( vm.count("load-library") ) {
Strings_t lLib_list = vm["load-library"].as< Strings_t >();
for (Strings_t::const_iterator lLib=lLib_list.begin();
lLib != lLib_list.end();
++lLib) {
// load done through Gaudi helper class
System::ImageHandle tmp; // we ignore the library handle
unsigned long err = System::loadDynamicLib(*lLib, &tmp);
if (err != 1) {
cout << "WARNING: failed to load: "<< *lLib << endl;
}
}
}
if ( !fs::exists( out ) ) {
try {
fs::create_directory(out);
}
catch ( fs::filesystem_error &err ) {
cout << "ERROR: error creating directory: "<< err.what() << endl;
return EXIT_FAILURE;
}
}
cout << ":::::: libraries : [ ";
copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
cout << "] ::::::" << endl;
configGenerator py( pkgName, out.string() );
py.setConfigurableModule (vm["configurable-module"].as<string>());
py.setConfigurableDefaultName(vm["configurable-default-name"].as<string>());
py.setConfigurableAlgorithm (vm["configurable-algorithm"].as<string>());
py.setConfigurableAlgTool (vm["configurable-algtool"].as<string>());
py.setConfigurableAuditor (vm["configurable-auditor"].as<string>());
py.setConfigurableService (vm["configurable-service"].as<string>());
int sc = EXIT_FAILURE;
try {
sc = py.genConfig( libs, userModule );
}
catch ( exception& e ) {
cout << "ERROR: Could not generate Configurable(s) !\n"
<< "ERROR: Got exception: " << e.what() << endl;
return EXIT_FAILURE;
}
if ( EXIT_SUCCESS == sc ) {
// create an empty __init__.py file in the output dir
fstream initPy( ( out / fs::path( "__init__.py" ) ).string().c_str(),
std::ios_base::out|std::ios_base::trunc );
initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
}
cout << ":::::: libraries : [ ";
copy( libs.begin(), libs.end(), ostream_iterator<string>(cout, " ") );
cout << "] :::::: [DONE]" << endl;
return sc;
}