Commit 09db50b2 authored by scott snyder's avatar scott snyder
Browse files

CaloDetDescr: Python 3 / flake8 fixes

Update to work with python 3.  Also add flake8 checking and fix warnings.
parent ac28b5e0
......@@ -54,3 +54,12 @@ atlas_install_joboptions( share/*.py )
atlas_add_test( CaloConstIteratorAdaptor_test
SOURCES test/CaloConstIteratorAdaptor_test.cxx
LINK_LIBRARIES CaloDetDescrLib )
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 CaloDetDescr.CaloDetDescrConf import CaloDepthTool
......@@ -17,7 +17,7 @@ class CaloDepthToolBase ( CaloDepthTool ) :
CaloDepthTool.__init__( self,name) # call base class constructor
if name=="CaloDepthToolBaseUNSET":
raise RuntimeError,"CaloDepthToolBase should not be called with default name"
raise RuntimeError ("CaloDepthToolBase should not be called with default name")
if depth=="CDTBunset":
mlog.info("depth should be explicitly set. OK only if copy")
......@@ -41,8 +41,8 @@ class CaloDepthToolBase ( CaloDepthTool ) :
# depthchoice should be one of
depthList=["egparam","cscopt","cscopt2","TBparam","entrance","middle","flat"]
if not depthchoice in depthList:
raise RuntimeError, "depth not among autorised value",depthchoice
if depthchoice not in depthList:
raise RuntimeError ("depth not among autorised value",depthchoice)
# assign property value
self.DepthChoice=depthchoice
......@@ -63,7 +63,7 @@ def CaloDepthToolFactory( depth ):
# from CaloDetDescr.CaloDepthToolBase import caloDepthToolshowerdefault
# theTool=caloDepthToolshowerdefault
# note that this is just an illustration redundant with the factory above
__all__ = [ 'caloDepthToolshowerdefault','caloDepthToolegparam','caloDepthToolTBparam','caloDepthToolcscopt','caloDepthToolcscopt2','caloDepthToolmiddle','caloDepthToolentrance','caloDepthToolflat' ] # and the others, etc ...
__all__ = [ 'caloDepthToolshowerdefault','caloDepthToolegparam','caloDepthToolTBparam','caloDepthToolcscopt','caloDepthToolcscopt2','caloDepthToolmiddle','caloDepthToolentrance','caloDepthToolflat' ] # noqa: F822 # and the others, etc ...
# the following facade will masquerade as this module in order to have
# a __getattr__ method at the module level
......@@ -97,7 +97,7 @@ class _ModuleFacade( object ):
elif name == 'caloDepthToolflat':
setattr( self._module, name, CaloDepthToolBase("CaloDepthToolflat",depth="flat") )
else:
raise RuntimeError,("unknown name %s " % name)
raise RuntimeError ("unknown name %s " % name)
# now try again, will succeed if proper tool has been created in block above
return getattr( self._module, name )
......
print " WARNING obsolete jobOption. Please use Calorimeter/CaloDetDescr/python/CaloDepthTool configurables instead. "
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
printfunc (" WARNING obsolete jobOption. Please use Calorimeter/CaloDetDescr/python/CaloDepthTool configurables instead. ")
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
#
# A short example of how to retrieve the calorimeter detector description
# from python. Run this with `athena.py -i'.
......
# $Id$
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
#
# @file CaloDetDescr/share/CaloSuperCellIDTool_test.py
# @author scott snyder <snyder@bnl.gov>
......@@ -173,9 +173,8 @@ class CaloSuperCellIDToolTest (PyAthena.Alg):
def init (self):
if self.tool != None:
if self.tool is not None:
return
sg = PyAthena.py_svc('StoreGateSvc')
ds = PyAthena.py_svc('DetectorStore')
self.calocell_helper = ds['CaloCell_ID']
self.calosc_helper = ds['CaloCell_SuperCell_ID']
......@@ -220,8 +219,8 @@ class CaloSuperCellIDToolTest (PyAthena.Alg):
cell_id = calocell_helper.cell_id (subcalo, *cell_tuple)
sc_id = tool.offlineToSuperCellID (cell_id)
if self.unpack (sc_id, calosc_helper) != sc_tuple:
print 'ERROR cell->sc', subcalo, cell_tuple, sc_tuple, \
self.unpack (sc_id, calosc_helper)
printfunc ('ERROR cell->sc', subcalo, cell_tuple, sc_tuple,
self.unpack (sc_id, calosc_helper))
assert False
return
......@@ -236,8 +235,8 @@ class CaloSuperCellIDToolTest (PyAthena.Alg):
sc_id = calosc_helper.cell_id (subcalo, *sc_tuple)
idlist = tool.superCellToOfflineID (sc_id)
if self.unpack_list (idlist, calocell_helper) != cell_list:
print 'ERROR sc->cell', subcalo, sc_tuple, cell_list, \
self.unpack_list (idlist, calocell_helper)
printfunc ('ERROR sc->cell', subcalo, sc_tuple, cell_list,
self.unpack_list (idlist, calocell_helper))
assert False
return
......@@ -263,23 +262,25 @@ class CaloSuperCellIDToolTest (PyAthena.Alg):
for cell_id in toiter (calocell.cell_range (subcalo)):
sc_id = t.offlineToSuperCellID (cell_id)
if not sc_id.is_valid():
if calocell.is_tile_gap (cell_id): continue
if calocell.is_tile_gap (cell_id):
continue
if (calocell.is_em_barrel (cell_id) and
calocell.calo_sample (cell_id) == 0 and
calocell.eta (cell_id) == 60):
continue
print 'ERROR unmapped cell subcalo', \
calocell.sub_calo (cell_id), \
'sample', calocell.calo_sample (cell_id),\
'posneg', calocell.pos_neg (cell_id),\
'region', calocell.region (cell_id),\
'eta', calocell.eta (cell_id),\
'phi', calocell.phi (cell_id)
printfunc ('ERROR unmapped cell subcalo',
calocell.sub_calo (cell_id),
'sample', calocell.calo_sample (cell_id),
'posneg', calocell.pos_neg (cell_id),
'region', calocell.region (cell_id),
'eta', calocell.eta (cell_id),
'phi', calocell.phi (cell_id))
assert False
hvec[calosc.calo_cell_hash(sc_id).value() - hmin] = 1
idlist = t.superCellToOfflineID (sc_id)
for id2 in idlist:
if cell_id == id2: break
if cell_id == id2:
break
else:
raise Exception ("Didn't find cell")
......@@ -319,7 +320,8 @@ class CaloSuperCellIDToolTest (PyAthena.Alg):
if hvec[i] == 0:
h = PyAthena.IdentifierHash (i)
id = calocell.cell_id (subcalo, h)
if calocell.is_tile_gap(id): continue
if calocell.is_tile_gap(id):
continue
if (calocell.is_em_barrel (id) and
calocell.calo_sample (id) == 0 and
calocell.eta (id) == 60):
......
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