Loading [MathJax]/extensions/tex2jax.js
|
bool | genComponent (const std::string &libName, const std::string &componentName, component_t componentType, const vector< PropertyBase * > &properties, const Gaudi::PluginService::Details::Registry::FactoryInfo &info) |
|
bool | genComponent2 (const std::string &componentName, component_t componentType, const vector< PropertyBase * > &properties, const std::vector< std::string > &interfaces, const Gaudi::PluginService::Details::Registry::FactoryInfo &info) |
|
void | genImport (std::ostream &s, std::string_view frmt, std::string indent) |
|
void | genHeader (std::ostream &pyOut, std::ostream &dbOut) |
|
void | genBody (std::ostream &pyOut, std::ostream &dbOut) |
|
void | genTrailer (std::ostream &pyOut, std::ostream &dbOut) |
|
void | pythonizeValue (const PropertyBase *prop, string &pvalue, string &ptype) |
| handle the "marshalling" of Properties More...
|
|
Definition at line 171 of file genconf.cpp.
◆ configGenerator()
configGenerator::configGenerator |
( |
const string & |
pkgName, |
|
|
const string & |
outputDirName |
|
) |
| |
|
inline |
◆ genBody()
void configGenerator::genBody |
( |
std::ostream & |
pyOut, |
|
|
std::ostream & |
dbOut |
|
) |
| |
|
inlineprivate |
◆ genComponent()
bool configGenerator::genComponent |
( |
const std::string & |
libName, |
|
|
const std::string & |
componentName, |
|
|
component_t |
componentType, |
|
|
const vector< PropertyBase * > & |
properties, |
|
|
const Gaudi::PluginService::Details::Registry::FactoryInfo & |
info |
|
) |
| |
|
private |
Definition at line 705 of file genconf.cpp.
710 auto cname = pythonizeName( componentName );
711 const auto decl_loc = info.getprop(
"declaration_location" );
713 std::vector<std::pair<std::string, std::string>> propDoc;
717 m_pyBuf <<
" __slots__ = { \n";
719 const string&
pname = prop->name();
721 if ( !boost::regex_match(
pname, pythonIdentifier ) ) {
722 LOG_ERROR <<
"invalid property name \"" <<
pname <<
"\" in component " << cname <<
" (invalid Python identifier)"
725 m_pyBuf <<
" #ERROR-invalid identifier '" <<
pname <<
"'\n"
730 string pvalue, ptype;
734 if ( prop->documentation() !=
"none" ) {
735 propDoc.emplace_back(
pname, prop->documentation() +
" [" + prop->ownerTypeName() +
"]" );
739 m_pyBuf <<
" _propertyDocDct = { \n";
740 for (
const auto& prop : propDoc ) {
741 m_pyBuf << std::setw( 5 ) <<
"'" << prop.first <<
"' : "
742 <<
"\"\"\" " << prop.second <<
" \"\"\",\n";
746 if ( !decl_loc.empty() ) {
m_pyBuf <<
" __declaration_location__ = '" << decl_loc <<
"'\n"; }
747 m_pyBuf <<
" def __init__(self, name = " <<
m_configurable[component_t::DefaultName] <<
", **kwargs):\n"
748 <<
" super(" << cname <<
", self).__init__(name)\n"
749 <<
" for n,v in kwargs.items():\n"
750 <<
" setattr(self, n, v)\n"
751 <<
" def getDlls( self ):\n"
752 <<
" return '" << libName <<
"'\n"
753 <<
" def getType( self ):\n"
754 <<
" return '" << componentName <<
"'\n"
755 <<
" pass # class " << cname <<
"\n"
760 const string modName =
fs::path( pyName ).filename().stem().string();
763 m_dbBuf <<
m_pkgName <<
"." << modName <<
" " << libName <<
" " << cname <<
"\n" << flush;
◆ genComponent2()
bool configGenerator::genComponent2 |
( |
const std::string & |
componentName, |
|
|
component_t |
componentType, |
|
|
const vector< PropertyBase * > & |
properties, |
|
|
const std::vector< std::string > & |
interfaces, |
|
|
const Gaudi::PluginService::Details::Registry::FactoryInfo & |
info |
|
) |
| |
|
private |
Definition at line 769 of file genconf.cpp.
774 m_db2Buf <<
" '" << componentName <<
"': {\n";
775 m_db2Buf <<
" '__component_type__': '";
776 switch ( componentType ) {
777 case component_t::Algorithm:
780 case component_t::AlgTool:
783 case component_t::ApplicationMgr:
784 case component_t::Service:
787 case component_t::Auditor:
794 const auto decl_loc = info.getprop(
"declaration_location" );
795 if ( !decl_loc.empty() ) {
m_db2Buf <<
"',\n '__declaration_location__': '" << decl_loc; }
797 m_db2Buf <<
"',\n '__interfaces__': (";
798 for (
const auto& intf : std::set<std::string>{
begin( interfaces ),
end( interfaces ) } ) {
799 if ( ignored_interfaces.find( intf ) ==
end( ignored_interfaces ) ) {
m_db2Buf <<
'\'' << intf <<
"', "; }
801 m_db2Buf <<
"),\n 'properties': {\n";
805 const string&
pname = prop->name();
807 if ( !boost::regex_match(
pname, pythonIdentifier ) ) {
808 LOG_ERROR <<
"invalid property name \"" <<
pname <<
"\" in component " << componentName
809 <<
" (invalid Python identifier)" << std::endl;
810 m_db2Buf <<
" #ERROR-invalid identifier '" <<
pname <<
"'\n";
815 string pvalue, ptype;
818 m_db2Buf <<
" '" <<
pname <<
"': ('" << ptype <<
"', " << pvalue <<
", '''" << prop->documentation()
819 <<
" [" << prop->ownerTypeName() <<
"]'''";
820 auto sem = prop->semantics();
821 if ( !sem.empty() ) {
m_db2Buf <<
", '" << sem <<
'\''; }
◆ genConfig()
int configGenerator::genConfig |
( |
const Strings_t & |
modules, |
|
|
const string & |
userModule |
|
) |
| |
main entry point of this class:
- iterate over all the modules (ie: library names)
- for each module extract component informations
- eventually generate the header/body/trailer python file and "Db" file
write-out files for this library
Definition at line 466 of file genconf.cpp.
469 const auto endLib = libs.end();
471 static const std::string gaudiSvc =
"GaudiCoreSvc";
472 const bool isGaudiSvc =
473 std::find_if( libs.begin(), endLib, [](
const auto&
s ) {
474 return s.find( gaudiSvc ) != std::string::npos;
479 cout <<
"ERROR: ApplicationMgr can not be created. Check environment" << endl;
484 using Gaudi::PluginService::Details::Registry;
485 const Registry&
registry = Registry::instance();
487 auto bkgNames =
registry.loadedFactoryNames();
490 IInterface* dummySvc =
new Service(
"DummySvc", svcLoc );
496 for (
const auto& iLib : libs ) {
497 std::string lib =
fs::path( iLib ).stem().string();
498 if ( lib.compare( 0, 3,
"lib" ) == 0 ) {
499 lib = lib.substr( 3 );
501 LOG_INFO <<
":::: processing library: " << iLib <<
"...";
520 for (
const auto& factoryName :
registry.loadedFactoryNames() ) {
521 if ( bkgNames.find( factoryName ) != bkgNames.end() ) {
523 LOG_INFO <<
"\t==> skipping [" << factoryName <<
"]...";
527 auto entry =
factories.find( factoryName );
529 LOG_ERROR <<
"inconsistency in component factories list: I cannot find anymore " << factoryName;
532 const auto& info = entry->second;
533 if ( !info.is_set() )
continue;
536 if ( !info.getprop(
"ReflexName" ).empty() )
continue;
542 if ( libNativeName( lib ) != info.library ) {
543 LOG_WARNING <<
"library [" << lib <<
"] exposes factory [" << factoryName <<
"] which is declared in ["
544 << info.library <<
"] !!";
548 component_t
type = component_t::Unknown;
550 const auto ft = allowedFactories.find( info.factory.type().name() );
551 if ( ft != allowedFactories.end() ) {
553 }
else if ( factoryName ==
"ApplicationMgr" ) {
554 type = component_t::ApplicationMgr;
560 std::string
name = boost::trim_copy( factoryName );
562 const auto className = info.getprop(
"ClassName" );
563 LOG_INFO <<
" - component: " << className <<
" (" << ( className !=
name ? (
name +
": " ) : std::string() )
566 string cname =
"DefaultName";
570 case component_t::Algorithm:
573 case component_t::Service:
576 case component_t::AlgTool:
582 case component_t::Auditor:
585 case component_t::ApplicationMgr:
591 }
catch ( exception& e ) {
592 LOG_ERROR <<
"Error instantiating " <<
name <<
" from " << iLib;
593 LOG_ERROR <<
"Got exception: " << e.what();
597 LOG_ERROR <<
"Error instantiating " <<
name <<
" from " << iLib;
611 LOG_ERROR <<
"could not cast IInterface* object to an IProperty* !";
612 LOG_ERROR <<
"NO Configurable will be generated for [" <<
name <<
"] !";
628 if ( !userModule.empty() ) py <<
"from " << userModule <<
" import *" << endl;
635 db2 <<
"{\n" <<
m_db2Buf.str() <<
"}\n";
643 return allGood ? EXIT_SUCCESS : EXIT_FAILURE;
◆ genHeader()
void configGenerator::genHeader |
( |
std::ostream & |
pyOut, |
|
|
std::ostream & |
dbOut |
|
) |
| |
|
private |
Definition at line 677 of file genconf.cpp.
683 <<
"\"\"\"Automatically generated. DO NOT EDIT please\"\"\"\n";
689 genImport( py,
"from {}.Configurable import *" );
692 db <<
"## -*- ascii -*- \n"
693 <<
"# db file automatically generated by genconf on: " << now <<
"\n"
◆ genImport()
void configGenerator::genImport |
( |
std::ostream & |
s, |
|
|
std::string_view |
frmt, |
|
|
std::string |
indent = "" |
|
) |
| |
|
private |
Definition at line 646 of file genconf.cpp.
648 std::string::size_type pos = 0, nxtpos = 0;
651 while ( std::string::npos != pos ) {
653 nxtpos =
m_configurable[component_t::Module].find_first_of(
',', pos );
657 std::ostringstream
import;
662 if ( std::string::npos == nxtpos ) {
664 s << indent <<
import.str() <<
"\n" << flush;
665 pos = std::string::npos;
668 s << indent <<
"try:\n" << indent << py_tab <<
import.str() <<
"\n" << indent <<
"except ImportError:\n" << flush;
◆ genTrailer()
void configGenerator::genTrailer |
( |
std::ostream & |
pyOut, |
|
|
std::ostream & |
dbOut |
|
) |
| |
|
private |
◆ pythonizeValue()
void configGenerator::pythonizeValue |
( |
const PropertyBase * |
prop, |
|
|
string & |
pvalue, |
|
|
string & |
ptype |
|
) |
| |
|
private |
handle the "marshalling" of Properties
Definition at line 831 of file genconf.cpp.
834 const std::string cvalue = p->toString();
835 const std::type_index ti = std::type_index( *p->type_info() );
838 if ( ti == typeIndex<bool>() ) {
839 pvalue = ( cvalue ==
"0" || cvalue ==
"False" || cvalue ==
"false" ) ?
"False" :
"True";
840 }
else if ( ti == typeIndex<char>() || ti == typeIndex<signed char>() || ti == typeIndex<unsigned char>() ||
841 ti == typeIndex<short>() || ti == typeIndex<unsigned short>() || ti == typeIndex<int>() ||
842 ti == typeIndex<unsigned int>() || ti == typeIndex<long>() || ti == typeIndex<unsigned long>() ||
843 ti == typeIndex<long long>() || ti == typeIndex<unsigned long long>() ) {
845 }
else if ( ti == typeIndex<float>() || ti == typeIndex<double>() ) {
847 pvalue = boost::to_lower_copy( cvalue );
848 if ( std::string::npos != pvalue.find(
"nan" ) ) {
849 pvalue =
"float('nan')";
850 }
else if ( std::string::npos == pvalue.find(
"." ) && std::string::npos == pvalue.find(
"e" ) ) {
851 pvalue = cvalue +
".0";
853 }
else if ( ti == typeIndex<string>() ) {
854 pvalue = quote( cvalue );
855 }
else if ( ti == typeIndex<GaudiHandleBase>() ) {
859 pvalue =
base.pythonRepr();
860 ptype =
base.pythonPropertyClassName();
862 }
else if ( ti == typeIndex<GaudiHandleArrayBase>() ) {
866 pvalue =
base.pythonRepr();
867 ptype =
base.pythonPropertyClassName();
873 pvalue =
base.pythonRepr();
876 std::ostringstream v_str;
877 v_str.setf( std::ios::showpoint );
878 p->toStream( v_str );
879 pvalue = v_str.str();
◆ setConfigurableAlgorithm()
void configGenerator::setConfigurableAlgorithm |
( |
const std::string & |
cfgAlgorithm | ) |
|
|
inline |
◆ setConfigurableAlgTool()
void configGenerator::setConfigurableAlgTool |
( |
const std::string & |
cfgAlgTool | ) |
|
|
inline |
◆ setConfigurableAuditor()
void configGenerator::setConfigurableAuditor |
( |
const std::string & |
cfgAuditor | ) |
|
|
inline |
◆ setConfigurableDefaultName()
void configGenerator::setConfigurableDefaultName |
( |
const std::string & |
defaultName | ) |
|
|
inline |
customize the default name for configurable instances
Definition at line 223 of file genconf.cpp.
◆ setConfigurableModule()
void configGenerator::setConfigurableModule |
( |
const std::string & |
moduleName | ) |
|
|
inline |
customize the Module name where configurable base classes are defined
Definition at line 220 of file genconf.cpp.
◆ setConfigurableService()
void configGenerator::setConfigurableService |
( |
const std::string & |
cfgService | ) |
|
|
inline |
◆ setConfigurableTypes()
void configGenerator::setConfigurableTypes |
( |
const std::set< conf_t > & |
types | ) |
|
|
inline |
customize configurable types to generate
Definition at line 217 of file genconf.cpp.
◆ m_configurable
std::map<component_t, std::string> configGenerator::m_configurable |
|
private |
Configurable customization.
Contains customization for:
- Name of the module where configurable base classes are defined
- Name of the configurable base class for the Algorithm component
- Name of the configurable base class for the AlgTool component
- Name of the configurable base class for the Service component
Definition at line 204 of file genconf.cpp.
◆ m_confTypes
std::set<conf_t> configGenerator::m_confTypes |
|
private |
Types of configurables to generate.
Definition at line 188 of file genconf.cpp.
◆ m_db2Buf
stringstream configGenerator::m_db2Buf |
|
private |
◆ m_dbBuf
stringstream configGenerator::m_dbBuf |
|
private |
buffer of generated configurables informations for the "Db" file The "Db" file is holding informations about the generated configurables This file is later one used by the PropertyProxy.py to locate Configurables and know their default values, host module,...
Definition at line 194 of file genconf.cpp.
◆ m_importDataHandles
bool configGenerator::m_importDataHandles = false |
|
private |
◆ m_importGaudiHandles
bool configGenerator::m_importGaudiHandles = false |
|
private |
switch to decide if the generated configurables need to import GaudiHandles (ie: if one of the components has a XyzHandle<T>)
Definition at line 184 of file genconf.cpp.
◆ m_outputDirName
string configGenerator::m_outputDirName |
|
private |
absolute path to the directory where genconf will store auto-generated files (Configurables and ConfigurableDb)
Definition at line 177 of file genconf.cpp.
◆ m_pkgName
string configGenerator::m_pkgName |
|
private |
name of the package we are processing
Definition at line 173 of file genconf.cpp.
◆ m_pyBuf
stringstream configGenerator::m_pyBuf |
|
private |
buffer of auto-generated configurables
Definition at line 180 of file genconf.cpp.
The documentation for this class was generated from the following file:
void genTrailer(std::ostream &pyOut, std::ostream &dbOut)
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
const GaudiHandleArrayBase & value() const
bool genComponent(const std::string &libName, const std::string &componentName, component_t componentType, const vector< PropertyBase * > &properties, const Gaudi::PluginService::Details::Registry::FactoryInfo &info)
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
DataHandleProperty.h GaudiKernel/DataHandleProperty.h.
std::set< conf_t > m_confTypes
Types of configurables to generate.
void * ImageHandle
Definition of an image handle.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
virtual unsigned long addRef() const =0
Increment the reference count of Interface instance.
stringstream m_dbBuf
buffer of generated configurables informations for the "Db" file The "Db" file is holding information...
bool m_importGaudiHandles
switch to decide if the generated configurables need to import GaudiHandles (ie: if one of the compon...
stringstream m_pyBuf
buffer of auto-generated configurables
GAUDI_API ISvcLocator * svcLocator()
AttribStringParser::Iterator begin(const AttribStringParser &parser)
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
bool genComponent2(const std::string &componentName, component_t componentType, const vector< PropertyBase * > &properties, const std::vector< std::string > &interfaces, const Gaudi::PluginService::Details::Registry::FactoryInfo &info)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
const GaudiHandleBase & value() const
string m_pkgName
name of the package we are processing
void genImport(std::ostream &s, std::string_view frmt, std::string indent)
std::map< component_t, std::string > m_configurable
Configurable customization.
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
Base class of array's of various gaudihandles.
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
GAUDIPS_API Logger & logger()
Return the current logger instance.
void genHeader(std::ostream &pyOut, std::ostream &dbOut)
static Time current()
Returns the current time.
string m_outputDirName
absolute path to the directory where genconf will store auto-generated files (Configurables and Confi...
stringstream m_db2Buf
buffer of generated GaudiConfig2 configurables
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
void pythonizeValue(const PropertyBase *prop, string &pvalue, string &ptype)
handle the "marshalling" of Properties
void genBody(std::ostream &pyOut, std::ostream &dbOut)
virtual unsigned long release() const =0
Release Interface instance.