Commit d69009c3 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Avoid an issue with the latest autopep8

See https://github.com/hhatto/autopep8/issues/346
parent cb656e95
......@@ -47,7 +47,7 @@ def setLibraryPreload(newpreload):
to_load = [libname
for libname in newpreload
if libname not in set(preload)]
if to_load:
preload += to_load
preload = ":".join(preload)
......@@ -66,7 +66,8 @@ def rationalizepath(path):
path = os.path.realpath(path)
return path
# variable used to keep alive the temporary option files extracted from the .qmt
# variable used to keep alive the temporary option files extracted
# from the .qmt
_qmt_tmp_opt_files = []
def getArgsFromQmt(qmtfile):
'''
......@@ -211,7 +212,7 @@ if __name__ == "__main__":
'memory)')
parser.add_option("--run-info-file", type="string",
help="Save gaudi process information to the file specified (in JSON format)")
parser.set_defaults(options = [],
tcmalloc = False,
profilerName = '',
......@@ -295,7 +296,7 @@ if __name__ == "__main__":
profilerName = opts.profilerName
profilerExecName = ""
profilerOutput = opts.profilerOutput or (profilerName + ".output")
# To restart the application removing the igprof option and prepending the string
args = getArgsWithoutoProfilerInfo(sys.argv)
......@@ -361,7 +362,7 @@ if __name__ == "__main__":
to_reload = []
if opts.preload:
to_reload = setLibraryPreload(opts.preload)
if profilerExecName:
# We profile python
profilerOptions += " python"
......@@ -491,5 +492,5 @@ if __name__ == "__main__":
logging.info("Saving run info to: %s" % opts.run_info_file)
with open(opts.run_info_file, "w") as f:
json.dump(run_info, f)
sys.exit(retcode)
......@@ -185,5 +185,3 @@ class SshSession(object) :
def __del__(self):
self.session.close()
print 'killed ppserver in ', self.host
# == EOF ====================================================================================
......@@ -14,68 +14,68 @@ histos = ['TH1D', 'TH1F', 'TH2D', 'TH2F', 'TProfile']
ref = 'REFERENCE'
test = 'TEST'
# =================================================================================================
# =============================================================================
# Method : rec( o, path=None, lst=None )
#
#
# @param o : a ROOT object
# @param path : a string like a transient store path; ie '/stat/CaloPIDs/ECALPIDE'
# @param lst : a list to hold (path, object) tuples
#
#
# function : recursively pull apart a ROOT file, making a list of (path, TObject) tuples
# This is done by GetListOfKeys method, which lets one work down through directories
# until you hit the Histo at the end of the path. The list of tuples is returned
#
#
def rec( o, path=None, lst=None ) :
if not path : path = '/stat' ; lst = []
else : path = path + '/' + o.GetName()
lst.append( (path,o) )
if 'GetListOfKeys' in dir(o) :
if 'GetListOfKeys' in dir(o) :
keys = o.GetListOfKeys()
for k in keys :
name = k.GetName()
rec( o.Get(name), path, lst )
rec( o.Get(name), path, lst )
else :
pass
return lst
# =================================================================================================
# =============================================================================
# =================================================================================================
# =============================================================================
# Method : composition( t )
#
#
# @param t : a tuple of ( type, d ) where type is either 'REFERENCE' or 'TEST'
# and d is a dictionary of ROOT objects, with each key = ROOT path
#
# and d is a dictionary of ROOT objects, with each key = ROOT path
#
# function : deduce the composition, (objects/histos) counts
#
def composition( t ) :
typ, d = t
typ, d = t
hists = 0 ; objs = 0
for k in d.keys() :
for k in d.keys() :
if d[k].__class__.__name__ in histos : hists += 1
else : objs += 1
return objs, hists
# =================================================================================================
# =================================================================================================
# =============================================================================
# =============================================================================
# Method : comparePaths( t1, t2 )
#
#
# @param t1, t2 : a tuple of ( type, d ) where type is either 'REFERENCE' or 'TEST'
# and d is a dictionary of ROOT objects, with each key = ROOT path
#
# and d is a dictionary of ROOT objects, with each key = ROOT path
#
# function : compare the paths between the two histo files. If the files are identical, they
# should have the same set of paths. The Test file should definitely have the
# same paths as the Reference. Perhaps the Reference file will have some more paths due
# to extra histos added as part of Application Sequencer finalisation
# Arguments t1 and t2 are checked and the test/reference auto-detected
#
def comparePaths( t1, t2 ) :
#
def comparePaths( t1, t2 ) :
if t1[0] == ref : ds = t1[1] ; dp = t2[1]
elif t2[0] == ref : ds = t2[1] ; dp = t1[1]
else : print 'Neither tuple is Reference Root file reference?' ; return
dsks = ds.keys() ; dpks = dp.keys()
dsks.sort() ; dpks.sort()
sset = set( dsks )
pset = set( dpks )
os, hs = composition( (ref, ds) )
......@@ -88,7 +88,7 @@ def comparePaths( t1, t2 ) :
matching = sset.intersection(pset)
matchingHistos = 0
for n in matching :
if ds[n].__class__.__name__ in histos : matchingHistos += 1
if ds[n].__class__.__name__ in histos : matchingHistos += 1
print '\nMatching paths : %i'%( len(matching) )
uSer = sset - pset
# work out histos unique to test file
......@@ -96,21 +96,21 @@ def comparePaths( t1, t2 ) :
for n in uSer :
if ds[n].__class__.__name__ in histos : uniqueReferenceHistos += 1
print 'Paths unique to Reference file : %i ( %i Histos )'%( len(uSer), uniqueReferenceHistos )
if uSer :
if uSer :
for n in uSer : print '\t%s : \t%s'%( ds[n], n )
uPar = pset - sset
uniqueTestHistos = 0
for n in uPar :
if dp[n].__class__.__name__ in histos : uniqueTestHistos += 1
print 'Paths unique to Test file : %i ( %i Histos )'%( len(uPar), uniqueTestHistos )
if uPar :
if uPar :
for n in uPar : print '\t%s : \t%s'%( dp[n], n )
print 'Matching Histos to test : %i'%( matchingHistos )
print '='*80 + '\n'
return ( ((os,hs),(op,hp)), (uSer, uniqueReferenceHistos), (uPar, uniqueTestHistos), matchingHistos )
# =================================================================================================
# =============================================================================
# =================================================================================================
# =============================================================================
# Method : bin2binIdentity(h1,h2)
#
# @param h1, h2 : The two histogtams to compare
......@@ -131,14 +131,14 @@ def bin2binIdentity(h1,h2):
h2bin=h2.GetBinContent(ibin)
diffbins+= (h1bin!=h2bin)
return diffbins
# =================================================================================================
# =============================================================================
# Method : compareHistos( t1, t2 )
#
#
# @param t1, t2 : a tuple of ( type, d ) where type is either 'REFERENCE' or 'TEST'
# and d is a dictionary of ROOT objects, with each key = ROOT path
#
# and d is a dictionary of ROOT objects, with each key = ROOT path
#
# function : compare the histograms in Reference/Test ROOT files. First, go through each
# dict to collect the histos (ignore TDirectory objects, etc). Then the histos
# in the test file (experimental) are compared to their equivalents in the
......@@ -148,11 +148,11 @@ def bin2binIdentity(h1,h2):
# 3) If integrals are equal, check the KolmogorovTest() ; should be 1
# 4) If identity flag is there and KS test is performed, perform bin2bin identity test
# Arguments t1 and t2 are checked and the test/reference auto-detected
#
#
def compareHistos(t1, t2, state, checkBin2BinIdentity) :
( ((referenceObjects,referenceHistos),(parallObjects, parallHistos)), (uniqueSerPaths,uniqueSerHistos), (uniqueParPaths,uniqueParHistos), mh ) = state
# deduce which one is test, which reference
if t1[0] == ref : ds = t1[1] ; dp = t2[1]
elif t2[0] == ref : ds = t2[1] ; dp = t1[1]
......@@ -163,16 +163,16 @@ def compareHistos(t1, t2, state, checkBin2BinIdentity) :
hcs = 0 ; sHistos = []
omit = [re.compile(regex) for regex in gRegexBlackList]
# find the histos in the reference file
for k in ds.keys() :
for k in ds.keys() :
if not any(regex.search(k)!=None for regex in omit):
if ds[k].__class__.__name__ in histos : hcs += 1 ; sHistos.append( k )
# same for test
for k in dp.keys() :
if not any(regex.search(k)!=None for regex in omit):
if dp[k].__class__.__name__ in histos : hcp += 1 ; pHistos.append( k )
cEntries = 0 ; xEntries = 0 ; diffEntries = []
cIntegrals = 0 ; xIntegrals = 0 ; diffIntegrals = []
......@@ -182,7 +182,7 @@ def compareHistos(t1, t2, state, checkBin2BinIdentity) :
kTestResults={}
notfound = 0 ; integralMatch = 0 ; otherTest = 0 ; zeroIntegralMatch = 0
for h in sHistos :
if h in pHistos :
if h in pHistos :
# matching histos to check
cEntries += 1
sh = ds[h] ; ph = dp[h]
......@@ -202,56 +202,56 @@ def compareHistos(t1, t2, state, checkBin2BinIdentity) :
failedIdentity += 1
diffIdentity.append(h)
identityDiffBins[h]=diffBins
if (bool(sint) and bool(pint)) and ( sBinError>0 and pBinError>0 ) :
if (bool(sint) and bool(pint)) and ( sBinError>0 and pBinError>0 ) :
kTested += 1
kTest = sh.KolmogorovTest(ph)
kTestResults [h] = kTest
if int(kTest) : passedKol += 1
else : failedKol += 1 ; diffKols.append(h) # ; print 'KTest result : ', kTest
else :
if int(kTest) : passedKol += 1
else : failedKol += 1 ; diffKols.append(h) # ; print 'KTest result : ', kTest
else :
# try the integral test?
otherTest += 1
if all((sint, pint)) and (sint==pint) :
if all((sint, pint)) and (sint==pint) :
integralMatch += 1
elif (sint==pint) :
zeroIntegralMatch += 1
else :
else :
diffIntegrals.append( h )
xIntegrals += 1
else :
notfound += 1 ; print 'not found? ', h
# report on Failed Entry-Checks
# report on Failed Entry-Checks
print '\n\n'+'-'*80
print 'Summary of histos with different Entries'
print '-'*80
if diffEntries :
diffEntries.sort()
for e in diffEntries : print '\t\t\t%s:\t%i != %i'%( e, int(ds[e].GetEntries()), int(dp[e].GetEntries()) )
diffEntries.sort()
for e in diffEntries : print '\t\t\t%s:\t%i != %i'%( e, int(ds[e].GetEntries()), int(dp[e].GetEntries()) )
print '-'*80
# report on Failed Kolmogorov Tests
# report on Failed Kolmogorov Tests
print '\n\n'+'-'*60
print 'Summary of histos which failed Kolmogorov Test'
print '-'*60
if diffKols :
diffKols.sort()
for e in diffKols :
diffKols.sort()
for e in diffKols :
result = kTestResults[e] # DP Calculated twice ARGH!!
print '%s\t\t%s :\tK-Test Result :\t %5.16f'%( ds[e].ClassName(), e, result )
print '%s\t\t%s :\tK-Test Result :\t %5.16f'%( ds[e].ClassName(), e, result )
print '-'*60
# report on Failed Integral Checks
print '\n\n'+'-'*60
print 'Summary of histos which failed Integral Check'
print '-'*60
if diffIntegrals :
diffIntegrals.sort()
for e in diffIntegrals :
for e in diffIntegrals :
diff = dp[e].Integral()-ds[e].Integral()
pc = (diff*100)/ds[e].Integral()
print '%s\t\t%s:\t Diff = %5.6f\tPercent Diff to Reference : %5.6f '%( ds[e].ClassName(), e, diff, pc )
print '-'*60 + '\n'
print '-'*60 + '\n'
print '='*80 + '\n'
# Report on failed bin2bin identity
......@@ -265,7 +265,7 @@ def compareHistos(t1, t2, state, checkBin2BinIdentity) :
for e in diffIdentity:
print '%s\t\t%s: %i different bins'%( ds[e].ClassName(), e, identityDiffBins[e])
print '-'*80
print '\n' + '='*80
print 'Comparison : Reference/Test ROOT Histo files'
print '\n\t\tReference\tTest'
......@@ -277,8 +277,8 @@ def compareHistos(t1, t2, state, checkBin2BinIdentity) :
print 'Objects/Histos unique to Test File : %i / %i'%( len(uniqueParPaths)-uniqueParHistos, uniqueParHistos )
print '\nMatching Histograms valid for Comparison : %i'%( mh )
print '\nOmissions\' patterns : '
for entry in gRegexBlackList : print '\t%s'%( entry )
print '\nHistograms for Comparison (after Omissions) : %i'%( mh-len(gRegexBlackList) )
for entry in gRegexBlackList : print '\t%s'%( entry )
print '\nHistograms for Comparison (after Omissions) : %i'%( mh-len(gRegexBlackList) )
print '\n\tHISTOGRAM TESTS : '
print '\t\tKOLMOGOROV TEST : %i'%( kTested )
print '\t\tINTEGRAL TEST : %i'%( otherTest )
......@@ -286,19 +286,19 @@ def compareHistos(t1, t2, state, checkBin2BinIdentity) :
if checkBin2BinIdentity:
print '\t\tBIN2BIN TEST : %i'%( passedIdentity )
print '\t\t ____'
print '\t\tTested : %i'%( cEntries )
print '\t\tTested : %i'%( cEntries )
print '\n\tDISCREPANCIES : '
print '\t\tK-Test : %i'%( failedKol )
print '\t\tIntegrals : %i'%( xIntegrals )
print '\t\tEntries : %i'%( xEntries )
print '\t\tIntegrals : %i'%( xIntegrals )
print '\t\tEntries : %i'%( xEntries )
retval = failedKol+xIntegrals+xEntries+failedIdentity
if retval!=0:
print '\nThe two sets of histograms were not identical'
print '\n'+'='*80
return retval
return retval
# =================================================================================================
# =============================================================================
def extractBlacklist(listString):
global gRegexBlackList
......@@ -308,7 +308,7 @@ def extractBlacklist(listString):
else:
gBlackList =[]
# =================================================================================================
# =============================================================================
if __name__ == '__main__' :
usage = "usage: %prog testFile.root referenceFile.root [options]"
......@@ -325,14 +325,14 @@ if __name__ == '__main__' :
print "Wrong number of rootfiles. Usage:"
print usage
sys.exit(1)
extractBlacklist(options.blacklist)
testFile,referenceFile=args
tfs = TFile( testFile, 'REC' ) ; print 'opening Test File : %s'%( testFile )
tfp = TFile( referenceFile, 'REC' ) ; print 'opening Reference File : %s'%( referenceFile )
# get structure of TFiles in a list of (path, object) tuples
lref = rec(tfs) ; ltest = rec(tfp)
# make a dictionary of lser and lpar. keys=paths
......@@ -340,18 +340,17 @@ if __name__ == '__main__' :
dtest = dict( [(n, o) for n, o in ltest] )
# make a tuple of (type, dict) where type is either 'reference' or 'test'
ts = ( ref, dref ) ; tp = ( test, dtest )
# check objs/histos in each file
composition( ts ) ; composition( tp )
# compare paths from each file
state = comparePaths( ts, tp )
# compare histos from each file
retval =compareHistos( ts, tp, state, checkBin2BinIdentity=options.bin2bin )
# finished with TFiles
tfs.Close() ; tfp.Close()
sys.exit(retval)
sys.exit(retval)
......@@ -502,11 +502,7 @@ class BaseTest(object):
reference = os.path.join(dirname, candidates[-1][1])
return reference
#---------------------------------------------------------------------------------------------------#
#---------------------------------------------------------------------------------------------------#
#-----------------------------------------GAUDI TOOLS-----------------------------------------------------#
#---------------------------------------------------------------------------------------------------#
#---------------------------------------------------------------------------------------------------#
# ======= GAUDI TOOLS =======
import shutil
import string
......
......@@ -74,7 +74,7 @@ else:
# forward to the actual implementation of GaudiPython::Helper::toArray<T>
toArray = lambda typ: getattr(Helper,"toArray<%s>"%typ)
#----Convenient accessors to PyROOT functionality ---------------------------------------
# ----Convenient accessors to PyROOT functionality ----------------------------
ROOT = cppyy.libPyROOT
makeNullPointer = cppyy.libPyROOT.MakeNullPointer
setOwnership = cppyy.libPyROOT.SetOwnership
......@@ -82,7 +82,7 @@ setOwnership = cppyy.libPyROOT.SetOwnership
def deprecation(message):
warnings.warn('GaudiPython: '+ message, DeprecationWarning, stacklevel=3)
#----InterfaceCast class ----------------------------------------------------------------
# ----InterfaceCast class -----------------------------------------------------
class InterfaceCast(object) :
""" Helper class to obtain the adequate interface from a component
by using the Gaudi queryInterface() mechanism """
......@@ -104,7 +104,7 @@ class InterfaceCast(object) :
traceback.print_stack()
return None
cast = __call__
#---Interface class (for backward compatibility)-----------------------------------------
# ---Interface class (for backward compatibility)------------------------------
class Interface(InterfaceCast) :
def __init__(self, t ):
deprecation('Use InterfaceCast class instead')
......@@ -112,7 +112,7 @@ class Interface(InterfaceCast) :
def cast(self, obj) :
return self(obj)
#----load dictionary function using Gaudi function---------------------------------------
# ----load dictionary function using Gaudi function----------------------------
def loaddict(dict) :
""" Load a LCG dictionary using various mechanisms"""
if Helper.loadDynamicLib(dict) == 1 : return
......@@ -122,7 +122,7 @@ def loaddict(dict) :
except:
raise ImportError, 'Error loading dictionary library'
#---get a class (by loading modules if needed)--------------------------------------------
# ---get a class (by loading modules if needed)--------------------------------
def getClass( name , libs = [] ) :
"""
Function to retrieve a certain C++ class by name and to load dictionary if requested
......@@ -147,7 +147,7 @@ def getClass( name , libs = [] ) :
# return None ( or raise exception? I do not know... )
return None
#----PropertyEntry class---------------------------------------------------------------------
# ----PropertyEntry class------------------------------------------------------
class PropertyEntry(object) :
""" holds the value and the documentation string of a property """
def __init__(self, prop) :
......@@ -182,7 +182,7 @@ class PropertyEntry(object) :
def hasDoc(self):
return len(self.__doc__)>0 and self.__doc__ != 'none'
#----iProperty class---------------------------------------------------------------------
# ----iProperty class----------------------------------------------------------
class iProperty(object) :
""" Python equivalent to the C++ Property interface """
def __init__(self, name, ip = None) :
......@@ -289,7 +289,7 @@ class iProperty(object) :
def name(self) :
return self._name
#----iService class---------------------------------------------------------------------
# ----iService class-----------------------------------------------------------
class iService(iProperty) :
""" Python equivalent to IProperty interface """
def __init__(self, name, isvc = None ) :
......@@ -309,7 +309,7 @@ class iService(iProperty) :
if self._isvc: return True
else : return False
#----iAlgorithm class---------------------------------------------------------------------
# ----iAlgorithm class---------------------------------------------------------
class iAlgorithm(iProperty) :
""" Python equivalent to IAlgorithm interface """
def __init__(self, name, ialg = None ) :
......@@ -334,7 +334,7 @@ class iAlgorithm(iProperty) :
sysReinitialize = lambda self : self.__call_interface_method__("_ialg","sysReinitialize")
sysRestart = lambda self : self.__call_interface_method__("_ialg","sysRestart")
#----iAlgTool class---------------------------------------------------------------------
# ----iAlgTool class-----------------------------------------------------------
class iAlgTool(iProperty) :
""" Python equivalent to IAlgTool interface (not completed yet) """
def __init__(self, name, itool = None ) :
......@@ -353,7 +353,7 @@ class iAlgTool(iProperty) :
if self._itool : return self._itool.name()
else : return self._name
#----iDataSvc class---------------------------------------------------------------------
# ----iDataSvc class-----------------------------------------------------------
class iDataSvc(iService) :
def __init__(self, name, idp) :
iService.__init__(self, name, idp )
......@@ -478,7 +478,7 @@ class iDataSvc(iService) :
return self._idm.clearStore()
#----iHistogramSvc class---------------------------------------------------------------------
# ----iHistogramSvc class------------------------------------------------------
class iHistogramSvc(iDataSvc) :
def __init__(self, name, ihs) :
self.__dict__['_ihs'] = InterfaceCast(gbl.IHistogramSvc)(ihs)
......@@ -547,7 +547,7 @@ class iHistogramSvc(iDataSvc) :
fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
return fun( self.getAsAIDA( path ) )
#----iNTupleSvc class---------------------------------------------------------------------
# ----iNTupleSvc class---------------------------------------------------------
class iNTupleSvc(iDataSvc) :
RowWiseTuple = 42
ColumnWiseTuple = 43
......@@ -571,7 +571,7 @@ class iNTupleSvc(iDataSvc) :
return iDataSvc.__getitem__( self , path )
#----iToolSvc class---------------------------------------------------------------------
# ----iToolSvc class-----------------------------------------------------------
class iToolSvc(iService) :
def __init__(self, name, its) :
self.__dict__['_its'] = InterfaceCast(gbl.IToolSvc)(its)
......@@ -604,7 +604,7 @@ class iToolSvc(iService) :
if type(itool) is iAlgTool :
self._its.releaseTool(itool._itool)
#----iJopOptSvc class-------------------------------------------------------------------
# ----iJopOptSvc class---------------------------------------------------------
class iJobOptSvc(iService) :
"""
Python-image of C++ class IJobOptionsSvc
......@@ -643,7 +643,7 @@ class iJobOptSvc(iService) :
all = self.getProperties ( component )
return all.get( name.upper() , None ) # RETURN
#----iEventSelector class------------------------------------------------------------------
# ----iEventSelector class-----------------------------------------------------
class iEventSelector(iService):
def __init__(self):
iService.__init__(self, 'EventSelector', Helper.service(gbl.Gaudi.svcLocator(),'EventSelector'))
......@@ -658,7 +658,7 @@ class iEventSelector(iService):
# It is not possible to reinitialize EventSelector only
self.g.service('EventLoopMgr').reinitialize()
#----AppMgr class---------------------------------------------------------------------
# ----AppMgr class-------------------------------------------------------------
class AppMgr(iService) :
def __new__ ( cls, *args, **kwargs ):
global _gaudi
......@@ -1031,7 +1031,7 @@ class AppMgr(iService) :
toolSvc = toolsvc
partSvc = partsvc
#--------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
def _getFIDandEvents( pfn ):
tfile = gbl.TFile.Open(pfn)
if not tfile : raise 'Cannot open ROOT file ', pfn
......@@ -1044,7 +1044,7 @@ def _getFIDandEvents( pfn ):
tfile.Close()
return fid, nevt
#--------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
def getComponentProperties( name ):
""" Get all the properties of a component as a Python dictionary.
The component is instantiated using the component library
......@@ -1097,7 +1097,7 @@ def _copyFactoriesFromList(factories) :
factories.push_back(factory)
return result
#----CallbackStreamBuf----------------------------------------------------------------
# ----CallbackStreamBuf--------------------------------------------------------
# Used for redirecting C++ messages to python
_CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
class CallbackStreamBuf (_CallbackStreamBufBase):
......@@ -1109,7 +1109,7 @@ class CallbackStreamBuf (_CallbackStreamBufBase):
self.callback(string)
return 0
#----PyAlgorithm----------------------------------------------------------------------
# ----PyAlgorithm--------------------------------------------------------------
# Used to implement Algorithms in Python
_PyAlgorithm = gbl.GaudiPython.PyAlgorithm
class PyAlgorithm (_PyAlgorithm) :
......@@ -1131,7 +1131,7 @@ class PyAlgorithm (_PyAlgorithm) :
def beginRun(self) : return 1
def endRun(self) : return 1
#----Enable tab completion------------------------------------------------------------
# ----Enable tab completion----------------------------------------------------<