The Gaudi Framework  v36r10 (fc05264c)
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/convenience.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
 

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

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

◆ LOG_ERROR

#define LOG_ERROR   BOOST_LOG_TRIVIAL( error )

Definition at line 76 of file genconf.cpp.

◆ LOG_INFO

#define LOG_INFO   BOOST_LOG_TRIVIAL( info )

Definition at line 78 of file genconf.cpp.

◆ LOG_WARNING

#define LOG_WARNING   BOOST_LOG_TRIVIAL( warning )

Definition at line 77 of file genconf.cpp.

Typedef Documentation

◆ LibPathNames_t

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

Definition at line 87 of file genconf.cpp.

◆ Strings_t

Definition at line 86 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 250 of file genconf.cpp.

250  {
251  namespace logging = boost::log;
252  namespace keywords = boost::log::keywords;
253  namespace expr = boost::log::expressions;
254 
255  logging::add_console_log( std::cout, keywords::format =
256  ( expr::stream << "[" << std::setw( 7 ) << std::left
257  << logging::trivial::severity << "] " << expr::smessage ) );
258 
259  logging::core::get()->set_filter( logging::trivial::severity >= level );
260 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 263 of file genconf.cpp.

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