diff --git a/Alignment/MillePedeAlignmentAlgorithm/scripts/mps_alisetup.py b/Alignment/MillePedeAlignmentAlgorithm/scripts/mps_alisetup.py index 0eddb1c934e12..0346e35b9886a 100755 --- a/Alignment/MillePedeAlignmentAlgorithm/scripts/mps_alisetup.py +++ b/Alignment/MillePedeAlignmentAlgorithm/scripts/mps_alisetup.py @@ -19,6 +19,7 @@ import collections import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass as mpslib from Alignment.MillePedeAlignmentAlgorithm.alignmentsetup.helper import checked_out_MPS +from functools import reduce def get_weight_configs(config): diff --git a/CondCore/Utilities/python/popcon2dropbox.py b/CondCore/Utilities/python/popcon2dropbox.py index 3b921541d723a..4536678b214a1 100644 --- a/CondCore/Utilities/python/popcon2dropbox.py +++ b/CondCore/Utilities/python/popcon2dropbox.py @@ -29,13 +29,13 @@ def __init__( self, fileName ): def authPath( self ): apath = '' - if self.md.has_key('authenticationPath'): + if 'authenticationPath' in self.md: apath = self.md.get('authenticationPath') return apath def authSys( self ): asys = 1 - if self.md.has_key('authenticationSys'): + if 'authenticationSys' in self.md: asys = self.md.get('authenticationSystem') return asys diff --git a/CondCore/Utilities/scripts/uploadConditions.py b/CondCore/Utilities/scripts/uploadConditions.py index 81fb8cbbdb33e..fe6904c1c9695 100755 --- a/CondCore/Utilities/scripts/uploadConditions.py +++ b/CondCore/Utilities/scripts/uploadConditions.py @@ -852,7 +852,7 @@ def re_upload( options ): def upload(options, arguments): results = uploadAllFiles(options, arguments) - if not results.has_key('status'): + if 'status' not in results: print 'Unexpected error.' return -1 ret = results['status'] diff --git a/DQM/Integration/python/config/FrontierCondition_GT_autoExpress_cfi.py b/DQM/Integration/python/config/FrontierCondition_GT_autoExpress_cfi.py index e71c360fc3bac..a44f32a686afc 100644 --- a/DQM/Integration/python/config/FrontierCondition_GT_autoExpress_cfi.py +++ b/DQM/Integration/python/config/FrontierCondition_GT_autoExpress_cfi.py @@ -40,8 +40,8 @@ def unique(seq, keepstr=True): except TypeError: # hashing didn't work, see if seq is sortable try: from itertools import groupby - s = sorted(enumerate(seq),key=lambda (i,v):(v,i)) - return t(g.next() for k,g in groupby(s, lambda (i,v): v)) + s = sorted(enumerate(seq),key=lambda i_v1:(i_v1[1],i_v1[0])) + return t(next(g) for k,g in groupby(s, lambda i_v: i_v[1])) except: # not sortable, use brute force seen = [] return t(c for c in seq if not (c in seen or seen.append(c))) diff --git a/EventFilter/L1TXRawToDigi/python/util/__init__.py b/EventFilter/L1TXRawToDigi/python/util/__init__.py index 2a0cdc57b1b33..8f7aa2702ba7c 100644 --- a/EventFilter/L1TXRawToDigi/python/util/__init__.py +++ b/EventFilter/L1TXRawToDigi/python/util/__init__.py @@ -1,2 +1,3 @@ -from getRunInfo import getRunsForDate, getRunsNewer, today, daysAgo, day, getFilesForRun, runGetDatasetsAvailable +from __future__ import absolute_import +from .getRunInfo import getRunsForDate, getRunsNewer, today, daysAgo, day, getFilesForRun, runGetDatasetsAvailable diff --git a/EventFilter/L1TXRawToDigi/python/util/rrClient.py b/EventFilter/L1TXRawToDigi/python/util/rrClient.py index dcd446999f194..f6206cfc90051 100644 --- a/EventFilter/L1TXRawToDigi/python/util/rrClient.py +++ b/EventFilter/L1TXRawToDigi/python/util/rrClient.py @@ -1,5 +1,6 @@ +from __future__ import absolute_import import re, json, datetime -from rrapi import RRApi, RRApiError +from .rrapi import RRApi, RRApiError URL = "http://runregistry.web.cern.ch/runregistry/" @@ -31,7 +32,7 @@ def getRunsNewer(run, minLumis): else : print "RunRegistry API 'app' != user, who knows why... :<" - except RRApiError, e: + except RRApiError as e: print e if __name__ == '__main__' : diff --git a/EventFilter/L1TXRawToDigi/python/util/rrapi.py b/EventFilter/L1TXRawToDigi/python/util/rrapi.py index cb355d30a8db2..cc465de2a0bd9 100644 --- a/EventFilter/L1TXRawToDigi/python/util/rrapi.py +++ b/EventFilter/L1TXRawToDigi/python/util/rrapi.py @@ -108,7 +108,7 @@ def get(self, parts, data = None): if re.search("json", resp.info().gettype()): try: return json.loads(rdata) - except TypeError, e: + except TypeError as e: self.dprint(e) return rdata else: diff --git a/L1Trigger/L1THGCal/test/macros/drawTriggerCells.py b/L1Trigger/L1THGCal/test/macros/drawTriggerCells.py index 1d79713c6f4e2..11aa08bfa6251 100644 --- a/L1Trigger/L1THGCal/test/macros/drawTriggerCells.py +++ b/L1Trigger/L1THGCal/test/macros/drawTriggerCells.py @@ -135,7 +135,7 @@ def boxlines(box): triggercell.center.y = treeTriggerCells.y triggercell.center.z = treeTriggerCells.z for cellid in treeTriggerCells.c_id: - if not cellid in cells: raise StandardError("Cannot find cell {0} in trigger cell".format(cellid)) + if not cellid in cells: raise Exception("Cannot find cell {0} in trigger cell".format(cellid)) cell = cells[cellid] triggercell.cells.append(cell) triggercells[triggercell.id] = triggercell diff --git a/L1Trigger/L1THGCal/test/macros/drawTriggerModules.py b/L1Trigger/L1THGCal/test/macros/drawTriggerModules.py index 9766271846574..4c91396ad8e49 100644 --- a/L1Trigger/L1THGCal/test/macros/drawTriggerModules.py +++ b/L1Trigger/L1THGCal/test/macros/drawTriggerModules.py @@ -151,7 +151,7 @@ def boxlines(box): triggercell.center.y = treeTriggerCells.y triggercell.center.z = treeTriggerCells.z for cellid in treeTriggerCells.c_id: - if not cellid in cells: raise StandardError("Cannot find cell {0} in trigger cell".format(cellid)) + if not cellid in cells: raise Exception("Cannot find cell {0} in trigger cell".format(cellid)) cell = cells[cellid] triggercell.cells.append(cell) triggercells[triggercell.id] = triggercell @@ -177,7 +177,7 @@ def boxlines(box): module.center.y = treeModules.y module.center.z = treeModules.z for cellid in treeModules.tc_id: - if not cellid in triggercells: raise StandardError("Cannot find trigger cell {0} in module".format(cellid)) + if not cellid in triggercells: raise Exception("Cannot find trigger cell {0} in module".format(cellid)) cell = triggercells[cellid] module.cells.append(cell) modules[module.id] = module diff --git a/L1Trigger/L1THGCal/test/macros/drawTriggerModulesHex.py b/L1Trigger/L1THGCal/test/macros/drawTriggerModulesHex.py index 1684e01f354f9..08305a13af05a 100644 --- a/L1Trigger/L1THGCal/test/macros/drawTriggerModulesHex.py +++ b/L1Trigger/L1THGCal/test/macros/drawTriggerModulesHex.py @@ -71,7 +71,7 @@ triggercell.center.y = treeTriggerCells.y triggercell.center.z = treeTriggerCells.z for cellid in treeTriggerCells.c_id: - if not cellid in cells: raise StandardError("Cannot find cell {0} in trigger cell".format(cellid)) + if not cellid in cells: raise Exception("Cannot find cell {0} in trigger cell".format(cellid)) cell = cells[cellid] triggercell.cells.append(cell) triggercells[triggercell.id] = triggercell @@ -97,7 +97,7 @@ module.center.y = treeModules.y module.center.z = treeModules.z for cellid in treeModules.tc_id: - if not cellid in triggercells: raise StandardError("Cannot find trigger cell {0} in module".format(cellid)) + if not cellid in triggercells: raise Exception("Cannot find trigger cell {0} in module".format(cellid)) cell = triggercells[cellid] module.cells.append(cell) modules[module.id] = module diff --git a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py index 72edddaa5b835..fc2c1b8b2d78b 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/JetAnalyzer.py @@ -73,7 +73,7 @@ def __init__(self, cfg_ana, cfg_comp, looperName): self.addJECShifts = self.cfg_ana.addJECShifts if hasattr(self.cfg_ana, 'addJECShifts') else 0 if self.recalibrateJets == "MC" : self.recalibrateJets = self.cfg_comp.isMC elif self.recalibrateJets == "Data": self.recalibrateJets = not self.cfg_comp.isMC - elif self.recalibrateJets not in [True,False]: raise RuntimeError, "recalibrateJets must be any of { True, False, 'MC', 'Data' }, while it is %r " % self.recalibrateJets + elif self.recalibrateJets not in [True,False]: raise RuntimeError("recalibrateJets must be any of { True, False, 'MC', 'Data' }, while it is %r " % self.recalibrateJets) calculateSeparateCorrections = getattr(cfg_ana,"calculateSeparateCorrections", False); calculateType1METCorrection = getattr(cfg_ana,"calculateType1METCorrection", False); @@ -82,7 +82,7 @@ def __init__(self, cfg_ana, cfg_comp, looperName): doResidual = getattr(cfg_ana, 'applyL2L3Residual', 'Data') if doResidual == "MC": doResidual = self.cfg_comp.isMC elif doResidual == "Data": doResidual = not self.cfg_comp.isMC - elif doResidual not in [True,False]: raise RuntimeError, "If specified, applyL2L3Residual must be any of { True, False, 'MC', 'Data'(default)}" + elif doResidual not in [True,False]: raise RuntimeError("If specified, applyL2L3Residual must be any of { True, False, 'MC', 'Data'(default)}") GT = getattr(cfg_comp, 'jecGT', mcGT if self.cfg_comp.isMC else dataGT) # Now take care of the optional arguments kwargs = { 'calculateSeparateCorrections':calculateSeparateCorrections, @@ -104,7 +104,7 @@ def __init__(self, cfg_ana, cfg_comp, looperName): elif (self.jetGammaDR == self.jetLepDR): self.jetGammaLepDR = self.jetGammaDR else: - raise RuntimeError, "DR for simultaneous cleaning of jets from leptons and photons is not defined, and dR(gamma, jet)!=dR(lep, jet)" + raise RuntimeError("DR for simultaneous cleaning of jets from leptons and photons is not defined, and dR(gamma, jet)!=dR(lep, jet)") if(self.cfg_ana.doQG): qgdefname="{CMSSW_BASE}/src/PhysicsTools/Heppy/data/pdfQG_AK4chs_13TeV_v2b.root" self.qglcalc = QGLikelihoodCalculator(getattr(self.cfg_ana,"QGpath",qgdefname).format(CMSSW_BASE= os.environ['CMSSW_BASE'])) diff --git a/PhysicsTools/Heppy/python/analyzers/objects/LeptonAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/LeptonAnalyzer.py index 0cd8803c26904..3b6e47d97b312 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/LeptonAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/LeptonAnalyzer.py @@ -24,9 +24,9 @@ class LeptonAnalyzer( Analyzer ): def __init__(self, cfg_ana, cfg_comp, looperName ): super(LeptonAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName) if hasattr(self.cfg_ana, 'doMuScleFitCorrections'): - raise RuntimeError, "doMuScleFitCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'MuScleFit', )" + raise RuntimeError("doMuScleFitCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'MuScleFit', )") if hasattr(self.cfg_ana, 'doRochesterCorrections'): - raise RuntimeError, "doRochesterCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'Rochester', )" + raise RuntimeError("doRochesterCorrections is not supported. Please set instead doMuonScaleCorrections = ( 'Rochester', )") if self.cfg_ana.doMuonScaleCorrections: algo, options = self.cfg_ana.doMuonScaleCorrections if algo == "Kalman": @@ -41,11 +41,11 @@ def __init__(self, cfg_ana, cfg_comp, looperName ): elif algo == "MuScleFit": print "WARNING: the MuScleFit correction in heppy is still from Run 1 (and probably no longer functional)" if options not in [ "prompt", "prompt-sync", "rereco", "rereco-sync" ]: - raise RuntimeError, 'MuScleFit correction name must be one of [ "prompt", "prompt-sync", "rereco", "rereco-sync" ] ' + raise RuntimeError('MuScleFit correction name must be one of [ "prompt", "prompt-sync", "rereco", "rereco-sync" ] ') rereco = ("prompt" not in self.cfg_ana.doMuScleFitCorrections) sync = ("sync" in self.cfg_ana.doMuScleFitCorrections) self.muonScaleCorrector = MuScleFitCorr(cfg_comp.isMC, rereco, sync) - else: raise RuntimeError, "Unknown muon scale correction algorithm" + else: raise RuntimeError("Unknown muon scale correction algorithm") else: self.muonScaleCorrector = None #FIXME: only Embedded works @@ -290,7 +290,7 @@ def makeAllMuons(self, event): elif aeta < 2.200: mu.EffectiveArea03 = 0.0433 else: mu.EffectiveArea03 = 0.0577 mu.EffectiveArea04 = 0 # not computed - else: raise RuntimeError, "Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)" + else: raise RuntimeError("Unsupported value for mu_effectiveAreas: can only use Data2012 (rho: ?) and Phys14_25ns_v1 or Spring15_25ns_v1 (rho: fixedGridRhoFastjetAll)") # Attach the vertex to them, for dxy/dz calculation for mu in allmuons: mu.associatedVertex = event.goodVertices[0] if len(event.goodVertices)>0 else event.vertices[0] @@ -386,7 +386,7 @@ def makeAllElectrons(self, event): else: ele.EffectiveArea03 = 0.2687 # warning: EAs not computed for cone DR=0.4 yet. Do not correct ele.EffectiveArea04 = 0.0 - else: raise RuntimeError, "Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)" + else: raise RuntimeError("Unsupported value for ele_effectiveAreas: can only use Data2012 (rho: ?), Phys14_v1 and Spring15_v1 (rho: fixedGridRhoFastjetAll)") # Electron scale calibrations if self.cfg_ana.doElectronScaleCorrections: @@ -469,7 +469,7 @@ def attachMiniIsolation(self, mu): mu.miniAbsIsoPU = self.IsolationComputer.puAbsIso(mu.physObj, mu.miniIsoR, 0.015 if what == "eleE" else 0.0, 0.0,self.IsolationComputer.selfVetoNone); mu.miniAbsIsoNeutral = max(0.0, mu.miniAbsIsoNeutral - 0.5*mu.miniAbsIsoPU) elif puCorr != 'raw': - raise RuntimeError, "Unsupported miniIsolationCorr name '" + puCorr + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested)." + raise RuntimeError("Unsupported miniIsolationCorr name '" + puCorr + "'! For now only 'rhoArea', 'deltaBeta', 'raw', 'weights' are supported (and 'weights' is not tested).") mu.miniAbsIso = mu.miniAbsIsoCharged + mu.miniAbsIsoNeutral mu.miniRelIso = mu.miniAbsIso/mu.pt() diff --git a/PhysicsTools/Heppy/python/analyzers/objects/METAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/objects/METAnalyzer.py index 2f29c3e3f03cd..7f859e26ea90c 100644 --- a/PhysicsTools/Heppy/python/analyzers/objects/METAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/objects/METAnalyzer.py @@ -233,7 +233,7 @@ def makeMETs(self, event): setattr(event,"met_raw.upara_gamma"+self.cfg_ana.collectionPostFix, self.met_raw.upara_gamma) setattr(event,"met_raw.uperp_gamma"+self.cfg_ana.collectionPostFix, self.met_raw.uperp_gamma) - if hasattr(event,"met"+self.cfg_ana.collectionPostFix): raise RuntimeError, "Event already contains met with the following postfix: "+self.cfg_ana.collectionPostFix + if hasattr(event,"met"+self.cfg_ana.collectionPostFix): raise RuntimeError("Event already contains met with the following postfix: "+self.cfg_ana.collectionPostFix) setattr(event, "met"+self.cfg_ana.collectionPostFix, self.met) if self.cfg_ana.doMetNoPU: setattr(event, "metNoPU"+self.cfg_ana.collectionPostFix, self.metNoPU) setattr(event, "met_sig"+self.cfg_ana.collectionPostFix, self.met_sig) diff --git a/PhysicsTools/Heppy/python/physicsobjects/Electron.py b/PhysicsTools/Heppy/python/physicsobjects/Electron.py index 4ebea13ee045a..82b33ba0c8145 100644 --- a/PhysicsTools/Heppy/python/physicsobjects/Electron.py +++ b/PhysicsTools/Heppy/python/physicsobjects/Electron.py @@ -203,9 +203,9 @@ def mvaRun2( self, name, debug = False ): if name == "NonTrigSpring15MiniAOD" and self.physObj.hasUserFloat("ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values"): self._mvaRun2[name] = self.physObj.userFloat("ElectronMVAEstimatorRun2Spring15NonTrig25nsV1Values") return self._mvaRun2[name] - if name not in ElectronMVAID_ByName: raise RuntimeError, "Unknown electron run2 mva id %s (known ones are: %s)\n" % (name, ElectronMVAID_ByName.keys()) - if self.associatedVertex == None: raise RuntimeError, "You need to set electron.associatedVertex before calling any MVA" - if self.rho == None: raise RuntimeError, "You need to set electron.rho before calling any MVA" + if name not in ElectronMVAID_ByName: raise RuntimeError("Unknown electron run2 mva id %s (known ones are: %s)\n" % (name, ElectronMVAID_ByName.keys())) + if self.associatedVertex == None: raise RuntimeError("You need to set electron.associatedVertex before calling any MVA") + if self.rho == None: raise RuntimeError("You need to set electron.rho before calling any MVA") # -v---- below is correct in Heppy 74X, but probably not functional anyway self._mvaRun2[name] = ElectronMVAID_ByName[name](self.physObj, self.associatedVertex, self.rho, True, debug) # -v---- below would be correct for CMGTools 74X witht the updated Spring15 MVA electron ID @@ -250,7 +250,7 @@ def mvaIDRun2(self, name, wp): if (eta < 0.8) : return self.mvaRun2(name) > 0.73; elif (eta < 1.479): return self.mvaRun2(name) > 0.57; else : return self.mvaRun2(name) > 0.05; - else: raise RuntimeError, "Ele MVA ID Working point not found" + else: raise RuntimeError("Ele MVA ID Working point not found") elif name == "NonTrigPhys14Fix": if wp == "HZZ": if self.pt() <= 10: @@ -261,7 +261,7 @@ def mvaIDRun2(self, name, wp): if eta < 0.8 : return self.mvaRun2(name) > -0.652; elif eta < 1.479: return self.mvaRun2(name) > -0.701; else : return self.mvaRun2(name) > -0.350; - else: raise RuntimeError, "Ele MVA ID Working point not found" + else: raise RuntimeError("Ele MVA ID Working point not found") elif name in ("NonTrigSpring15","NonTrigSpring15MiniAOD"): if wp=="VLoose": if self.pt() <= 10: @@ -311,8 +311,8 @@ def mvaIDRun2(self, name, wp): if eta < 0.8: return self.mvaRun2(name) > -0.083313 elif eta < 1.479: return self.mvaRun2(name) > -0.235222 else: return self.mvaRun2(name) > -0.67099 - else: raise RuntimeError, "Ele MVA ID Working point not found" - else: raise RuntimeError, "Ele MVA ID type not found" + else: raise RuntimeError("Ele MVA ID Working point not found") + else: raise RuntimeError("Ele MVA ID type not found") diff --git a/PhysicsTools/Heppy/python/physicsobjects/Jet.py b/PhysicsTools/Heppy/python/physicsobjects/Jet.py index 7fc46d5fa4675..6d279f378f3dc 100644 --- a/PhysicsTools/Heppy/python/physicsobjects/Jet.py +++ b/PhysicsTools/Heppy/python/physicsobjects/Jet.py @@ -129,7 +129,7 @@ def jetID(self,name=""): if name == "PAG_monoID_Loose": return (eta<3.0 and chf>0.05 and nhf<0.7 and phf<0.8); if name == "PAG_monoID_Tight": return (eta<3.0 and chf>0.2 and nhf<0.7 and phf<0.7); - raise RuntimeError, "jetID '%s' not supported" % name + raise RuntimeError("jetID '%s' not supported" % name) def looseJetId(self): '''PF Jet ID (loose operation point) [method provided for convenience only]''' diff --git a/PhysicsTools/HeppyCore/python/utils/diclist.py b/PhysicsTools/HeppyCore/python/utils/diclist.py index 7a77993a45971..ba2acf5955f67 100644 --- a/PhysicsTools/HeppyCore/python/utils/diclist.py +++ b/PhysicsTools/HeppyCore/python/utils/diclist.py @@ -21,24 +21,24 @@ def add( self, key, value ): self.append(value) def __getitem__(self, index): - '''index can be a dictionary key, or an integer specifying + '''index can be a dictionary key, or an integer specifying the rank of the value to be accessed ''' try: - # if index is an integer (the rank), use the list. + # if index is an integer (the rank), use the list. return super(diclist, self).__getitem__(index) - except TypeError, ValueError: + except (TypeError, ValueError): # else it's the dictionary key. - # use the internal dictionary to get the index, + # use the internal dictionary to get the index, # and return the corresponding value from the list return super(diclist, self).__getitem__( self.dico[index] ) - + def __setitem__(self, index, value): '''These functions are quite risky...''' try: return super(diclist, self).__setitem__(index, value) except TypeError as ValueError: return super(diclist, self).__setitem__( self.dico[index], value ) - - + +