From 901f818993e12e2d08ca7e7dea096dc2365a4551 Mon Sep 17 00:00:00 2001 From: ibelyaev <Ivan.Belyaev@cern.ch> Date: Sat, 9 Mar 2019 14:25:50 +0100 Subject: [PATCH 1/2] Fix RebuildSelection for non-trivial structures in Common/Standard particles --- .../python/PhysSelPython/Wrappers.py | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py b/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py index a716e739d..a5f4c157b 100755 --- a/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py +++ b/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py @@ -2062,18 +2062,43 @@ def RebuildSelection ( selection , replace = True , prefix = 'REBUILD:%s' ) : >>> from StandardParticles StdLoosePions >>> pions = RebuildSelection ( StdLoosePions ) ## by selection """ + + module = None + if isinstance ( selection , AutomaticData ) : - n = selection .name() - n = n[:n.find('_Particles')] - d,r,n = n.rpartition('_') - if r and n : selection = n - - if isinstance ( selection , str ) : + n = selection . name () + # n = n[:n.find('_Particles')] + # d,r,n = n.rpartition('_') + # if r and n : selection = n + phys , slash , nam = n.rpartition('/') + assert slash and nam, "RebuildSelection can't deduce the algorithm name from '%'" % n + selection = nam + + if isinstance ( selection , str ) : + import importlib - COMMON = importlib.import_module ( 'CommonParticles.%s' % selection ) - algorithm = COMMON.algorithm - if not algorithm : - raise AttributeError('No proper algorithm is found!') + algorithm = None + try : + + COMMON = importlib.import_module ( 'CommonParticles.%s' % selection ) + if hasattr ( COMMON , 'algorithm' ) : algorithm = COMMON.algorithm + elif hasattr ( COMMON , selection ) : algorithm = getattr ( COMMON , selection ) + + except: + + import CommonParticles + for i in dir(CommonParticles) : + if not isinstance ( i , str ) : continue + try : + COMMON = importlib.import_module ( 'CommonParticles.%s' % i ) + if hasattr ( COMMON , selection ) : + algorithm = getattr ( COMMON , selection ) + break + except : + continue + + assert not algorithm is None, "Сan't find proper selection %s" % selection + elif isinstance ( selection , Configurable ) : algorithm = selection else : raise AttributeError("Unknown selection type") -- GitLab From ea5bab0c04b582280d6ffa0b782170a762f85411 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues <eduardo.rodrigues@cern.ch> Date: Tue, 12 Mar 2019 11:31:57 +0000 Subject: [PATCH 2/2] Update Wrappers.py --- PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py b/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py index a5f4c157b..9152e7188 100755 --- a/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py +++ b/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py @@ -2071,7 +2071,7 @@ def RebuildSelection ( selection , replace = True , prefix = 'REBUILD:%s' ) : # d,r,n = n.rpartition('_') # if r and n : selection = n phys , slash , nam = n.rpartition('/') - assert slash and nam, "RebuildSelection can't deduce the algorithm name from '%'" % n + assert slash and nam, "RebuildSelection can't deduce the algorithm name from %" % n selection = nam if isinstance ( selection , str ) : @@ -2079,7 +2079,6 @@ def RebuildSelection ( selection , replace = True , prefix = 'REBUILD:%s' ) : import importlib algorithm = None try : - COMMON = importlib.import_module ( 'CommonParticles.%s' % selection ) if hasattr ( COMMON , 'algorithm' ) : algorithm = COMMON.algorithm elif hasattr ( COMMON , selection ) : algorithm = getattr ( COMMON , selection ) -- GitLab