The Gaudi Framework  v38r3 (c3fc9673)
genconf.cpp File Reference
#include <Gaudi/Algorithm.h>
#include <Gaudi/PluginService.h>
#include <GaudiKernel/AlgTool.h>
#include <GaudiKernel/Auditor.h>
#include <GaudiKernel/Bootstrap.h>
#include <GaudiKernel/DataHandle.h>
#include <GaudiKernel/DataHandleProperty.h>
#include <GaudiKernel/GaudiHandle.h>
#include <GaudiKernel/HashMap.h>
#include <GaudiKernel/IAlgTool.h>
#include <GaudiKernel/IAlgorithm.h>
#include <GaudiKernel/IAppMgrUI.h>
#include <GaudiKernel/IAuditor.h>
#include <GaudiKernel/IProperty.h>
#include <GaudiKernel/ISvcLocator.h>
#include <GaudiKernel/Service.h>
#include <GaudiKernel/SmartIF.h>
#include <GaudiKernel/System.h>
#include <GaudiKernel/Time.h>
#include <algorithm>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/program_options.hpp>
#include <boost/regex.hpp>
#include <exception>
#include <fmt/format.h>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <type_traits>
#include <vector>
Include dependency graph for genconf.cpp:

Go to the source code of this file.

Classes

class  configGenerator
 

Namespaces

 fmt
 

Macros

#define LOG_ERROR   BOOST_LOG_TRIVIAL( error )
 
#define LOG_WARNING   BOOST_LOG_TRIVIAL( warning )
 
#define LOG_INFO   BOOST_LOG_TRIVIAL( info )
 
#define LOG_DEBUG   BOOST_LOG_TRIVIAL( debug )
 

Typedefs

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

Functions

template<typename T >
const T & fmt::runtime (const T &v)
 
int createAppMgr ()
 
void init_logging (boost::log::trivial::severity_level level)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ LOG_DEBUG

#define LOG_DEBUG   BOOST_LOG_TRIVIAL( debug )

Definition at line 87 of file genconf.cpp.

◆ LOG_ERROR

#define LOG_ERROR   BOOST_LOG_TRIVIAL( error )

Definition at line 84 of file genconf.cpp.

◆ LOG_INFO

#define LOG_INFO   BOOST_LOG_TRIVIAL( info )

Definition at line 86 of file genconf.cpp.

◆ LOG_WARNING

#define LOG_WARNING   BOOST_LOG_TRIVIAL( warning )

Definition at line 85 of file genconf.cpp.

Typedef Documentation

◆ LibPathNames_t

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

Definition at line 95 of file genconf.cpp.

◆ Strings_t

Definition at line 94 of file genconf.cpp.

Function Documentation

◆ createAppMgr()

int createAppMgr ( )

Definition at line 830 of file genconf.cpp.

832 {
834  SmartIF<IAppMgrUI> appUI( iface );
835  auto propMgr = appUI.as<IProperty>();
836  if ( !propMgr || !appUI ) return EXIT_FAILURE;
837 
838  propMgr->setProperty( "JobOptionsType", "NONE" ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ ); // No job
839  // options
840  propMgr->setProperty( "AppName", "" ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ ); // No initial printout
841  // message
842  propMgr->setProperty( "OutputLevel", 7 ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ ); // No other printout
843  // messages
844  appUI->configure().ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
845  auto msgSvc = SmartIF<IMessageSvc>{ iface }.as<IProperty>();
846  msgSvc->setPropertyRepr( "setWarning", "['DefaultName', 'PropertyHolder']" )
847  .ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
848  msgSvc->setProperty( "Format", "%T %0W%M" ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
849  return EXIT_SUCCESS;
850 }

◆ init_logging()

void init_logging ( boost::log::trivial::severity_level  level)

Definition at line 258 of file genconf.cpp.

258  {
259  namespace logging = boost::log;
260  namespace keywords = boost::log::keywords;
261  namespace expr = boost::log::expressions;
262 
263  logging::add_console_log( std::cout, keywords::format =
264  ( expr::stream << "[" << std::setw( 7 ) << std::left
265  << logging::trivial::severity << "] " << expr::smessage ) );
266 
267  logging::core::get()->set_filter( logging::trivial::severity >= level );
268 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 271 of file genconf.cpp.

273 {
274  init_logging( ( System::isEnvSet( "VERBOSE" ) && !System::getEnv( "VERBOSE" ).empty() )
275  ? boost::log::trivial::info
276  : boost::log::trivial::warning );
277 
278  fs::path pwd = fs::initial_path();
279  fs::path out;
280  Strings_t libs;
281  std::string pkgName;
282  std::string userModule;
283 
284  // declare a group of options that will be allowed only on command line
285  po::options_description generic( "Generic options" );
286  generic.add_options()( "help,h", "produce this help message" )(
287  "package-name,p", po::value<string>(), "name of the package for which we create the configurables file" )(
288  "input-libraries,i", po::value<string>(), "libraries to extract the component configurables from" )(
289  "input-cfg,c", po::value<string>(),
290  "path to the cfg file holding the description of the Configurable base "
291  "classes, the python module holding the Configurable definitions, etc..." )(
292  "output-dir,o", po::value<string>()->default_value( "../genConfDir" ),
293  "output directory for genconf files." )( "debug-level,d", po::value<int>()->default_value( 0 ), "debug level" )(
294  "load-library,l", po::value<Strings_t>()->composing(), "preloading library" )(
295  "user-module,m", po::value<string>(), "user-defined module to be imported by the genConf-generated one" )(
296  "no-init", "do not generate the (empty) __init__.py" );
297 
298  // declare a group of options that will be allowed both on command line
299  // _and_ in configuration file
300  po::options_description config( "Configuration" );
301  config.add_options()( "configurable-module", po::value<string>()->default_value( "AthenaCommon" ),
302  "Name of the module holding the configurable classes" )(
303  "configurable-default-name", po::value<string>()->default_value( "Configurable.DefaultName" ),
304  "Default name for the configurable instance" )( "configurable-algorithm",
305  po::value<string>()->default_value( "ConfigurableAlgorithm" ),
306  "Name of the configurable base class for Algorithm components" )(
307  "configurable-algtool", po::value<string>()->default_value( "ConfigurableAlgTool" ),
308  "Name of the configurable base class for AlgTool components" )(
309  "configurable-auditor", po::value<string>()->default_value( "ConfigurableAuditor" ),
310  "Name of the configurable base class for Auditor components" )(
311  "configurable-service", po::value<string>()->default_value( "ConfigurableService" ),
312  "Name of the configurable base class for Service components" );
313 
314  po::options_description cmdline_options;
315  cmdline_options.add( generic ).add( config );
316 
317  po::options_description config_file_options;
318  config_file_options.add( config );
319 
320  po::options_description visible( "Allowed options" );
321  visible.add( generic ).add( config );
322 
323  po::variables_map vm;
324 
325  try {
326  po::store( po::command_line_parser( argc, argv ).options( cmdline_options ).run(), vm );
327 
328  po::notify( vm );
329 
330  // try to read configuration from the optionally given configuration file
331  if ( vm.count( "input-cfg" ) ) {
332  string cfgFileName = vm["input-cfg"].as<string>();
333  cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
334  std::ifstream ifs( cfgFileName );
335  po::store( parse_config_file( ifs, config_file_options ), vm );
336  }
337 
338  po::notify( vm );
339  } catch ( po::error& err ) {
340  LOG_ERROR << "error detected while parsing command options: " << err.what();
341  return EXIT_FAILURE;
342  }
343 
344  //--- Process command options -----------------------------------------------
345  if ( vm.count( "help" ) ) {
346  cout << visible << endl;
347  return EXIT_FAILURE;
348  }
349 
350  if ( vm.count( "package-name" ) ) {
351  pkgName = vm["package-name"].as<string>();
352  } else {
353  LOG_ERROR << "'package-name' required";
354  cout << visible << endl;
355  return EXIT_FAILURE;
356  }
357 
358  if ( vm.count( "user-module" ) ) {
359  userModule = vm["user-module"].as<string>();
360  LOG_INFO << "INFO: will import user module " << userModule;
361  }
362 
363  if ( vm.count( "input-libraries" ) ) {
364  // re-shape the input arguments:
365  // - removes spurious spaces,
366  // - split into tokens.
367  std::string tmp = vm["input-libraries"].as<std::string>();
368  boost::trim( tmp );
369  boost::split( libs, tmp, boost::is_any_of( " " ), boost::token_compress_on );
370  } else {
371  LOG_ERROR << "input component library(ies) required";
372  cout << visible << endl;
373  return EXIT_FAILURE;
374  }
375 
376  if ( vm.count( "output-dir" ) ) { out = fs::system_complete( fs::path( vm["output-dir"].as<string>() ) ); }
377 
378  if ( vm.count( "debug-level" ) ) { Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() ); }
379 
380  if ( vm.count( "load-library" ) ) {
381  for ( const auto& lLib : vm["load-library"].as<Strings_t>() ) {
382  // load done through Gaudi helper class
383  System::ImageHandle tmp; // we ignore the library handle
384  unsigned long err = System::loadDynamicLib( lLib, &tmp );
385  if ( err != 1 ) LOG_WARNING << "failed to load: " << lLib;
386  }
387  }
388 
389  if ( !fs::exists( out ) ) {
390  try {
391  fs::create_directory( out );
392  } catch ( fs::filesystem_error& err ) {
393  LOG_ERROR << "error creating directory: " << err.what();
394  return EXIT_FAILURE;
395  }
396  }
397 
398  {
400  msg << ":::::: libraries : [ ";
401  std::copy( libs.begin(), libs.end(), std::ostream_iterator<std::string>( msg, " " ) );
402  msg << "] ::::::";
403  LOG_INFO << msg.str();
404  }
405 
406  configGenerator py( pkgName, out.string() );
407  py.setConfigurableModule( vm["configurable-module"].as<string>() );
408  py.setConfigurableDefaultName( vm["configurable-default-name"].as<string>() );
409  py.setConfigurableAlgorithm( vm["configurable-algorithm"].as<string>() );
410  py.setConfigurableAlgTool( vm["configurable-algtool"].as<string>() );
411  py.setConfigurableAuditor( vm["configurable-auditor"].as<string>() );
412  py.setConfigurableService( vm["configurable-service"].as<string>() );
413 
414  int sc = EXIT_FAILURE;
415  try {
416  sc = py.genConfig( libs, userModule );
417  } catch ( exception& e ) {
418  cout << "ERROR: Could not generate Configurable(s) !\n"
419  << "ERROR: Got exception: " << e.what() << endl;
420  return EXIT_FAILURE;
421  }
422 
423  if ( EXIT_SUCCESS == sc && !vm.count( "no-init" ) ) {
424  // create an empty __init__.py file in the output dir
425  std::fstream initPy( ( out / fs::path( "__init__.py" ) ).string(), std::ios_base::out | std::ios_base::trunc );
426  initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
427  }
428 
429  {
431  msg << ":::::: libraries : [ ";
432  std::copy( libs.begin(), libs.end(), std::ostream_iterator<std::string>( msg, " " ) );
433  msg << "] :::::: [DONE]";
434  LOG_INFO << msg.str();
435  }
436  return sc;
437 }
Gaudi::createApplicationMgr
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
System::loadDynamicLib
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:150
Write.stream
stream
Definition: Write.py:32
std::string
STL class.
std::exception
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
std::fstream
STL class.
configGenerator
Definition: genconf.cpp:174
GaudiAlg.HistoUtils.path
path
Definition: HistoUtils.py:960
plotBacklogPyRoot.argc
argc
Definition: plotBacklogPyRoot.py:173
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:388
std::vector< std::string >
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
System::ImageHandle
void * ImageHandle
Definition of an image handle.
Definition: ModuleInfo.h:40
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
prepareBenchmark.config
config
Definition: prepareBenchmark.py:43
IProperty
Definition: IProperty.h:33
std::cout
LOG_ERROR
#define LOG_ERROR
Definition: genconf.cpp:83
std::flush
T flush(T... args)
std::copy
T copy(T... args)
SmartIF< IAppMgrUI >
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:408
gaudirun.level
level
Definition: gaudirun.py:364
Gaudi::PluginService::v1::SetDebug
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
Definition: PluginServiceV1.cpp:323
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
std::ostringstream
STL class.
LOG_WARNING
#define LOG_WARNING
Definition: genconf.cpp:84
std::ostream_iterator
init_logging
void init_logging(boost::log::trivial::severity_level level)
Definition: genconf.cpp:258
std::endl
T endl(T... args)
LOG_INFO
#define LOG_INFO
Definition: genconf.cpp:85
std::left
T left(T... args)
std::vector::begin
T begin(T... args)
IInterface
Definition: IInterface.h:237
std::vector::end
T end(T... args)
gaudirun.options
options
Definition: gaudirun.py:313
std::setw
T setw(T... args)
std::exception::what
T what(T... args)
gaudirun.argv
list argv
Definition: gaudirun.py:327
PrepareBase.out
out
Definition: PrepareBase.py:20
std::ifstream
STL class.
IProperty::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39