The Gaudi Framework  v36r1 (3e2fb5a8)
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 824 of file genconf.cpp.

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

◆ init_logging()

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

Definition at line 249 of file genconf.cpp.

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 262 of file genconf.cpp.

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