Skip to content
Snippets Groups Projects

[WIP] Fix RebuildSelection for non-trivial structures in Common/Standard particles

Closed Eduardo Rodrigues requested to merge erodrigu-cherrypick-2017 into 2017-patches
1 file
+ 34
10
Compare changes
  • Side-by-side
  • Inline
@@ -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")
Loading