4 #pragma warning( disable : 4273 ) 14 #pragma warning( disable : 279 ) 17 #include "boost/program_options.hpp" 20 #include "boost/algorithm/string/case_conv.hpp" 21 #include "boost/algorithm/string/classification.hpp" 22 #include "boost/algorithm/string/replace.hpp" 23 #include "boost/algorithm/string/split.hpp" 24 #include "boost/algorithm/string/trim.hpp" 25 #include "boost/filesystem/convenience.hpp" 26 #include "boost/filesystem/exception.hpp" 27 #include "boost/filesystem/operations.hpp" 28 #include "boost/format.hpp" 29 #include "boost/regex.hpp" 31 #include <boost/log/core.hpp> 32 #include <boost/log/expressions.hpp> 33 #include <boost/log/trivial.hpp> 34 #include <boost/log/utility/setup/common_attributes.hpp> 35 #include <boost/log/utility/setup/console.hpp> 72 namespace fs = boost::filesystem;
74 #define LOG_ERROR BOOST_LOG_TRIVIAL( error ) 75 #define LOG_WARNING BOOST_LOG_TRIVIAL( warning ) 76 #define LOG_INFO BOOST_LOG_TRIVIAL( info ) 77 #define LOG_DEBUG BOOST_LOG_TRIVIAL( debug ) 94 const boost::regex pythonIdentifier(
"^[a-zA-Z_][a-zA-Z0-9_]*$" );
130 : m_pkgName( pkgName )
131 , m_outputDirName( outputDirName )
133 , m_importGaudiHandles( false )
134 , m_importDataObjectHandles( false )
144 int genConfig(
const Strings_t& modules,
const string& userModule );
164 m_configurable[
"Service"] = cfgService;
165 m_configurable[
"ApplicationMgr"] = cfgService;
181 void pythonizeValue(
const PropertyBase* prop,
string& pvalue,
string& ptype );
184 void pythonizeName(
string&
name );
192 namespace keywords = boost::log::keywords;
193 namespace expr = boost::log::expressions;
197 << logging::trivial::severity <<
"] " << expr::smessage ) );
207 ? boost::log::trivial::info
208 : boost::log::trivial::warning );
217 po::options_description
generic(
"Generic options" );
218 generic.add_options()(
"help,h",
"produce this help message" )(
219 "package-name,p", po::value<string>(),
"name of the package for which we create the configurables file" )(
220 "input-libraries,i", po::value<string>(),
"libraries to extract the component configurables from" )(
221 "input-cfg,c", po::value<string>(),
"path to the cfg file holding the description of the Configurable base " 222 "classes, the python module holding the Configurable definitions, etc..." )(
223 "output-dir,o", po::value<string>()->default_value(
"../genConf" ),
224 "output directory for genconf files." )(
"debug-level,d", po::value<int>()->default_value( 0 ),
"debug level" )(
225 "load-library,l", po::value<Strings_t>()->composing(),
"preloading library" )(
226 "user-module,m", po::value<string>(),
"user-defined module to be imported by the genConf-generated one" )(
227 "no-init",
"do not generate the (empty) __init__.py" );
231 po::options_description
config(
"Configuration" );
232 config.add_options()(
"configurable-module", po::value<string>()->default_value(
"AthenaCommon" ),
233 "Name of the module holding the configurable classes" )(
234 "configurable-default-name", po::value<string>()->default_value(
"Configurable.DefaultName" ),
235 "Default name for the configurable instance" )(
"configurable-algorithm",
236 po::value<string>()->default_value(
"ConfigurableAlgorithm" ),
237 "Name of the configurable base class for Algorithm components" )(
238 "configurable-algtool", po::value<string>()->default_value(
"ConfigurableAlgTool" ),
239 "Name of the configurable base class for AlgTool components" )(
240 "configurable-auditor", po::value<string>()->default_value(
"ConfigurableAuditor" ),
241 "Name of the configurable base class for Auditor components" )(
242 "configurable-service", po::value<string>()->default_value(
"ConfigurableService" ),
243 "Name of the configurable base class for Service components" );
245 po::options_description cmdline_options;
246 cmdline_options.add(
generic ).add( config );
248 po::options_description config_file_options;
249 config_file_options.add( config );
251 po::options_description visible(
"Allowed options" );
252 visible.add(
generic ).add( config );
254 po::variables_map vm;
257 po::store( po::command_line_parser( argc, argv ).
options( cmdline_options ).run(), vm );
262 if ( vm.count(
"input-cfg" ) ) {
263 string cfgFileName = vm[
"input-cfg"].as<
string>();
264 cfgFileName = fs::system_complete(
fs::path( cfgFileName ) ).
string();
266 po::store( parse_config_file( ifs, config_file_options ), vm );
270 }
catch ( po::error& err ) {
271 LOG_ERROR <<
"error detected while parsing command options: " << err.what();
276 if ( vm.count(
"help" ) ) {
281 if ( vm.count(
"package-name" ) ) {
282 pkgName = vm[
"package-name"].as<
string>();
289 if ( vm.count(
"user-module" ) ) {
290 userModule = vm[
"user-module"].as<
string>();
291 LOG_INFO <<
"INFO: will import user module " << userModule;
294 if ( vm.count(
"input-libraries" ) ) {
300 string tmp = vm[
"input-libraries"].as<
string>();
302 boost::split( inputLibs, tmp, boost::is_any_of(
" " ), boost::token_compress_on );
307 for ( Strings_t::const_iterator iLib = inputLibs.
begin(); iLib != inputLibs.
end(); ++iLib ) {
309 if ( 0 == lib.
find(
"lib" ) ) {
317 if ( libs.
empty() ) {
318 LOG_ERROR <<
"input component library(ies) required !\n";
319 LOG_ERROR <<
"'input-libraries' argument was [" << vm[
"input-libraries"].as<
string>() <<
"]";
323 LOG_ERROR <<
"input component library(ies) required";
328 if ( vm.count(
"output-dir" ) ) {
329 out = fs::system_complete(
fs::path( vm[
"output-dir"].as<string>() ) );
332 if ( vm.count(
"debug-level" ) ) {
336 if ( vm.count(
"load-library" ) ) {
338 for ( Strings_t::const_iterator lLib = lLib_list.
begin(); lLib != lLib_list.
end(); ++lLib ) {
348 if ( !fs::exists( out ) ) {
350 fs::create_directory( out );
351 }
catch ( fs::filesystem_error& err ) {
352 LOG_ERROR <<
"error creating directory: " << err.what();
359 msg <<
":::::: libraries : [ ";
367 py.setConfigurableDefaultName( vm[
"configurable-default-name"].as<string>() );
368 py.setConfigurableAlgorithm( vm[
"configurable-algorithm"].as<string>() );
369 py.setConfigurableAlgTool( vm[
"configurable-algtool"].as<string>() );
370 py.setConfigurableAuditor( vm[
"configurable-auditor"].as<string>() );
371 py.setConfigurableService( vm[
"configurable-service"].as<string>() );
373 int sc = EXIT_FAILURE;
375 sc = py.genConfig( libs, userModule );
377 cout <<
"ERROR: Could not generate Configurable(s) !\n" 378 <<
"ERROR: Got exception: " << e.
what() <<
endl;
382 if ( EXIT_SUCCESS == sc && !vm.count(
"no-init" ) ) {
384 fstream initPy( ( out /
fs::path(
"__init__.py" ) ).
string(), std::ios_base::out | std::ios_base::trunc );
385 initPy <<
"## Hook for " << pkgName <<
" genConf module\n" <<
flush;
390 msg <<
":::::: libraries : [ ";
392 msg <<
"] :::::: [DONE]";
405 const Strings_t::const_iterator endLib = libs.
end();
408 const bool isGaudiSvc = (
std::find( libs.
begin(), endLib, gaudiSvc ) != endLib );
412 cout <<
"ERROR: ApplicationMgr can not be created. Check environment" <<
endl;
418 Registry&
registry = Registry::instance();
429 for ( Strings_t::const_iterator iLib = libs.
begin(); iLib != endLib; ++iLib ) {
431 LOG_INFO <<
":::: processing library: " << *iLib <<
"...";
434 m_importGaudiHandles =
false;
435 m_importDataObjectHandles =
false;
451 const string ident = *it;
452 if ( bkgNames.
find( ident ) != bkgNames.
end() ) {
454 LOG_INFO <<
"\t==> skipping [" << ident <<
"]...";
459 const Registry::FactoryInfo info = registry.getInfo( *it );
460 const string rtype = info.rtype;
463 if ( info.properties.find(
"ReflexName" ) != info.properties.end() )
continue;
470 LOG_WARNING <<
"library [" << *iLib <<
"] exposes factory [" << ident <<
"] which is declared in [" 471 << DsoUtils::dsoName( info.ptr ) <<
"] !!";
477 if ( ident ==
"ApplicationMgr" )
478 type =
"ApplicationMgr";
494 type =
"Unknown", known =
false;
499 if ( type ==
"IInterface" ) {
505 if ( type ==
"Converter" || type ==
"DataObject" ) {
512 <<
" Component [" << ident <<
"] is skipped !";
516 LOG_INFO <<
" - component: " << info.className <<
" (" 517 << ( info.className != name ? ( name +
": " ) :
std::string() ) << type <<
")";
519 string cname =
"DefaultName";
522 if ( type ==
"Algorithm" ) {
524 }
else if ( type ==
"Service" ) {
526 }
else if ( type ==
"AlgTool" ) {
527 prop =
SmartIF<IAlgTool>( AlgTool::Factory::create( ident, cname, type, dummySvc ) );
530 }
else if ( type ==
"Auditor" ) {
532 }
else if ( type ==
"ApplicationMgr" ) {
538 LOG_ERROR <<
"Error instantiating " << name <<
" from " << *iLib;
543 LOG_ERROR <<
"Error instantiating " << name <<
" from " << *iLib;
548 if ( genComponent( *iLib, name, type, prop->
getProperties() ) ) {
553 LOG_ERROR <<
"could not cast IInterface* object to an IProperty* !";
554 LOG_ERROR <<
"return type from PluginSvc is [" << rtype <<
"]...";
555 LOG_ERROR <<
"NO Configurable will be generated for [" << name <<
"] !";
566 std::fstream py( pyName, std::ios_base::out | std::ios_base::trunc );
567 std::fstream db( dbName, std::ios_base::out | std::ios_base::trunc );
570 if ( !userModule.
empty() ) py <<
"from " << userModule <<
" import *" <<
endl;
572 genTrailer( py, db );
579 return allGood ? EXIT_SUCCESS : EXIT_FAILURE;
585 std::string::size_type pos = 0, nxtpos = 0;
588 while ( std::string::npos != pos ) {
590 nxtpos = m_configurable[
"Module"].find_first_of(
',', pos );
593 mod = m_configurable[
"Module"].
substr( pos, nxtpos - pos );
599 if ( std::string::npos == nxtpos ) {
601 s << indent <<
import.str() <<
"\n" <<
flush;
602 pos = std::string::npos;
605 s << indent <<
"try:\n" << indent << py_tab <<
import.str() <<
"\n" << indent <<
"except ImportError:\n" <<
flush;
620 <<
"\"\"\"Automatically generated. DO NOT EDIT please\"\"\"\n";
621 if ( m_importGaudiHandles ) {
622 py <<
"from GaudiKernel.GaudiHandles import *\n";
625 if ( m_importDataObjectHandles ) {
626 py <<
"from GaudiKernel.DataObjectHandleBase import *\n";
629 genImport( py,
boost::format(
"from %1%.Configurable import *" ) );
632 db <<
"## -*- ascii -*- \n" 633 <<
"# db file automatically generated by genconf on: " << now <<
"\n" 641 db <<
"## " << m_pkgName <<
"\n" <<
std::flush;
649 string cname = componentName;
650 pythonizeName( cname );
653 PropertyDoc_t propDoc;
656 m_pyBuf <<
"class " << cname <<
"( " << m_configurable[componentType] <<
" ) :" 658 m_pyBuf <<
" __slots__ = { \n";
661 const string pname = ( *it )->name();
663 if ( !boost::regex_match( pname, pythonIdentifier ) ) {
664 std::cout <<
"ERROR: invalid property name \"" << pname <<
"\" in component " << cname
665 <<
" (invalid Python identifier)" <<
std::endl;
667 m_pyBuf <<
" #ERROR-invalid identifier '" << pname <<
"'\n" 672 string pvalue, ptype;
673 pythonizeValue( ( *it ), pvalue, ptype );
674 m_pyBuf <<
" '" << pname <<
"' : " << pvalue <<
", # " << ptype <<
"\n";
676 if ( ( *it )->documentation() !=
"none" ) {
677 propDoc[
pname] = ( *it )->documentation() +
" [" + ( *it )->ownerTypeName() +
"]";
681 m_pyBuf <<
" _propertyDocDct = { \n";
682 for ( PropertyDoc_t::const_iterator iProp = propDoc.begin(); iProp != propDoc.end(); ++iProp ) {
683 m_pyBuf <<
std::setw( 5 ) <<
"'" << iProp->first <<
"' : " 684 <<
"\"\"\" " << iProp->second <<
" \"\"\",\n";
688 m_pyBuf <<
" def __init__(self, name = " << m_configurable[
"DefaultName"] <<
", **kwargs):\n" 689 <<
" super(" << cname <<
", self).__init__(name)\n" 690 <<
" for n,v in kwargs.items():\n" 691 <<
" setattr(self, n, v)\n" 692 <<
" def getDlls( self ):\n" 693 <<
" return '" << libName <<
"'\n" 694 <<
" def getType( self ):\n" 695 <<
" return '" << componentName <<
"'\n" 696 <<
" pass # class " << cname <<
"\n" 700 const string pyName = (
fs::path( m_outputDirName ) /
fs::path( libName +
"Conf.py" ) ).
string();
704 m_dbBuf << m_pkgName <<
"." << modName <<
" " << libName <<
" " << cname <<
"\n" <<
flush;
712 static string in(
"<>&*,: ()." );
713 static string out(
"__rp__s___" );
714 boost::algorithm::replace_all( name,
", ",
"," );
715 for ( string::iterator i = name.
begin(); i != name.
end(); ++i ) {
716 if ( in.
find( *i ) != string::npos ) *i = out[in.
find( *i )];
726 if ( ti ==
typeid(
bool ) ) {
727 pvalue = ( cvalue ==
"0" || cvalue ==
"False" || cvalue ==
"false" ) ?
"False" :
"True";
729 }
else if ( ti ==
typeid(
char ) || ti ==
typeid(
signed char ) || ti ==
typeid(
unsigned char ) ||
730 ti ==
typeid( short ) || ti ==
typeid(
unsigned short ) || ti ==
typeid( int ) ||
731 ti ==
typeid(
unsigned int ) || ti ==
typeid( long ) || ti ==
typeid(
unsigned long ) ) {
734 }
else if ( ti ==
typeid(
long long ) || ti ==
typeid(
unsigned long long ) ) {
735 pvalue = cvalue +
"L";
737 }
else if ( ti ==
typeid(
float ) || ti ==
typeid( double ) ) {
739 pvalue = boost::to_lower_copy( cvalue );
740 if ( pvalue ==
"nan" ) {
741 pvalue =
"float('nan')";
743 }
else if ( std::string::npos == pvalue.
find(
"." ) && std::string::npos == pvalue.
find(
"e" ) ) {
744 pvalue = cvalue +
".0";
747 }
else if ( ti ==
typeid(
string ) ) {
749 pvalue =
"'" + cvalue +
"'";
752 m_importGaudiHandles =
true;
757 ptype =
"GaudiHandle";
759 m_importGaudiHandles =
true;
764 ptype =
"GaudiHandleArray";
766 m_importDataObjectHandles =
true;
771 ptype =
"DataObjectHandleBase";
774 v_str.
setf( std::ios::showpoint );
776 pvalue = v_str.
str();
789 if ( !propMgr || !appUI )
return EXIT_FAILURE;
791 propMgr->setProperty(
"AppName",
"" );
792 propMgr->setProperty(
"OutputLevel",
"7" );
795 msgSvc->setProperty(
"setWarning",
"['DefaultName', 'PropertyHolder']" );
796 msgSvc->setProperty(
"Format",
"%T %0W%M" );
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
int genConfig(const Strings_t &modules, const string &userModule)
main entry point of this class:
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
The data converters are responsible to translate data from one representation into another...
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
std::vector< std::string > Strings_t
-*- C++ -*- /////////////////////////////
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
const std::string name() const
property name
void pythonizeName(string &name)
Translates a valid C++ typename into a valid python one.
static Time current()
Returns the current time.
void setConfigurableDefaultName(const std::string &defaultName)
customize the default name for configurable instances
std::vector< fs::path > LibPathNames_t
void setConfigurableAlgTool(const std::string &cfgAlgTool)
customize the configurable base class for AlgTool component
void * ImageHandle
Definition of an image handle.
virtual std::string toString() const =0
value -> string
GaudiUtils::HashMap< std::string, std::string > m_configurable
Configurable customization.
stringstream m_pyBuf
buffer of auto-generated configurables
GAUDIPS_API Logger & logger()
Return the current logger instance.
virtual void toStream(std::ostream &out) const =0
value -> stream
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
int genComponent(const std::string &libName, const std::string &componentName, const std::string &componentType, const vector< PropertyBase * > &properties)
void setConfigurableModule(const std::string &moduleName)
customize the Module name where configurable base classes are defined
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
int main(int argc, char **argv)
bool m_importDataObjectHandles
GAUDI_API ISvcLocator * svcLocator()
General service interface definition.
Definition of the basic interface.
const GaudiHandleBase & value() const
void genHeader(std::ostream &pyOut, std::ostream &dbOut)
const GaudiHandleArrayBase & value() const
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
stringstream m_dbBuf
buffer of generated configurables informations for the "Db" file The "Db" file is holding information...
configGenerator(const string &pkgName, const string &outputDirName)
The IAlgorithm is the interface implemented by the Algorithm base class.
std::string pythonRepr() const override
Python representation of array of handles, i.e.
void setConfigurableAlgorithm(const std::string &cfgAlgorithm)
customize the configurable base class for Algorithm component
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
void init_logging(boost::log::trivial::severity_level level)
Base class of array's of various gaudihandles.
string m_outputDirName
absolute path to the directory where genconf will store auto-generated files (Configurables and Confi...
void pythonizeValue(const PropertyBase *prop, string &pvalue, string &ptype)
handle the "marshalling" of Properties
virtual unsigned long release()=0
Release Interface instance.
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
void genImport(std::ostream &s, const boost::format &frmt, std::string indent)
std::string pythonRepr() const override
Python representation of handle, i.e.
bool m_importGaudiHandles
switch to decide if the generated configurables need to import GaudiHandles (ie: if one of the compon...
void setConfigurableService(const std::string &cfgService)
customize the configurable base class for Service component
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
std::string pythonRepr() const override
In-memory database of the loaded factories.
string m_pkgName
name of the package we are processing
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
static GAUDI_API void disableChecking()
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
void genTrailer(std::ostream &pyOut, std::ostream &dbOut)
const DataObjectHandleBase & value() const
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
virtual StatusCode configure()=0
Configure the job.
The IProperty is the basic interface for all components which have properties that can be set or get...
Base class for all services.
A DataObject is the base class of any identifiable object on any data store.
The IAuditor is the interface implmented by the AlgAuditor base class.
std::string libNativeName(const std::string &libName)
void genBody(std::ostream &pyOut, std::ostream &dbOut)
const std::type_info * type_info() const
property type-info
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
void setConfigurableAuditor(const std::string &cfgAuditor)
customize the configurable base class for AlgTool component