The Gaudi Framework  v37r1 (a7f61348)
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
 

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

◆ LOG_ERROR

#define LOG_ERROR   BOOST_LOG_TRIVIAL( error )

Definition at line 85 of file genconf.cpp.

◆ LOG_INFO

#define LOG_INFO   BOOST_LOG_TRIVIAL( info )

Definition at line 87 of file genconf.cpp.

◆ LOG_WARNING

#define LOG_WARNING   BOOST_LOG_TRIVIAL( warning )

Definition at line 86 of file genconf.cpp.

Typedef Documentation

◆ LibPathNames_t

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

Definition at line 96 of file genconf.cpp.

◆ Strings_t

Definition at line 95 of file genconf.cpp.

Function Documentation

◆ createAppMgr()

int createAppMgr ( )

Definition at line 831 of file genconf.cpp.

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

◆ init_logging()

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

Definition at line 259 of file genconf.cpp.

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 272 of file genconf.cpp.

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