Commit 24ec9f13 authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'py3.LArG4Validation-20200224' into 'master'

LArG4Validation: Python 3 / flake8 fixes

See merge request atlas/athena!30568
parents a65f6517 b9bae94e
......@@ -37,3 +37,10 @@ atlas_install_joboptions( share/*.py )
atlas_install_runtime( test/*.xml )
atlas_install_scripts( share/AODElectronContainerReader.py share/LArG4ValidationGenerate.py share/LArG4AODNtuplePlotter.py share/LArG4ValidationPlotter.py )
atlas_add_test( flake8
SCRIPT flake8 --select=ATL,F,E7,E9,W6 ${CMAKE_CURRENT_SOURCE_DIR}/python
POST_EXEC_SCRIPT nopost.sh )
atlas_add_test( flake8_share
SCRIPT flake8 --select=ATL,F,E7,E9,W6 --ignore=F401,F821,ATL900 ${CMAKE_CURRENT_SOURCE_DIR}/share
POST_EXEC_SCRIPT nopost.sh )
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
from __future__ import print_function
__author__ = 'Radist Morse radist.morse@gmail.com'
......@@ -36,7 +38,7 @@ def parseRoots(filename) :
rf.markersize = float(line[5])
rf.legendname = " ".join(line[6:])
parsedRoots.append(rf)
print "Found rootfile '"+rf.filename+"' added as '"+rf.legendname+"'"
print ("Found rootfile '"+rf.filename+"' added as '"+rf.legendname+"'")
if line[0] == "restrict" :
re = RestrictEntry()
abs = False
......@@ -58,10 +60,10 @@ def parseRoots(filename) :
rech.rangeList += re.rangeList
re.rangeList = []
if (len(re.rangeList) > 0) : #no restriction for this variable yet. add it.
print "A restriction found for variable",str(re)
print ("A restriction found for variable",str(re))
rstrict.append(re)
else :
print "WARNING: unknown key:", line[0]
print ("WARNING: unknown key:", line[0])
continue
for pr in parsedRoots : #apply global restrictions on every plot
for re in parsedRestricts :
......@@ -123,25 +125,25 @@ class RestrictEntry :
parsed = rang.split("..")
try :
parsed[0] = float(parsed[0])
except :
except ValueError:
parsed[0] = -999999.9
try :
parsed[1] = float(parsed[1])
except :
except ValueError:
parsed[1] = 9999999.9
self.rangeList.append(parsed[0:2])
def addRangeAbs(self,rang) :
parsed = rang.split("..")
try :
parsed[0] = float(parsed[0])
except :
except ValueError:
parsed[0] = 0.0
try :
parsed[1] = float(parsed[1])
except :
except ValueError:
parsed[1] = 9999999.9
if (parsed[0] < 0) or (parsed[1] <= 0) :
print "WARNING: The absolute range is not valid: less then zero. Ignore."
print ("WARNING: The absolute range is not valid: less then zero. Ignore.")
return
rang = str(parsed[0])+".."+str(parsed[1])
rang2 = str(-parsed[1])+".."+str(-parsed[0])
......@@ -174,10 +176,10 @@ def parsePlots(filename,varCaption) :
varcap = var.lstrip("+")
pe.axis_captions[var.lstrip("+")]=varcap
if (pe.vars_to_draw[0].startswith("+")) and ((pe.givenmin < 0) or (pe.givenmax < 0)) :
print "WARNING: Boundaries are less the zero, while the variable is absolute. Ignore."
print ("WARNING: Boundaries are less the zero, while the variable is absolute. Ignore.")
pe.givenmin = 0.0
pe.givenmax = 0.0
print "Found 1D histogram:",pe.vars_to_draw[0],[pe.givenmin,pe.givenmax]
print ("Found 1D histogram:",pe.vars_to_draw[0],[pe.givenmin,pe.givenmax])
parsedPlots.append(pe)
elif line[0] == "prof" :
pe.vars_to_draw.extend(line[1:3])
......@@ -193,10 +195,10 @@ def parsePlots(filename,varCaption) :
varcap = var.lstrip("+")
pe.axis_captions[var.lstrip("+")]=varcap
if (pe.vars_to_draw[0].startswith("+")) and ((pe.givenmin < 0) or (pe.givenmax < 0)) :
print "WARNING: Boundaries are less the zero, while the variable is absolute. Ignore."
print ("WARNING: Boundaries are less the zero, while the variable is absolute. Ignore.")
pe.givenmin = 0.0
pe.givenmax = 0.0
print "Found 1D profile:",pe.vars_to_draw[1],"vs",pe.vars_to_draw[0],[pe.givenmin,pe.givenmax]
print ("Found 1D profile:",pe.vars_to_draw[1],"vs",pe.vars_to_draw[0],[pe.givenmin,pe.givenmax])
parsedPlots.append(pe)
elif line[0] == "hist2d" :
pe = PlotEntry()
......@@ -212,7 +214,7 @@ def parsePlots(filename,varCaption) :
if (varcap == "") :
varcap = var.lstrip("+")
pe.axis_captions[var.lstrip("+")]=varcap
print "Found 2D histogram:",pe.vars_to_draw
print ("Found 2D histogram:",pe.vars_to_draw)
parsedPlots.append(pe)
elif line[0] == "prof2d" :
pe.vars_to_draw.extend(line[1:4])
......@@ -228,7 +230,7 @@ def parsePlots(filename,varCaption) :
if (varcap == "") :
varcap = var.lstrip("+")
pe.axis_captions[var.lstrip("+")]=varcap
print "Found 2D profile:",pe.vars_to_draw[2],"vs",pe.vars_to_draw[0:2]
print ("Found 2D profile:",pe.vars_to_draw[2],"vs",pe.vars_to_draw[0:2])
parsedPlots.append(pe)
elif line[0] == "restrict" :
re = RestrictEntry()
......@@ -251,15 +253,15 @@ def parsePlots(filename,varCaption) :
rech.rangeList += re.rangeList
re.rangeList = []
if (len(re.rangeList) > 0) : #no restriction for this variable yet. add it.
print "A restriction found for variable",str(re)
print ("A restriction found for variable",str(re))
rstrict.append(re)
elif line[0] == "axisname" :
if (len(parsedPlots) == 0) : #no plots yet. drop the name
print "WARNING: axisname shouldn't be before plots"
print ("WARNING: axisname shouldn't be before plots")
continue
parsedPlots[-1].axis_captions[line[1].lstrip("+")] = " ".join(line[2:]).replace("%","#")
else :
print "WARNING: unknown key:", line[0]
print ("WARNING: unknown key:", line[0])
continue
for pe in parsedPlots : #apply global restrictions on every plot
for re in parsedRestricts :
......@@ -313,8 +315,8 @@ def fillPlots(plots,plotopts,rootopts,eventVal) :
if (eventval == "False") :
try: #then try the event itself
eventval = event.__getattr__(rest.var)
except: #nothing found
print "ERROR: Non-existent variable in plot restrict:", rest.var
except AttributeError: #nothing found
print ("ERROR: Non-existent variable in plot restrict:", rest.var)
import sys
sys.exit(1)
if not rest.checkVar(eventval) : #variable is not in the range list
......@@ -326,8 +328,8 @@ def fillPlots(plots,plotopts,rootopts,eventVal) :
if (eventval == "False") :
try: #then try the event itself
eventval = event.__getattr__(rest.var)
except: #nothing found
print "ERROR: Non-existent variable in rootfile restrict:", rest.var
except Exception: #nothing found
print ("ERROR: Non-existent variable in rootfile restrict:", rest.var)
import sys
sys.exit(1)
if not rest.checkVar(eventval) : #variable is not in the range list
......@@ -349,8 +351,8 @@ def fillPlots(plots,plotopts,rootopts,eventVal) :
if (eventval == "False") :
try: #then try the event itself
eventval = event.__getattr__(locvar)
except: #nothing found
print "ERROR: Non-existent variable:", locvar
except AttributeError: #nothing found
print ("ERROR: Non-existent variable:", locvar)
import sys
sys.exit(1)
if (eventval < 0) :
......@@ -455,11 +457,11 @@ def drawPlots(plots,plotopts,rootopts,output,optzero,optmean,opth,optw) :
#drawing hists
for plotopt in plotopts :
print "Drawing",plotopt.display_name
print ("Drawing",plotopt.display_name)
num += 1
if (num > maxperlist and output != "DISPLAY") : #end of a current PS page
ps.NewPage()
print "new page"
print ("new page")
num = 1
canv.cd(num)
gPad.SetLogy(plotopt.logy)
......@@ -467,7 +469,6 @@ def drawPlots(plots,plotopts,rootopts,output,optzero,optmean,opth,optw) :
entries = {}
valuemax = -999999.9
valuemin = 999999.9
entryZ = 0
for rootopt in rootopts : #get the max entries
......@@ -478,13 +479,13 @@ def drawPlots(plots,plotopts,rootopts,output,optzero,optmean,opth,optw) :
for rootopt in rootopts : #get the max entries
plot = plots[plotopt][rootopt]
if (plotopt.profile) :
print rootopt.legendname,"is a profile: no need to scale"
print (rootopt.legendname,"is a profile: no need to scale")
else :
if not (entries[rootopt] == 0) :
print "scaling",rootopt.legendname,"to",entryZ/entries[rootopt]
print ("scaling",rootopt.legendname,"to",entryZ/entries[rootopt])
plot.Scale(entryZ/entries[rootopt])
else :
print rootopt.legendname,"is an empty hist, no scale"
print (rootopt.legendname,"is an empty hist, no scale")
for rootopt in rootopts : #get the highest peak
if (plots[plotopt][rootopt].GetMaximum() > valuemax) :
......@@ -497,7 +498,7 @@ def drawPlots(plots,plotopts,rootopts,output,optzero,optmean,opth,optw) :
if (rootopt.markerstyle > 0) : #not filler
continue
plot = plots[plotopt][rootopt]
print "Drawing filler from",rootopt.legendname
print ("Drawing filler from",rootopt.legendname)
if optzero :
if (plotopt.logy == 1) :
plot.SetMinimum(1.0)
......@@ -521,7 +522,7 @@ def drawPlots(plots,plotopts,rootopts,output,optzero,optmean,opth,optw) :
leg.AddEntry(plot,prname,"L")
if (rootopt.markerstyle == 0) : #filler
continue #fillers are already drawn
print "Drawing plot from",rootopt.legendname
print ("Drawing plot from",rootopt.legendname)
if optzero :
if (plotopt.logy == 1) :
plot.SetMinimum(1.0)
......
#!/usr/bin/env physh
#
# $Id: AODElectronContainerReader.py,v 1.0 2010-08-12 13:00:12 Morse Exp $
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
#
# python script for launching AODReader job
#
......@@ -22,7 +20,7 @@ parser.add_option("-o","--outputFile",dest="output",default='ntuple.root',help="
for arg in args :
if (not isfile (arg)) :
print "ERROR: wrong input: nonexistent file:",arg
printfunc ("ERROR: wrong input: nonexistent file:",arg)
exit(1)
from AthenaCommon.AppMgr import ServiceMgr
......
#!/usr/bin/env python
#
# $Id: LArG4AODNtuplePlotter.py 505706 2012-06-15 11:48:02Z gsedov $
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
#
# python script for drawing LArG4Validation ntuples
#
......@@ -61,7 +59,6 @@ def varname(hname) :
import sys
from os.path import isfile
from optparse import OptionParser
from math import sqrt
usage = "usage: %prog [options] root1 [root2 ...]"
......@@ -82,28 +79,30 @@ parser.set_defaults(split_canvas="1:1",plots="",files="",outputfile="DISPLAY",di
split_canv = options.split_canvas.split(":")
split_canv = map(int,split_canv)
from LArG4Validation.LArG4PlottingScript import *
from LArG4Validation.LArG4PlottingScript import parseRoots, defaultRoots, \
parsePlots, fillPlots, dividePlots, savePlots, drawPlots, PlotEntry, \
createPlots
if (len(split_canv) != 2) :
print "ERROR: wrong split parameter"
printfunc ("ERROR: wrong split parameter")
sys.exit(1)
if (options.divide and len(args) < 2) :
print "ERROR: must be at least two input files for ratio calculation"
printfunc ("ERROR: must be at least two input files for ratio calculation")
sys.exit(1)
if isfile(options.files) :
print "Parsing file with root parameters:",options.files
printfunc ("Parsing file with root parameters:",options.files)
parsedRoots = parseRoots(options.files)
else :
print "No root parameters provided, using default"
printfunc ("No root parameters provided, using default")
parsedRoots = defaultRoots(args)
if isfile(options.plots) :
print "Parsing file with plots parameters:",options.plots
printfunc ("Parsing file with plots parameters:",options.plots)
parsedPlots = parsePlots(options.plots,varname)
else :
print "No plots parameters provided, using default"
printfunc ("No plots parameters provided, using default")
parsedPlots = []
parsedRestricts = []
listvars = ["hadrleak","e237oe277","weta2","f1","e2tsts1","e2tsts1demins","wtots1","fracs1","weta1"]
......@@ -132,38 +131,38 @@ maxperlist = split_canv[0]*split_canv[1]
numplots = len(parsedPlots)
if (options.outputfile == "DISPLAY") and (numplots > maxperlist) :
print "ERROR: too many hists to print to display"
printfunc ("ERROR: too many hists to print to display")
sys.exit(1)
from ROOT import TFile, TTree
from ROOT import TFile
#opening root files
for rootopt in parsedRoots :
if not isfile(rootopt.filename) :
print "ERROR: unexistent file:",rootopt.filename
printfunc ("ERROR: unexistent file:",rootopt.filename)
sys.exit(1)
root = TFile(rootopt.filename,"read")
if root.IsOpen() == 0 :
print "ERROR: can't open the file:",rootopt.filename
printfunc ("ERROR: can't open the file:",rootopt.filename)
sys.exit(1)
rootopt.rootfile = root
rootopt.tree = root.Get("AOD")
print "Creating plots..."
printfunc ("Creating plots...")
plots = createPlots(parsedPlots,parsedRoots)
print "Filling plots..."
printfunc ("Filling plots...")
fillPlots(plots,parsedPlots,parsedRoots,eventext)
if (options.divide) :
print "Calculating ratio"
printfunc ("Calculating ratio")
rootopt1 = parsedRoots.pop(0)
dividePlots(plots,rootopt1)
for rootopt in parsedRoots :
rootopt.legendname += " / " + rootopt1.legendname
print "Done!"
printfunc ("Done!")
if options.outputfile.endswith(".root") :
savePlots(plots,options.outputfile)
......
#!/usr/bin/env physh
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
# print command line for logging
from optparse import OptionParser
parser = OptionParser(usage = "usage: %prog", version="%prog $Id: LArG4ValidationGenerate.py 583537 2014-02-15 21:17:29Z zmarshal $")
......@@ -41,7 +42,7 @@ from AthenaCommon.GlobalFlags import globalflags
if len(options.condition) > 0 :
globalflags.ConditionsTag = options.condition
else :
print "No condition tag specified.\nThere is no use in validating FS with some arbitrary condition tag.\n Please, specify one."
printfunc ("No condition tag specified.\nThere is no use in validating FS with some arbitrary condition tag.\n Please, specify one.")
import sys
sys.exit(1)
......@@ -93,7 +94,7 @@ if (options.parameterize > 0):
simFlags.LArParameterization=options.parameterize
if len(options.fsLibs) > 0 :
print "Setting up ShowerLib Service"
printfunc ("Setting up ShowerLib Service")
from LArG4ShowerLibSvc.LArG4ShowerLibSvcConf import LArG4ShowerLibSvc
if not hasattr( ServiceMgr, 'LArG4ShowerLibSvc' ):
ServiceMgr += LArG4ShowerLibSvc()
......
#!/usr/bin/env python
#
# $Id: LArG4ValidationPlotter.py 505706 2012-06-15 11:48:02Z gsedov $
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
#
# python script for drawing LArG4Validation ntuples
#
......@@ -75,28 +73,30 @@ parser.set_defaults(split_canvas="1:1",plots="",files="",outputfile="DISPLAY",di
split_canv = options.split_canvas.split(":")
split_canv = map(int,split_canv)
from LArG4Validation.LArG4PlottingScript import *
from LArG4Validation.LArG4PlottingScript import parseRoots, defaultRoots, \
parsePlots, fillPlots, dividePlots, savePlots, drawPlots, PlotEntry, \
createPlots
if (len(split_canv) != 2) :
print "ERROR: wrong split parameter"
printfunc ("ERROR: wrong split parameter")
sys.exit(1)
if (options.divide and len(args) < 2) :
print "ERROR: must be at least two input files for ratio calculation"
printfunc ("ERROR: must be at least two input files for ratio calculation")
sys.exit(1)
if isfile(options.files) :
print "Parsing file with root parameters:",options.files
printfunc ("Parsing file with root parameters:",options.files)
parsedRoots = parseRoots(options.files)
else :
print "No root parameters provided, using default"
printfunc ("No root parameters provided, using default")
parsedRoots = defaultRoots(args)
if isfile(options.plots) :
print "Parsing file with plots parameters:",options.plots
printfunc ("Parsing file with plots parameters:",options.plots)
parsedPlots = parsePlots(options.plots,varname)
else :
print "No plots parameters provided, using default"
printfunc ("No plots parameters provided, using default")
parsedPlots = []
parsedRestricts = []
for var in ["erec","cpu"] :
......@@ -129,37 +129,37 @@ maxperlist = split_canv[0]*split_canv[1]
numplots = len(parsedPlots)
if (options.outputfile == "DISPLAY") and (numplots > maxperlist) :
print "ERROR: too many hists to print to display"
printfunc ("ERROR: too many hists to print to display")
sys.exit(1)
from ROOT import TFile, TTree
from ROOT import TFile
#opening root files
for rootopt in parsedRoots :
if not isfile(rootopt.filename) :
print "ERROR: unexistent file:",rootopt.filename
printfunc ("ERROR: unexistent file:",rootopt.filename)
sys.exit(1)
root = TFile(rootopt.filename,"read")
if root.IsOpen() == 0 :
print "ERROR: can't open the file:",rootopt.filename
printfunc ("ERROR: can't open the file:",rootopt.filename)
sys.exit(1)
rootopt.rootfile = root
rootopt.tree = root.Get("COL/1")
print "Creating plots..."
printfunc ("Creating plots...")
plots = createPlots(parsedPlots,parsedRoots)
print "Filling plots..."
printfunc ("Filling plots...")
fillPlots(plots,parsedPlots,parsedRoots,eventext)
if (options.divide) :
print "Calculating ratio"
printfunc ("Calculating ratio")
rootopt1 = parsedRoots.pop(0)
dividePlots(plots,rootopt1)
for rootopt in parsedRoots :
rootopt.legendname += " / " + rootopt1.legendname
print "Done!"
printfunc ("Done!")
if options.outputfile.endswith(".root") :
savePlots(plots,options.outputfile)
......
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
# get a handle to the default top-level algorithm sequence
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment