diff --git a/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py b/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py index a716e739d4105a30309d9bd6b09bd2f166583ba5..9152e7188bdafe758abffbe6fadee6dda3acec89 100755 --- a/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py +++ b/PhysSel/PhysSelPython/python/PhysSelPython/Wrappers.py @@ -2062,18 +2062,42 @@ 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")