| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Classes | Macros | Typedefs | Functions
genconf.cpp File Reference
`#include "boost/program_options.hpp"`
`#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/format.hpp"`
`#include "boost/regex.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 "GaudiKernel/Bootstrap.h"`
`#include "GaudiKernel/DataObjectHandleBase.h"`
`#include "GaudiKernel/DataObjectHandleProperty.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/AlgTool.h"`
`#include "GaudiKernel/Algorithm.h"`
`#include "GaudiKernel/Auditor.h"`
`#include "GaudiKernel/Time.h"`
`#include <Gaudi/PluginService.h>`
`#include <algorithm>`
`#include <exception>`
`#include <fstream>`
`#include <iostream>`
`#include <set>`
`#include <sstream>`
`#include <vector>`
`#include "DsoUtils.h"`
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::string > | Strings_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

#define LOG_DEBUG BOOST_LOG_TRIVIAL( debug )

Definition at line 86 of file genconf.cpp.

#define LOG_ERROR BOOST_LOG_TRIVIAL( error )

Definition at line 83 of file genconf.cpp.

#define LOG_INFO BOOST_LOG_TRIVIAL( info )

Definition at line 85 of file genconf.cpp.

#define LOG_WARNING BOOST_LOG_TRIVIAL( warning )

Definition at line 84 of file genconf.cpp.

## Typedef Documentation

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

Definition at line 95 of file genconf.cpp.

typedef std::vector<std::string> Strings_t

Definition at line 91 of file genconf.cpp.

## Function Documentation

int createAppMgr | ( |  | ) |

Definition at line 791 of file genconf.cpp.

793 {
794 IInterface* iface = Gaudi::createApplicationMgr();
795 SmartIF<IAppMgrUI> appUI( iface );
796 auto propMgr = appUI.as<IProperty>();
797
798 if ( !propMgr || !appUI ) return EXIT_FAILURE;
799 propMgr->setProperty( "JobOptionsType", "NONE" ); // No job options
800 propMgr->setProperty( "AppName", "" ); // No initial printout message
801 propMgr->setProperty( "OutputLevel", "7" ); // No other printout messages
802 appUI->configure();
803 SmartIF<IProperty> msgSvc{SmartIF<IMessageSvc>{iface}};
804 msgSvc->setProperty( "setWarning", "['DefaultName', 'PropertyHolder']" );
805 msgSvc->setProperty( "Format", "%T %0W%M" );
806 return EXIT_SUCCESS;
807 }
SmartIF< IAppMgrUI >
IProperty::setProperty
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
ForwardSchedulerSimpleTest.msgSvc
msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
Gaudi::createApplicationMgr
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)

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

Definition at line 198 of file genconf.cpp.

199 {
200 namespace logging = boost::log;
201 namespace keywords = boost::log::keywords;
202 namespace expr = boost::log::expressions;
203
204 logging::add_console_log( std::cout, keywords::format =
205 ( expr::stream << "[" << std::setw( 7 ) << std::left
206 << logging::trivial::severity << "] " << expr::smessage ) );
207
208 logging::core::get()->set_filter( logging::trivial::severity >= level );
209 }
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::left
T left(T...args)
std::setw
T setw(T...args)
GaudiPython.Persistency.get
def get(type_)
Definition: Persistency.py:23
gaudirun.level
level
Definition: gaudirun.py:261
std::cout
Gaudi.Configuration.log
log
Definition: Configuration.py:13

int main | ( | int | argc,
|  | char ** | argv
| ) |  |

Definition at line 212 of file genconf.cpp.

214 {
215 init_logging( ( System::isEnvSet( "VERBOSE" ) && !System::getEnv( "VERBOSE" ).empty() )
216 ? boost::log::trivial::info
217 : boost::log::trivial::warning );
218
219 fs::path pwd = fs::initial_path();
220 fs::path out;
221 Strings_t libs;
222 std::string pkgName;
223 std::string userModule;
224
225 // declare a group of options that will be allowed only on command line
226 po::options_description generic( "Generic options" );
227 generic.add_options()( "help,h", "produce this help message" )(
228 "package-name,p", po::value<string>(), "name of the package for which we create the configurables file" )(
229 "input-libraries,i", po::value<string>(), "libraries to extract the component configurables from" )(
230 "input-cfg,c", po::value<string>(), "path to the cfg file holding the description of the Configurable base "
231 "classes, the python module holding the Configurable definitions, etc..." )(
232 "output-dir,o", po::value<string>()->default_value( "../genConf" ),
233 "output directory for genconf files." )( "debug-level,d", po::value<int>()->default_value( 0 ), "debug level" )(
234 "load-library,l", po::value<Strings_t>()->composing(), "preloading library" )(
235 "user-module,m", po::value<string>(), "user-defined module to be imported by the genConf-generated one" )(
236 "no-init", "do not generate the (empty) __init__.py" );
237
238 // declare a group of options that will be allowed both on command line
239 // _and_ in configuration file
240 po::options_description config( "Configuration" );
241 config.add_options()( "configurable-module", po::value<string>()->default_value( "AthenaCommon" ),
242 "Name of the module holding the configurable classes" )(
243 "configurable-default-name", po::value<string>()->default_value( "Configurable.DefaultName" ),
244 "Default name for the configurable instance" )( "configurable-algorithm",
245 po::value<string>()->default_value( "ConfigurableAlgorithm" ),
246 "Name of the configurable base class for Algorithm components" )(
247 "configurable-algtool", po::value<string>()->default_value( "ConfigurableAlgTool" ),
248 "Name of the configurable base class for AlgTool components" )(
249 "configurable-auditor", po::value<string>()->default_value( "ConfigurableAuditor" ),
250 "Name of the configurable base class for Auditor components" )(
251 "configurable-service", po::value<string>()->default_value( "ConfigurableService" ),
252 "Name of the configurable base class for Service components" );
253
254 po::options_description cmdline_options;
255 cmdline_options.add( generic ).add( config );
256
257 po::options_description config_file_options;
258 config_file_options.add( config );
259
260 po::options_description visible( "Allowed options" );
261 visible.add( generic ).add( config );
262
263 po::variables_map vm;
264
265 try {
266 po::store( po::command_line_parser( argc, argv ).options( cmdline_options ).run(), vm );
267
268 po::notify( vm );
269
270 // try to read configuration from the optionally given configuration file
271 if ( vm.count( "input-cfg" ) ) {
272 string cfgFileName = vm["input-cfg"].as<string>();
273 cfgFileName = fs::system_complete( fs::path( cfgFileName ) ).string();
274 std::ifstream ifs( cfgFileName );
275 po::store( parse_config_file( ifs, config_file_options ), vm );
276 }
277
278 po::notify( vm );
279 } catch ( po::error& err ) {
280 LOG_ERROR << "error detected while parsing command options: " << err.what();
281 return EXIT_FAILURE;
282 }
283
284 //--- Process command options -----------------------------------------------
285 if ( vm.count( "help" ) ) {
286 cout << visible << endl;
287 return EXIT_FAILURE;
288 }
289
290 if ( vm.count( "package-name" ) ) {
291 pkgName = vm["package-name"].as<string>();
292 } else {
293 LOG_ERROR << "'package-name' required";
294 cout << visible << endl;
295 return EXIT_FAILURE;
296 }
297
298 if ( vm.count( "user-module" ) ) {
299 userModule = vm["user-module"].as<string>();
300 LOG_INFO << "INFO: will import user module " << userModule;
301 }
302
303 if ( vm.count( "input-libraries" ) ) {
304 // re-shape the input arguments:
305 // - removes spurious spaces,
306 // - split into tokens.
307 Strings_t inputLibs;
308 {
309 string tmp = vm["input-libraries"].as<string>();
310 boost::trim( tmp );
311 boost::split( inputLibs, tmp, boost::is_any_of( " " ), boost::token_compress_on );
312 }
313
314 //
315 libs.reserve( inputLibs.size() );
316 for ( Strings_t::const_iterator iLib = inputLibs.begin(); iLib != inputLibs.end(); ++iLib ) {
317 std::string lib = fs::path( *iLib ).stem().string();
318 if ( 0 == lib.find( "lib" ) ) {
319 lib = lib.substr( 3 ); // For *NIX remove "lib"
320 }
321 // remove duplicates
322 if ( !lib.empty() && std::find( libs.begin(), libs.end(), lib ) == libs.end() ) {
323 libs.push_back( lib );
324 }
325 } //> end loop over input-libraries
326 if ( libs.empty() ) {
327 LOG_ERROR << "input component library(ies) required !\n";
328 LOG_ERROR << "'input-libraries' argument was [" << vm["input-libraries"].as<string>() << "]";
329 return EXIT_FAILURE;
330 }
331 } else {
332 LOG_ERROR << "input component library(ies) required";
333 cout << visible << endl;
334 return EXIT_FAILURE;
335 }
336
337 if ( vm.count( "output-dir" ) ) {
338 out = fs::system_complete( fs::path( vm["output-dir"].as<string>() ) );
339 }
340
341 if ( vm.count( "debug-level" ) ) {
342 Gaudi::PluginService::SetDebug( vm["debug-level"].as<int>() );
343 }
344
345 if ( vm.count( "load-library" ) ) {
346 Strings_t lLib_list = vm["load-library"].as<Strings_t>();
347 for ( Strings_t::const_iterator lLib = lLib_list.begin(); lLib != lLib_list.end(); ++lLib ) {
348 // load done through Gaudi helper class
349 System::ImageHandle tmp; // we ignore the library handle
350 unsigned long err = System::loadDynamicLib( *lLib, &tmp );
351 if ( err != 1 ) {
352 LOG_WARNING << "failed to load: " << *lLib;
353 }
354 }
355 }
356
357 if ( !fs::exists( out ) ) {
358 try {
359 fs::create_directory( out );
360 } catch ( fs::filesystem_error& err ) {
361 LOG_ERROR << "error creating directory: " << err.what();
362 return EXIT_FAILURE;
363 }
364 }
365
366 {
367 std::ostringstream msg;
368 msg << ":::::: libraries : [ ";
369 copy( libs.begin(), libs.end(), ostream_iterator<string>( msg, " " ) );
370 msg << "] ::::::";
371 LOG_INFO << msg.str();
372 }
373
374 configGenerator py( pkgName, out.string() );
375 py.setConfigurableModule( vm["configurable-module"].as<string>() );
376 py.setConfigurableDefaultName( vm["configurable-default-name"].as<string>() );
377 py.setConfigurableAlgorithm( vm["configurable-algorithm"].as<string>() );
378 py.setConfigurableAlgTool( vm["configurable-algtool"].as<string>() );
379 py.setConfigurableAuditor( vm["configurable-auditor"].as<string>() );
380 py.setConfigurableService( vm["configurable-service"].as<string>() );
381
382 int sc = EXIT_FAILURE;
383 try {
384 sc = py.genConfig( libs, userModule );
385 } catch ( exception& e ) {
386 cout << "ERROR: Could not generate Configurable(s) !\n"
387 << "ERROR: Got exception: " << e.what() << endl;
388 return EXIT_FAILURE;
389 }
390
391 if ( EXIT_SUCCESS == sc && !vm.count( "no-init" ) ) {
392 // create an empty __init__.py file in the output dir
393 fstream initPy( ( out / fs::path( "__init__.py" ) ).string(), std::ios_base::out | std::ios_base::trunc );
394 initPy << "## Hook for " << pkgName << " genConf module\n" << flush;
395 }
396
397 {
398 std::ostringstream msg;
399 msg << ":::::: libraries : [ ";
400 copy( libs.begin(), libs.end(), ostream_iterator<string>( msg, " " ) );
401 msg << "] :::::: [DONE]";
402 LOG_INFO << msg.str();
403 }
404 return sc;
405 }
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:550
std::string::empty
T empty(T...args)
std::copy
T copy(T...args)
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:772
prepareBenchmark.config
config
Definition: prepareBenchmark.py:27
gaudirun.argv
list argv
Definition: gaudirun.py:227
LOG_ERROR
#define LOG_ERROR
Definition: genconf.cpp:83
std::endl
T endl(T...args)
std::vector::end
T end(T...args)
System::ImageHandle
void * ImageHandle
Definition of an image handle.
Definition: ModuleInfo.h:30
configGenerator::setConfigurableModule
void setConfigurableModule(const std::string &moduleName)
customize the Module name where configurable base classes are defined
Definition: genconf.cpp:156
std::string
STL class.
gaudirun.options
options
Definition: gaudirun.py:215
std::vector::push_back
T push_back(T...args)
Gaudi::PluginService::SetDebug
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
Definition: PluginService.cpp:349
configGenerator
Definition: genconf.cpp:106
std::exception::what
T what(T...args)
LOG_INFO
#define LOG_INFO
Definition: genconf.cpp:85
std::ostringstream
STL class.
std::ostream_iterator
std::fstream
STL class.
std::ostringstream::str
T str(T...args)
std::exception
STL class.
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:570
plotBacklogPyRoot.argc
argc
Definition: plotBacklogPyRoot.py:128
std::flush
T flush(T...args)
init_logging
void init_logging(boost::log::trivial::severity_level level)
Definition: genconf.cpp:198
std::string::find
T find(T...args)
std::vector::size
T size(T...args)
std::vector< std::string >
LOG_WARNING
#define LOG_WARNING
Definition: genconf.cpp:84
std::vector::begin
T begin(T...args)
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
std::string::substr
T substr(T...args)
std::cout
std::ifstream
STL class.
std::vector::reserve
T reserve(T...args)
System::loadDynamicLib
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:126