From 306ad3dcaccd67aca712bf7b581d3fbc03aad8a6 Mon Sep 17 00:00:00 2001 From: Kevin Pedro Date: Fri, 13 Aug 2021 12:28:37 -0500 Subject: [PATCH 1/2] more Python3 fixes for geometry script --- Configuration/Geometry/python/generateGeometry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Configuration/Geometry/python/generateGeometry.py b/Configuration/Geometry/python/generateGeometry.py index af5ef6c4d33bf..302e080ad8cd6 100644 --- a/Configuration/Geometry/python/generateGeometry.py +++ b/Configuration/Geometry/python/generateGeometry.py @@ -29,10 +29,10 @@ def __init__(self, scriptName, detectorVersionDefault, detectorPrefix, detectorY def generateGeom(self, detectorTuple, args): detectorVersion = self.detectorPrefix+str(args.detectorVersionManual) # reverse dict search if overall D# specified - if args.v_detector>0: + if args.v_detector!=self.detectorVersionType(0): detectorVersion = self.detectorPrefix+str(args.v_detector) if detectorVersion in self.detectorVersionDict.values(): - detectorTuple = self.detectorVersionDict.keys()[self.detectorVersionDict.values().index(detectorVersion)] + detectorTuple = list(self.detectorVersionDict.keys())[list(self.detectorVersionDict.values()).index(detectorVersion)] else: print("Unknown detector "+detectorVersion) sys.exit(1) From 57911e2d57e96ba52f50106aac4fc9a6b1bbbf44 Mon Sep 17 00:00:00 2001 From: Kevin Pedro Date: Sat, 14 Aug 2021 23:04:37 -0500 Subject: [PATCH 2/2] make type fully consistent, avoid magic number --- Configuration/Geometry/python/generateGeometry.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Configuration/Geometry/python/generateGeometry.py b/Configuration/Geometry/python/generateGeometry.py index 302e080ad8cd6..a64a012778eca 100644 --- a/Configuration/Geometry/python/generateGeometry.py +++ b/Configuration/Geometry/python/generateGeometry.py @@ -25,11 +25,12 @@ def __init__(self, scriptName, detectorVersionDefault, detectorPrefix, detectorY self.deprecatedDets = deprecatedDets self.deprecatedSubdets = deprecatedSubdets self.detectorVersionType = detectorVersionType + self.detectorVersionNull = self.detectorVersionType(0) def generateGeom(self, detectorTuple, args): detectorVersion = self.detectorPrefix+str(args.detectorVersionManual) # reverse dict search if overall D# specified - if args.v_detector!=self.detectorVersionType(0): + if args.v_detector!=self.detectorVersionNull: detectorVersion = self.detectorPrefix+str(args.v_detector) if detectorVersion in self.detectorVersionDict.values(): detectorTuple = list(self.detectorVersionDict.keys())[list(self.detectorVersionDict.values()).index(detectorVersion)] @@ -249,7 +250,7 @@ def run(self): for aDict in self.allDicts: parser.add_argument("-"+aDict["abbrev"], "--"+aDict["name"], dest="v_"+aDict["name"], default=aDict["default"], type=int, help="version for "+aDict["name"]) parser.add_argument("-V", "--version", dest="detectorVersionManual", default=self.detectorVersionDefault, type=int, help="manual detector version number") - parser.add_argument("-D", "--detector", dest="v_detector", default=0, type=self.detectorVersionType, help="version for whole detector, ignored if 0, overrides subdet versions otherwise") + parser.add_argument("-D", "--detector", dest="v_detector", default=self.detectorVersionNull, type=self.detectorVersionType, help="version for whole detector, ignored if 0, overrides subdet versions otherwise") parser.add_argument("-l", "--list", dest="doList", default=False, action="store_true", help="list known detector versions and exit") parser.add_argument("-t", "--test", dest="doTest", default=False, action="store_true", help="enable unit test mode") args = parser.parse_args()