270{
272 ? boost::log::trivial::info
273 : boost::log::trivial::warning );
274
275 fs::path pwd = fs::initial_path();
278 std::string pkgName;
279 std::string userModule;
280
281
282 po::options_description generic( "Generic options" );
283 generic.add_options()( "help,h", "produce this help message" )(
284 "package-name,p", po::value<string>(), "name of the package for which we create the configurables file" )(
285 "input-libraries,i", po::value<string>(), "libraries to extract the component configurables from" )(
286 "input-cfg,c", po::value<string>(),
287 "path to the cfg file holding the description of the Configurable base "
288 "classes, the python module holding the Configurable definitions, etc..." )(
289 "output-dir,o", po::value<string>()->default_value( "../genConfDir" ),
290 "output directory for genconf files." )( "debug-level,d", po::value<int>()->default_value( 0 ), "debug level" )(
291 "load-library,l", po::value<Strings_t>()->composing(), "preloading library" )(
292 "user-module,m", po::value<string>(), "user-defined module to be imported by the genConf-generated one" )(
293 "type", po::value<string>()->default_value( "conf,conf2" ), "comma-separate types of configurables to generate" );
294
295
296
297 po::options_description
config(
"Configuration" );
298 config.add_options()(
"configurable-module", po::value<string>()->default_value(
"AthenaCommon" ),
299 "Name of the module holding the configurable classes" )(
300 "configurable-default-name", po::value<string>()->default_value( "Configurable.DefaultName" ),
301 "Default name for the configurable instance" )( "configurable-algorithm",
302 po::value<string>()->default_value( "ConfigurableAlgorithm" ),
303 "Name of the configurable base class for Algorithm components" )(
304 "configurable-algtool", po::value<string>()->default_value( "ConfigurableAlgTool" ),
305 "Name of the configurable base class for AlgTool components" )(
306 "configurable-auditor", po::value<string>()->default_value( "ConfigurableAuditor" ),
307 "Name of the configurable base class for Auditor components" )(
308 "configurable-service", po::value<string>()->default_value( "ConfigurableService" ),
309 "Name of the configurable base class for Service components" );
310
311 po::options_description cmdline_options;
312 cmdline_options.add( generic ).add( config );
313
314 po::options_description config_file_options;
315 config_file_options.add( config );
316
317 po::options_description visible( "Allowed options" );
318 visible.add( generic ).add( config );
319
320 po::variables_map vm;
321
322 try {
323 po::store( po::command_line_parser( argc, argv ).
options( cmdline_options ).run(), vm );
324
325 po::notify( vm );
326
327
328 if ( vm.contains( "input-cfg" ) ) {
329 string cfgFileName = vm["input-cfg"].as<string>();
330 cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
331 std::ifstream ifs( cfgFileName );
332 po::store( parse_config_file( ifs, config_file_options ), vm );
333 }
334
335 po::notify( vm );
336 } catch ( po::error& err ) {
337 LOG_ERROR <<
"error detected while parsing command options: " << err.what();
338 return EXIT_FAILURE;
339 }
340
341
342 if ( vm.contains( "help" ) ) {
343 cout << visible << endl;
344 return EXIT_FAILURE;
345 }
346
347 if ( vm.contains( "package-name" ) ) {
348 pkgName = vm["package-name"].as<string>();
349 } else {
351 cout << visible << endl;
352 return EXIT_FAILURE;
353 }
354
355 if ( vm.contains( "user-module" ) ) {
356 userModule = vm["user-module"].as<string>();
357 LOG_INFO <<
"INFO: will import user module " << userModule;
358 }
359
360 if ( vm.contains( "input-libraries" ) ) {
361
362
363
364 std::string tmp = vm["input-libraries"].as<std::string>();
365 boost::trim( tmp );
366 boost::split( libs, tmp, boost::is_any_of( " " ), boost::token_compress_on );
367 } else {
368 LOG_ERROR <<
"input component library(ies) required";
369 cout << visible << endl;
370 return EXIT_FAILURE;
371 }
372
373 if ( vm.contains(
"output-dir" ) ) {
out = fs::system_complete( fs::path( vm[
"output-dir"].as<string>() ) ); }
374
375 if ( vm.contains( "debug-level" ) ) { Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() ); }
376
377 if ( vm.contains( "load-library" ) ) {
378 for ( const auto& lLib : vm["load-library"].as<Strings_t>() ) {
379
382 if ( err != 1 )
LOG_WARNING <<
"failed to load: " << lLib;
383 }
384 }
385
386 std::set<conf_t> confTypes;
387 if ( vm.contains( "type" ) ) {
388 for ( const std::string& type : boost::tokenizer{ vm["type"].as<std::string>(), boost::char_separator{ "," } } ) {
389 if ( type == "conf" ) {
390 confTypes.insert( conf_t::CONF );
391 } else if ( type == "conf2" ) {
392 confTypes.insert( conf_t::CONF2 );
393 } else {
394 LOG_ERROR <<
"unknown configurable type: " << type;
395 cout << visible << endl;
396 return EXIT_FAILURE;
397 }
398 }
399 }
400
401 if ( !fs::exists( out ) ) {
402 try {
403 fs::create_directory( out );
404 } catch ( fs::filesystem_error& err ) {
405 LOG_ERROR <<
"error creating directory: " << err.what();
406 return EXIT_FAILURE;
407 }
408 }
409
410 {
411 std::ostringstream
msg;
412 msg <<
":::::: libraries : [ ";
413 std::copy( libs.begin(), libs.end(), std::ostream_iterator<std::string>( msg, " " ) );
416 }
417
419 py.setConfigurableModule( vm["configurable-module"].as<string>() );
420 py.setConfigurableTypes( confTypes );
421 py.setConfigurableDefaultName( vm["configurable-default-name"].as<string>() );
422 py.setConfigurableAlgorithm( vm["configurable-algorithm"].as<string>() );
423 py.setConfigurableAlgTool( vm["configurable-algtool"].as<string>() );
424 py.setConfigurableAuditor( vm["configurable-auditor"].as<string>() );
425 py.setConfigurableService( vm["configurable-service"].as<string>() );
426
427 int sc = EXIT_FAILURE;
428 try {
429 sc = py.genConfig( libs, userModule );
430 } catch ( exception& e ) {
431 cout << "ERROR: Could not generate Configurable(s) !\n"
432 << "ERROR: Got exception: " << e.what() << endl;
433 return EXIT_FAILURE;
434 }
435
436 {
437 std::ostringstream
msg;
438 msg <<
":::::: libraries : [ ";
439 std::copy( libs.begin(), libs.end(), std::ostream_iterator<std::string>( msg, " " ) );
440 msg <<
"] :::::: [DONE]";
442 }
443 return sc;
444}
std::vector< std::string > Strings_t
void init_logging(boost::log::trivial::severity_level level)
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
void * ImageHandle
Definition of an image handle.
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)