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 "no-init", "do not generate the (empty) __init__.py" )(
294 "type", po::value<string>()->default_value( "conf,conf2" ), "comma-separate types of configurables to generate" );
295
296
297
298 po::options_description
config(
"Configuration" );
299 config.add_options()(
"configurable-module", po::value<string>()->default_value(
"AthenaCommon" ),
300 "Name of the module holding the configurable classes" )(
301 "configurable-default-name", po::value<string>()->default_value( "Configurable.DefaultName" ),
302 "Default name for the configurable instance" )( "configurable-algorithm",
303 po::value<string>()->default_value( "ConfigurableAlgorithm" ),
304 "Name of the configurable base class for Algorithm components" )(
305 "configurable-algtool", po::value<string>()->default_value( "ConfigurableAlgTool" ),
306 "Name of the configurable base class for AlgTool components" )(
307 "configurable-auditor", po::value<string>()->default_value( "ConfigurableAuditor" ),
308 "Name of the configurable base class for Auditor components" )(
309 "configurable-service", po::value<string>()->default_value( "ConfigurableService" ),
310 "Name of the configurable base class for Service components" );
311
312 po::options_description cmdline_options;
313 cmdline_options.add( generic ).add( config );
314
315 po::options_description config_file_options;
316 config_file_options.add( config );
317
318 po::options_description visible( "Allowed options" );
319 visible.add( generic ).add( config );
320
321 po::variables_map vm;
322
323 try {
324 po::store( po::command_line_parser( argc, argv ).
options( cmdline_options ).run(), vm );
325
326 po::notify( vm );
327
328
329 if ( vm.contains( "input-cfg" ) ) {
330 string cfgFileName = vm["input-cfg"].as<string>();
331 cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
332 std::ifstream ifs( cfgFileName );
333 po::store( parse_config_file( ifs, config_file_options ), vm );
334 }
335
336 po::notify( vm );
337 } catch ( po::error& err ) {
338 LOG_ERROR <<
"error detected while parsing command options: " << err.what();
339 return EXIT_FAILURE;
340 }
341
342
343 if ( vm.contains( "help" ) ) {
344 cout << visible << endl;
345 return EXIT_FAILURE;
346 }
347
348 if ( vm.contains( "package-name" ) ) {
349 pkgName = vm["package-name"].as<string>();
350 } else {
352 cout << visible << endl;
353 return EXIT_FAILURE;
354 }
355
356 if ( vm.contains( "user-module" ) ) {
357 userModule = vm["user-module"].as<string>();
358 LOG_INFO <<
"INFO: will import user module " << userModule;
359 }
360
361 if ( vm.contains( "input-libraries" ) ) {
362
363
364
365 std::string tmp = vm["input-libraries"].as<std::string>();
366 boost::trim( tmp );
367 boost::split( libs, tmp, boost::is_any_of( " " ), boost::token_compress_on );
368 } else {
369 LOG_ERROR <<
"input component library(ies) required";
370 cout << visible << endl;
371 return EXIT_FAILURE;
372 }
373
374 if ( vm.contains(
"output-dir" ) ) {
out = fs::system_complete( fs::path( vm[
"output-dir"].as<string>() ) ); }
375
376 if ( vm.contains( "debug-level" ) ) { Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() ); }
377
378 if ( vm.contains( "load-library" ) ) {
379 for ( const auto& lLib : vm["load-library"].as<Strings_t>() ) {
380
383 if ( err != 1 )
LOG_WARNING <<
"failed to load: " << lLib;
384 }
385 }
386
387 std::set<conf_t> confTypes;
388 if ( vm.contains( "type" ) ) {
389 for ( const std::string& type : boost::tokenizer{ vm["type"].as<std::string>(), boost::char_separator{ "," } } ) {
390 if ( type == "conf" ) {
391 confTypes.insert( conf_t::CONF );
392 } else if ( type == "conf2" ) {
393 confTypes.insert( conf_t::CONF2 );
394 } else {
395 LOG_ERROR <<
"unknown configurable type: " << type;
396 cout << visible << endl;
397 return EXIT_FAILURE;
398 }
399 }
400 }
401
402 if ( !fs::exists( out ) ) {
403 try {
404 fs::create_directory( out );
405 } catch ( fs::filesystem_error& err ) {
406 LOG_ERROR <<
"error creating directory: " << err.what();
407 return EXIT_FAILURE;
408 }
409 }
410
411 {
412 std::ostringstream
msg;
413 msg <<
":::::: libraries : [ ";
414 std::copy( libs.begin(), libs.end(), std::ostream_iterator<std::string>( msg, " " ) );
417 }
418
420 py.setConfigurableModule( vm["configurable-module"].as<string>() );
421 py.setConfigurableTypes( confTypes );
422 py.setConfigurableDefaultName( vm["configurable-default-name"].as<string>() );
423 py.setConfigurableAlgorithm( vm["configurable-algorithm"].as<string>() );
424 py.setConfigurableAlgTool( vm["configurable-algtool"].as<string>() );
425 py.setConfigurableAuditor( vm["configurable-auditor"].as<string>() );
426 py.setConfigurableService( vm["configurable-service"].as<string>() );
427
428 int sc = EXIT_FAILURE;
429 try {
430 sc = py.genConfig( libs, userModule );
431 } catch ( exception& e ) {
432 cout << "ERROR: Could not generate Configurable(s) !\n"
433 << "ERROR: Got exception: " << e.what() << endl;
434 return EXIT_FAILURE;
435 }
436
437 if ( EXIT_SUCCESS == sc && !vm.contains( "no-init" ) ) {
438
439 std::fstream initPy( ( out / fs::path( "__init__.py" ) ).string(), std::ios_base::out | std::ios_base::trunc );
440 initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
441 }
442
443 {
444 std::ostringstream
msg;
445 msg <<
":::::: libraries : [ ";
446 std::copy( libs.begin(), libs.end(), std::ostream_iterator<std::string>( msg, " " ) );
447 msg <<
"] :::::: [DONE]";
449 }
450 return sc;
451}
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)