From 26153be28d069b305207aa44517bd945c14dcb07 Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Mon, 6 Jan 2025 10:41:54 +0100 Subject: [PATCH 1/5] Use standard locations if the LD_LIBRARY_PATH or ROOTSYS are empty --- DDCore/python/dd4hepFactories.py | 5 +++- DDCore/python/dd4hep_base.py | 30 +++++++++++++++++----- GaudiPluginService/src/PluginServiceV1.cpp | 5 ++-- GaudiPluginService/src/PluginServiceV2.cpp | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/DDCore/python/dd4hepFactories.py b/DDCore/python/dd4hepFactories.py index 4a77012e9..6a43b20e3 100755 --- a/DDCore/python/dd4hepFactories.py +++ b/DDCore/python/dd4hepFactories.py @@ -27,7 +27,10 @@ def __init__(self): self.all_components = [] def scanPath(self): - ldp = os.environ['LD_LIBRARY_PATH'].split(':') + if os.getenv("LD_LIBRARY_PATH") is not None: + ldp = os.environ['LD_LIBRARY_PATH'].split(':') + else: + ldp = [ '/usr/lib64', '/usr/lib/', '/usr/local/lib', '/usr/lib64/root', '/usr/lib/root', '/usr/local/lib/root' ] for p in ldp: if len(p): logger.info('+== Search component directory: ' + p) diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index 64328ef28..7bb6c4b5e 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -25,13 +25,24 @@ def compileAClick(dictionary, g4=True): """ from ROOT import gInterpreter, gSystem import os.path - dd4hep = os.environ['DD4hepINSTALL'] - inc = ' -I' + os.environ['ROOTSYS'] + '/include -I' + dd4hep + '/include ' - lib = ' -L' + dd4hep + '/lib -lDDCore -lDDG4 -lDDSegmentation ' + if os.getenv("DD4hepINSTALL") is not None: + dd4hep = os.environ['DD4hepINSTALL'] + else: + dd4hep = "/usr" + if os.getenv("ROOTSYS") is not None: + rootsys = os.environ['ROOTSYS'] + else: + rootsys = "/usr" + + inc = ' -I' + rootsys + '/include -I' + dd4hep + '/include ' + lib = ' -L' + dd4hep + '/lib64 '+ ' -L' + dd4hep + '/lib -lDDCore -lDDG4 -lDDSegmentation ' if g4: - geant4 = os.environ['G4INSTALL'] + if os.getenv("G4INSTALL") is not None: + geant4 = os.environ['G4INSTALL'] + else: + geant4 = "/usr" inc = inc + ' -I' + geant4 + '/include/Geant4 -Wno-shadow -g -O0 ' - lib = lib + ' -L' + geant4 + '/lib -L' + geant4 + '/lib64 -lG4event -lG4tracking -lG4particles ' + lib = lib + ' -L' + geant4 + '/lib64 -L' + geant4 + '/lib -lG4event -lG4tracking -lG4particles ' gSystem.AddIncludePath(inc) gSystem.AddLinkedLibs(lib) @@ -50,7 +61,14 @@ def loaddd4hep(): import os import sys # Add ROOT to the python path in case it is not yet there.... - sys.path.append(os.environ['ROOTSYS'] + os.sep + 'lib') + if os.getenv("ROOTSYS") is not None: + rootsys = os.environ['ROOTSYS'] + else: + rootsys = "/usr" + sys.path.append(rootsys + os.sep + 'lib') + sys.path.append(rootsys + os.sep + 'lib64') + sys.path.append(rootsys + os.sep + 'lib' + os.sep +'root') + sys.path.append(rootsys + os.sep + 'lib64' + os.sep +'root') from ROOT import gSystem import platform diff --git a/GaudiPluginService/src/PluginServiceV1.cpp b/GaudiPluginService/src/PluginServiceV1.cpp index d0f741bb7..c814730d3 100644 --- a/GaudiPluginService/src/PluginServiceV1.cpp +++ b/GaudiPluginService/src/PluginServiceV1.cpp @@ -156,9 +156,10 @@ namespace Gaudi { const char sep = ':'; #endif char* search_path = ::getenv( envVar ); - if ( search_path ) { + if ( true ) { logger().debug( std::string( "searching factories in " ) + envVar ); - std::string path( search_path ); + std::string path; + if ( search_path ) path = std::string(search_path); else path="/usr/lib64:/usr/lib:/usr/local/lib"; std::string::size_type pos = 0; std::string::size_type newpos = 0; while ( pos != std::string::npos ) { diff --git a/GaudiPluginService/src/PluginServiceV2.cpp b/GaudiPluginService/src/PluginServiceV2.cpp index 7b520e75f..06da671ec 100644 --- a/GaudiPluginService/src/PluginServiceV2.cpp +++ b/GaudiPluginService/src/PluginServiceV2.cpp @@ -158,7 +158,7 @@ namespace Gaudi { std::string search_path; const char* envPtr = std::getenv( envVar.c_str() ); - if ( envPtr ) search_path = envPtr; + if ( envPtr ) search_path = envPtr; else search_path="/usr/lib64:/usr/lib:/usr/local/lib"; if ( search_path.empty() ) { return; } From e320ac5b6231abbf8d0460fec82f32b1631b11fe Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Mon, 6 Jan 2025 12:03:39 +0100 Subject: [PATCH 2/5] Formatting --- DDCore/python/dd4hepFactories.py | 2 +- DDCore/python/dd4hep_base.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DDCore/python/dd4hepFactories.py b/DDCore/python/dd4hepFactories.py index 6a43b20e3..71a1b4e05 100755 --- a/DDCore/python/dd4hepFactories.py +++ b/DDCore/python/dd4hepFactories.py @@ -30,7 +30,7 @@ def scanPath(self): if os.getenv("LD_LIBRARY_PATH") is not None: ldp = os.environ['LD_LIBRARY_PATH'].split(':') else: - ldp = [ '/usr/lib64', '/usr/lib/', '/usr/local/lib', '/usr/lib64/root', '/usr/lib/root', '/usr/local/lib/root' ] + ldp = ['/usr/lib64', '/usr/lib/', '/usr/local/lib', '/usr/lib64/root', '/usr/lib/root', '/usr/local/lib/root'] for p in ldp: if len(p): logger.info('+== Search component directory: ' + p) diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index 7bb6c4b5e..698b804ef 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -35,7 +35,7 @@ def compileAClick(dictionary, g4=True): rootsys = "/usr" inc = ' -I' + rootsys + '/include -I' + dd4hep + '/include ' - lib = ' -L' + dd4hep + '/lib64 '+ ' -L' + dd4hep + '/lib -lDDCore -lDDG4 -lDDSegmentation ' + lib = ' -L' + dd4hep + '/lib64 ' + ' -L' + dd4hep + '/lib -lDDCore -lDDG4 -lDDSegmentation ' if g4: if os.getenv("G4INSTALL") is not None: geant4 = os.environ['G4INSTALL'] @@ -67,8 +67,8 @@ def loaddd4hep(): rootsys = "/usr" sys.path.append(rootsys + os.sep + 'lib') sys.path.append(rootsys + os.sep + 'lib64') - sys.path.append(rootsys + os.sep + 'lib' + os.sep +'root') - sys.path.append(rootsys + os.sep + 'lib64' + os.sep +'root') + sys.path.append(rootsys + os.sep + 'lib' + os.sep + 'root') + sys.path.append(rootsys + os.sep + 'lib64' + os.sep + 'root') from ROOT import gSystem import platform From b79da51486a9d7e62efef9259171785565d731a4 Mon Sep 17 00:00:00 2001 From: andriish Date: Thu, 9 Jan 2025 04:51:07 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Andre Sailer --- GaudiPluginService/src/PluginServiceV1.cpp | 2 +- GaudiPluginService/src/PluginServiceV2.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GaudiPluginService/src/PluginServiceV1.cpp b/GaudiPluginService/src/PluginServiceV1.cpp index c814730d3..58d89cb56 100644 --- a/GaudiPluginService/src/PluginServiceV1.cpp +++ b/GaudiPluginService/src/PluginServiceV1.cpp @@ -159,7 +159,7 @@ namespace Gaudi { if ( true ) { logger().debug( std::string( "searching factories in " ) + envVar ); std::string path; - if ( search_path ) path = std::string(search_path); else path="/usr/lib64:/usr/lib:/usr/local/lib"; + path = search_path ? std::string(search_path) : "/usr/lib64:/usr/lib:/usr/local/lib"; std::string::size_type pos = 0; std::string::size_type newpos = 0; while ( pos != std::string::npos ) { diff --git a/GaudiPluginService/src/PluginServiceV2.cpp b/GaudiPluginService/src/PluginServiceV2.cpp index 06da671ec..4afd1187d 100644 --- a/GaudiPluginService/src/PluginServiceV2.cpp +++ b/GaudiPluginService/src/PluginServiceV2.cpp @@ -158,7 +158,7 @@ namespace Gaudi { std::string search_path; const char* envPtr = std::getenv( envVar.c_str() ); - if ( envPtr ) search_path = envPtr; else search_path="/usr/lib64:/usr/lib:/usr/local/lib"; + search_path = envPtr ? envPtr : "/usr/lib64:/usr/lib:/usr/local/lib"; if ( search_path.empty() ) { return; } From 826dce31427e5bc68ba680e394e88b9bb916540f Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Thu, 9 Jan 2025 05:04:39 +0100 Subject: [PATCH 4/5] Implement comments --- DDCore/python/dd4hep_base.py | 28 ++-- GaudiPluginService/src/PluginServiceV1.cpp | 143 ++++++++++----------- 2 files changed, 78 insertions(+), 93 deletions(-) diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index 698b804ef..62bf4c988 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -25,22 +25,13 @@ def compileAClick(dictionary, g4=True): """ from ROOT import gInterpreter, gSystem import os.path - if os.getenv("DD4hepINSTALL") is not None: - dd4hep = os.environ['DD4hepINSTALL'] - else: - dd4hep = "/usr" - if os.getenv("ROOTSYS") is not None: - rootsys = os.environ['ROOTSYS'] - else: - rootsys = "/usr" + dd4hep = os.getenv("DD4hepINSTALL", "/usr") + rootsys = os.getenv("ROOTSYS", "/usr") inc = ' -I' + rootsys + '/include -I' + dd4hep + '/include ' lib = ' -L' + dd4hep + '/lib64 ' + ' -L' + dd4hep + '/lib -lDDCore -lDDG4 -lDDSegmentation ' if g4: - if os.getenv("G4INSTALL") is not None: - geant4 = os.environ['G4INSTALL'] - else: - geant4 = "/usr" + geant4 = os.getenv('G4INSTALL', "/usr") inc = inc + ' -I' + geant4 + '/include/Geant4 -Wno-shadow -g -O0 ' lib = lib + ' -L' + geant4 + '/lib64 -L' + geant4 + '/lib -lG4event -lG4tracking -lG4particles ' @@ -61,14 +52,11 @@ def loaddd4hep(): import os import sys # Add ROOT to the python path in case it is not yet there.... - if os.getenv("ROOTSYS") is not None: - rootsys = os.environ['ROOTSYS'] - else: - rootsys = "/usr" - sys.path.append(rootsys + os.sep + 'lib') - sys.path.append(rootsys + os.sep + 'lib64') - sys.path.append(rootsys + os.sep + 'lib' + os.sep + 'root') - sys.path.append(rootsys + os.sep + 'lib64' + os.sep + 'root') + rootsys = os.getenv("ROOTSYS","/usr") + sys.path.append(os.path.join(rootsys, 'lib')) + sys.path.append(os.path.join(rootsys, 'lib64')) + sys.path.append(os.path.join(rootsys, 'lib', 'root')) + sys.path.append(os.path.join(rootsys, 'lib64', 'root')) from ROOT import gSystem import platform diff --git a/GaudiPluginService/src/PluginServiceV1.cpp b/GaudiPluginService/src/PluginServiceV1.cpp index 58d89cb56..2ec602b7b 100644 --- a/GaudiPluginService/src/PluginServiceV1.cpp +++ b/GaudiPluginService/src/PluginServiceV1.cpp @@ -156,85 +156,82 @@ namespace Gaudi { const char sep = ':'; #endif char* search_path = ::getenv( envVar ); - if ( true ) { - logger().debug( std::string( "searching factories in " ) + envVar ); - std::string path; - path = search_path ? std::string(search_path) : "/usr/lib64:/usr/lib:/usr/local/lib"; - std::string::size_type pos = 0; - std::string::size_type newpos = 0; - while ( pos != std::string::npos ) { - std::string dirName; - // get the next entry in the path - newpos = path.find( sep, pos ); - if ( newpos != std::string::npos ) { - dirName = path.substr( pos, newpos - pos ); - pos = newpos + 1; - } else { - dirName = path.substr( pos ); - pos = newpos; - } - logger().debug( std::string( " looking into " ) + dirName ); - // look for files called "*.components" in the directory - DIR* dir = opendir( dirName.c_str() ); - if ( dir ) { - struct dirent* entry; - while ( ( entry = readdir( dir ) ) ) { - std::string name( entry->d_name ); - // check if the file name ends with ".components" - std::string::size_type extpos = name.find( ".components" ); - if ( ( extpos != std::string::npos ) && ( ( extpos + 11 ) == name.size() ) ) { - std::string fullPath = ( dirName + '/' + name ); - { // check if it is a regular file - struct stat buf; - if ( 0 != ::stat( fullPath.c_str(), &buf ) ) - continue; - else if ( !S_ISREG( buf.st_mode ) ) - continue; + logger().debug( std::string( "searching factories in " ) + envVar ); + std::string path = search_path ? std::string(search_path) : "/usr/lib64:/usr/lib:/usr/local/lib"; + std::string::size_type pos = 0; + std::string::size_type newpos = 0; + while ( pos != std::string::npos ) { + std::string dirName; + // get the next entry in the path + newpos = path.find( sep, pos ); + if ( newpos != std::string::npos ) { + dirName = path.substr( pos, newpos - pos ); + pos = newpos + 1; + } else { + dirName = path.substr( pos ); + pos = newpos; + } + logger().debug( std::string( " looking into " ) + dirName ); + // look for files called "*.components" in the directory + DIR* dir = opendir( dirName.c_str() ); + if ( dir ) { + struct dirent* entry; + while ( ( entry = readdir( dir ) ) ) { + std::string name( entry->d_name ); + // check if the file name ends with ".components" + std::string::size_type extpos = name.find( ".components" ); + if ( ( extpos != std::string::npos ) && ( ( extpos + 11 ) == name.size() ) ) { + std::string fullPath = ( dirName + '/' + name ); + { // check if it is a regular file + struct stat buf; + if ( 0 != ::stat( fullPath.c_str(), &buf ) ) + continue; + else if ( !S_ISREG( buf.st_mode ) ) + continue; + } + // read the file + logger().debug( std::string( " reading " ) + name ); + std::ifstream factories{fullPath}; + std::string line; + int factoriesCount = 0; + int lineCount = 0; + while ( !factories.eof() ) { + ++lineCount; + std::getline( factories, line ); + trim( line ); + // skip empty lines and lines starting with '#' + if ( line.empty() || line[0] == '#' ) continue; + // only accept "v1" factories + if ( line.substr( 0, 4 ) == "v1::" ) + line = line.substr( 4 ); + else + continue; + // look for the separator + auto pos = line.find( ':' ); + if ( pos == std::string::npos ) { + logger().warning( "failed to parse line " + fullPath + ':' + std::to_string( lineCount ) ); + continue; } - // read the file - logger().debug( std::string( " reading " ) + name ); - std::ifstream factories{fullPath}; - std::string line; - int factoriesCount = 0; - int lineCount = 0; - while ( !factories.eof() ) { - ++lineCount; - std::getline( factories, line ); - trim( line ); - // skip empty lines and lines starting with '#' - if ( line.empty() || line[0] == '#' ) continue; - // only accept "v1" factories - if ( line.substr( 0, 4 ) == "v1::" ) - line = line.substr( 4 ); - else - continue; - // look for the separator - auto pos = line.find( ':' ); - if ( pos == std::string::npos ) { - logger().warning( "failed to parse line " + fullPath + ':' + std::to_string( lineCount ) ); - continue; - } - const std::string lib( line, 0, pos ); - const std::string fact( line, pos + 1 ); - m_factories.emplace( fact, FactoryInfo( lib ) ); + const std::string lib( line, 0, pos ); + const std::string fact( line, pos + 1 ); + m_factories.emplace( fact, FactoryInfo( lib ) ); #ifdef GAUDI_REFLEX_COMPONENT_ALIASES - // add an alias for the factory using the Reflex convention - std::string old_name = old_style_name( fact ); - if ( fact != old_name ) { - FactoryInfo old_info( lib ); - old_info.properties["ReflexName"] = "true"; - m_factories.emplace( old_name, old_info ); - } -#endif - ++factoriesCount; - } - if ( logger().level() <= Logger::Debug ) { - logger().debug( " found " + std::to_string( factoriesCount ) + " factories" ); + // add an alias for the factory using the Reflex convention + std::string old_name = old_style_name( fact ); + if ( fact != old_name ) { + FactoryInfo old_info( lib ); + old_info.properties["ReflexName"] = "true"; + m_factories.emplace( old_name, old_info ); } +#endif + ++factoriesCount; + } + if ( logger().level() <= Logger::Debug ) { + logger().debug( " found " + std::to_string( factoriesCount ) + " factories" ); } } - closedir( dir ); } + closedir( dir ); } } } From 875c1fe67e0c4cb7b45e2ab2874d3f991c651211 Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Thu, 9 Jan 2025 05:08:39 +0100 Subject: [PATCH 5/5] Implement comments --- DDCore/python/dd4hepFactories.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/DDCore/python/dd4hepFactories.py b/DDCore/python/dd4hepFactories.py index 71a1b4e05..edcbefa2c 100755 --- a/DDCore/python/dd4hepFactories.py +++ b/DDCore/python/dd4hepFactories.py @@ -27,10 +27,7 @@ def __init__(self): self.all_components = [] def scanPath(self): - if os.getenv("LD_LIBRARY_PATH") is not None: - ldp = os.environ['LD_LIBRARY_PATH'].split(':') - else: - ldp = ['/usr/lib64', '/usr/lib/', '/usr/local/lib', '/usr/lib64/root', '/usr/lib/root', '/usr/local/lib/root'] + ldp = os.getenv("LD_LIBRARY_PATH","/usr/lib64:/usr/lib/:/usr/local/lib:/usr/lib64/root:/usr/lib/root:/usr/local/lib/root").split(':') for p in ldp: if len(p): logger.info('+== Search component directory: ' + p)