Skip to content

Commit

Permalink
Replace has_key with in for dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvaandering committed Oct 21, 2015
1 parent e09f3bf commit 50ca38b
Show file tree
Hide file tree
Showing 111 changed files with 1,052 additions and 1,053 deletions.
4 changes: 2 additions & 2 deletions Alignment/MuonAlignmentAlgorithms/scripts/alignCSCRings.py
Expand Up @@ -77,7 +77,7 @@

ring_id = "%s%s/%s" % (endcap[0], station[1],ring[1])

if MAP_RESULTS_FITSIN.has_key(ring_id):
if ring_id in MAP_RESULTS_FITSIN:
postal_address = idToPostalAddress(ring_id+'/01')

fits = MAP_RESULTS_FITSIN[ring_id]
Expand Down Expand Up @@ -119,7 +119,7 @@

ring_id = "%s%s/%s" % (endcap[0], s_with_corr, r_with_corr)

if xml_corr.has_key(ring_id):
if ring_id in xml_corr:
corr = xml_corr[ring_id]
e = endcap[3]
s = station[1]
Expand Down
6 changes: 3 additions & 3 deletions Alignment/MuonAlignmentAlgorithms/scripts/plotscripts.py
Expand Up @@ -1031,7 +1031,7 @@ def availableCellsCSC(reports):

def addToTestResults(c,res):
if len(res)>0:
if TEST_RESULTS.has_key(c): TEST_RESULTS[c].extend(res)
if c in TEST_RESULTS: TEST_RESULTS[c].extend(res)
else: TEST_RESULTS[c] = res


Expand Down Expand Up @@ -1150,7 +1150,7 @@ def doTestsForMapPlots(cells):
print "strange cell ID: ", c
return None

if MAP_RESULTS_FITSIN.has_key(c):
if c in MAP_RESULTS_FITSIN:
t = MAP_RESULTS_FITSIN[c]
t_a = testZeroWithin5Sigma(t['a'])
t_s = testZeroWithin5Sigma(t['sin'])
Expand All @@ -1159,7 +1159,7 @@ def doTestsForMapPlots(cells):
descr = "map fitsin 5 sigma away from 0; pulls : a=%.2f sin=%.2f, cos=%.2f" % (t_a,t_s,t_c)
res.append(testEntry("MAP_FITSIN",scope,descr,"SEVERE"))

if MAP_RESULTS_SAWTOOTH.has_key(c):
if c in MAP_RESULTS_SAWTOOTH:
t = MAP_RESULTS_SAWTOOTH[c]

t_a = testDeltaWithin5Sigma(t['a'],t['da'])
Expand Down
Expand Up @@ -100,7 +100,7 @@ def crabStatusFromReport(filename):
nJobs = 0
for j in Jobs:
jobStatus = str(j.attrs.get(statusField,None))
if summary.has_key(jobStatus): summary[jobStatus] += 1
if jobStatus in summary: summary[jobStatus] += 1
else: summary[jobStatus] = 1
nJobs += 1

Expand Down
20 changes: 10 additions & 10 deletions CalibMuon/DTCalibration/python/Workflow/crabWrap.py
Expand Up @@ -27,7 +27,7 @@ def computeSummaryCRAB260(up_task):
if job.runningJob['state'] == 'SubRequested' : jobStatus = 'Submitting'
if job.runningJob['state'] == 'Terminated': jobStatus = 'Done'

if summary.has_key(jobStatus): summary[jobStatus] += 1
if jobStatus in summary: summary[jobStatus] += 1
else: summary[jobStatus] = 1
nJobs += 1

Expand Down Expand Up @@ -57,7 +57,7 @@ def computeSummaryCRAB251(up_task):
if job_exit_code == 'None' : job_exit_code = ''
#printline+="%-6s %-18s %-36s %-13s %-16s %-4s" % (id,jobStatus,dest,exe_exit_code,job_exit_code,ended)
#print printline
if summary.has_key(jobStatus): summary[jobStatus] += 1
if jobStatus in summary: summary[jobStatus] += 1
else: summary[jobStatus] = 1
nJobs += 1

Expand Down Expand Up @@ -255,17 +255,17 @@ def initCrabEnvironment():
pythonpathend = pythonpathenv.split(':')[-1].rstrip('/')

indexBegin = sys.path.index(pythonpathbegin)
if os.environ.has_key('CRABPSETPYTHON'): sys.path.insert( indexBegin, os.environ['CRABPSETPYTHON'] )
if os.environ.has_key('CRABDLSAPIPYTHON'): sys.path.insert( indexBegin, os.environ['CRABDLSAPIPYTHON'] )
if os.environ.has_key('CRABDBSAPIPYTHON'): sys.path.insert( indexBegin, os.environ['CRABDBSAPIPYTHON'] )
if 'CRABPSETPYTHON' in os.environ: sys.path.insert( indexBegin, os.environ['CRABPSETPYTHON'] )
if 'CRABDLSAPIPYTHON' in os.environ: sys.path.insert( indexBegin, os.environ['CRABDLSAPIPYTHON'] )
if 'CRABDBSAPIPYTHON' in os.environ: sys.path.insert( indexBegin, os.environ['CRABDBSAPIPYTHON'] )

if os.environ['SCRAM_ARCH'].find('32') != -1 and os.environ.has_key('CRABPYSQLITE'):
if os.environ['SCRAM_ARCH'].find('32') != -1 and 'CRABPYSQLITE' in os.environ:
sys.path.insert( indexBegin, os.environ['CRABPYSQLITE'] )
elif os.environ['SCRAM_ARCH'].find('64') != -1 and os.environ.has_key('CRABPYSQLITE64'):
elif os.environ['SCRAM_ARCH'].find('64') != -1 and 'CRABPYSQLITE64' in os.environ:
sys.path.insert( indexBegin, os.environ['CRABPYSQLITE64'] )

indexEnd = sys.path.index(pythonpathend) + 1
if os.environ.has_key('CRABPYTHON'):
if 'CRABPYTHON' in os.environ:
if indexEnd >= len(sys.path): sys.path.append( os.environ['CRABPYTHON'] )
else: sys.path.insert( indexEnd, os.environ['CRABPYTHON'] )

Expand All @@ -292,9 +292,9 @@ def initCrabEnvironment():

# Remove libraries which over-ride CRAB libs and DBS_CONFIG setting
badPaths = []
if os.environ.has_key('DBSCMD_HOME'): # CMSSW's DBS, remove last bit of path
if 'DBSCMD_HOME' in os.environ: # CMSSW's DBS, remove last bit of path
badPaths.append('/'.join(os.environ['DBSCMD_HOME'].split('/')[:-1]))
if os.environ.has_key('DBS_CLIENT_CONFIG'):
if 'DBS_CLIENT_CONFIG' in os.environ:
del os.environ['DBS_CLIENT_CONFIG']

def pathIsGood(checkPath):
Expand Down
2 changes: 1 addition & 1 deletion CondCore/TagCollection/python/TagTree.py
Expand Up @@ -213,7 +213,7 @@ def renameNodes( self, nodenamemap):
cursor = query.execute()
while ( cursor.next() ):
nodelabel=cursor.currentRow()['nodelabel'].data()
if nodenamemap.has_key(nodelabel):
if nodelabel in nodenamemap:
allnodes[nodelabel]=nodenamemap[nodelabel]
else:
allnodes[nodelabel]=nodelabel
Expand Down
2 changes: 1 addition & 1 deletion CondCore/TagCollection/python/cacheconfigParser.py
Expand Up @@ -17,7 +17,7 @@ def handleFrontierConnect(self,dom):
for attrName in attrs.keys():
attrNode=attrs.get(attrName)
attrValue=attrNode.nodeValue
if self.__parameterDict.has_key(tagname):
if tagname in self.__parameterDict:
self.__parameterDict[tagname].append((attrName,attrValue))
else:
valuelist=[]
Expand Down
4 changes: 2 additions & 2 deletions CondCore/TagCollection/python/multivaluedict.py
Expand Up @@ -51,7 +51,7 @@ def __init__(self,List=[],Dict={}):
else:
self.__setitem__(key,value)
def __setitem__(self,key,value):
if not self.dict.has_key(key):
if key not in self.dict:
self.list.append(key)
if isinstance(value,MyUserList):
self.dict[key] = value
Expand All @@ -76,7 +76,7 @@ def __setslice__(self,start,stop,newdict):
start = max(start,0); stop = max(stop,0)
delindexes = []
for key in newdict.keys():
if self.dict.has_key(key):
if key in self.dict:
index = self.list.index(key)
delindexes.append(index)
if index < start:
Expand Down
10 changes: 5 additions & 5 deletions CondCore/TagCollection/python/seqvaluedict.py
Expand Up @@ -24,7 +24,7 @@ def __init__(self,List=[],Dict={}):
self.list,self.dict = List[:],Dict.copy()

def append(self,key,value):
if self.dict.has_key(key):
if key in self.dict:
self.list.remove(key)
self.list.append(key)
self.dict[key]=value
Expand All @@ -51,7 +51,7 @@ def __getitem__(self,key):
return self.__class__(key,newdict)
return self.dict[key]
def __setitem__(self,key,value):
if not self.dict.has_key(key):
if key not in self.dict:
self.list.append(key)
self.dict[key]=value
def __delitem__(self, key):
Expand All @@ -68,7 +68,7 @@ def __setslice__(self,start,stop,newdict):
start = max(start,0); stop = max(stop,0)
delindexes = []
for key in newdict.keys():
if self.dict.has_key(key):
if key in self.dict:
index = self.list.index(key)
delindexes.append(index)
if index < start:
Expand Down Expand Up @@ -119,7 +119,7 @@ def get(self, key, failobj=None):
def index(self,key):return self.list.index(key)
def insert(self,i,x):self.__setslice__(i,i,x)
def items(self):return map(None,self.list,self.values())
def has_key(self,key):return self.dict.has_key(key)
def has_key(self,key):return key in self.dict
def keys(self):return self.list
def map(self,function):
return self.__class__(map(function,self.items()))
Expand Down Expand Up @@ -152,7 +152,7 @@ def split(self,function,Ignore=None):
for key in self.list:
skey = function(key)
if skey != Ignore:
if not splitdict.has_key(skey):
if skey not in splitdict:
splitdict[skey] = self.__class__()
splitdict[skey][key] = self.dict[key]
return splitdict
Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/AlCa.py
Expand Up @@ -60,7 +60,7 @@ def alcaSkim(self, skims, **args):
options.scenario = "pp"
options.step = "ALCAOUTPUT:"+('+'.join(skims))
options.conditions = args['globaltag'] if 'globaltag' in args else 'None'
if args.has_key('globalTagConnect') and args['globalTagConnect'] != '':
if 'globalTagConnect' in args and args['globalTagConnect'] != '':
options.conditions += ','+args['globalTagConnect']

options.triggerResultsProcess = 'RECO'
Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/HeavyIons.py
Expand Up @@ -187,7 +187,7 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
process.dqmSaver.saveByLumiSection = 1
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
4 changes: 2 additions & 2 deletions Configuration/DataProcessing/python/Impl/Test.py
Expand Up @@ -97,10 +97,10 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.source.fileNames = cms.untracked(cms.vstring())
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
if args.has_key('saveByLumiSection') and \
if 'saveByLumiSection' in args and \
args.get('saveByLumiSection', ''):
process.dqmSaver.saveByLumiSection = int(args['saveByLumiSection'])
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/preprodmc.py
Expand Up @@ -56,7 +56,7 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.source.fileNames = cms.untracked(cms.vstring())
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/prodmc.py
Expand Up @@ -55,7 +55,7 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.source.fileNames = cms.untracked(cms.vstring())
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/relvalgen.py
Expand Up @@ -54,7 +54,7 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.source.fileNames = cms.untracked(cms.vstring())
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/relvalmc.py
Expand Up @@ -53,7 +53,7 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.source.fileNames = cms.untracked(cms.vstring())
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
2 changes: 1 addition & 1 deletion Configuration/DataProcessing/python/Impl/relvalmcfs.py
Expand Up @@ -50,7 +50,7 @@ def dqmHarvesting(self, datasetName, runNumber, globalTag, **args):
process.source.fileNames = cms.untracked(cms.vstring())
process.maxEvents.input = -1
process.dqmSaver.workflow = datasetName
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = \
cms.untracked.string(args['referenceFile'])

Expand Down
4 changes: 2 additions & 2 deletions Configuration/DataProcessing/python/Reco.py
Expand Up @@ -35,7 +35,7 @@ def promptReco(self, globalTag, **args):
"""
step = stepALCAPRODUCER(args['skims'])
PhysicsSkimStep = ''
if (args.has_key("PhysicsSkims")) :
if ("PhysicsSkims" in args) :
PhysicsSkimStep = stepSKIMPRODUCER(args['PhysicsSkims'])
dqmStep= dqmSeq(args,'')
options = Options()
Expand Down Expand Up @@ -206,7 +206,7 @@ def alcaSkim(self, skims, **args):
options.scenario = self.cbSc
options.step = step
options.conditions = args['globaltag'] if 'globaltag' in args else 'None'
if args.has_key('globalTagConnect') and args['globalTagConnect'] != '':
if 'globalTagConnect' in args and args['globalTagConnect'] != '':
options.conditions += ','+args['globalTagConnect']

options.triggerResultsProcess = 'RECO'
Expand Down
6 changes: 3 additions & 3 deletions Configuration/DataProcessing/python/Utils.py
Expand Up @@ -117,11 +117,11 @@ def harvestingMode(process, datasetName, args,rANDl=True):
process.source.processingMode = cms.untracked.string('RunsAndLumis')
process.dqmSaver.workflow = datasetName
process.dqmSaver.saveByLumiSection = 1
if args.has_key('referenceFile') and args.get('referenceFile', ''):
if 'referenceFile' in args and args.get('referenceFile', ''):
process.DQMStore.referenceFileName = cms.untracked.string(args['referenceFile'])

def dictIO(options,args):
if args.has_key('outputs'):
if 'outputs' in args:
options.outputDefinition = args['outputs'].__str__()
else:
writeTiers = args.get('writeTiers', [])
Expand All @@ -135,7 +135,7 @@ def dqmSeq(args,default):
return default

def gtNameAndConnect(globalTag, args):
if args.has_key('globalTagConnect') and args['globalTagConnect'] != '':
if 'globalTagConnect' in args and args['globalTagConnect'] != '':
return globalTag + ','+args['globalTagConnect']
# we override here the default in the release which uses the FrontierProd servlet not suited for Tier0 activity
return globalTag +',frontier://PromptProd/CMS_CONDITIONS'
4 changes: 2 additions & 2 deletions DQM/CSCMonitorModule/data/bookConverter.py
Expand Up @@ -25,7 +25,7 @@ def read_data():
value = key.childNodes[0].nodeValue
found = 0

if not elements.has_key(name):
if name not in elements:
elements[name] = {'type': '', 'count': 0}
elements[name]['count'] = elements[name]['count'] + 1

Expand Down Expand Up @@ -120,7 +120,7 @@ def priorities():
l = len(results[ci])
if l == 1:
continue
if not prior.has_key(l):
if l not in prior:
prior[l] = [ci]
else:
prior[l].append(ci)
Expand Down
2 changes: 1 addition & 1 deletion DQM/CSCMonitorModule/data/combine.py
Expand Up @@ -12,7 +12,7 @@
a=h.strip().split()
key=a[0].strip()
name=a[1].strip()
if histos.has_key(key):
if key in histos:
histos[key]=name
else:
missing[key]=name
Expand Down
8 changes: 4 additions & 4 deletions DQM/Integration/scripts/contentValuesCheck.py
Expand Up @@ -46,7 +46,7 @@ def __init__(self):
if not ss == None and not sub == ss:
continue

if not values.has_key(sub):
if sub not in values:
messages.append("%s: missing subsystem!" % sub)
continue

Expand All @@ -55,7 +55,7 @@ def __init__(self):

for folder in FOLDERS.keys():

if not values[sub].has_key(folder):
if folder not in values[sub]:
messages.append("%s: missing folder EventInfo/%s" % (sub, folder))
continue

Expand All @@ -65,13 +65,13 @@ def __init__(self):

sfolders.append(folder)

if not values[sub][folder].has_key('Summary'):
if 'Summary' not in values[sub][folder]:
messages.append("%s: missing summary value EventInfo/%s" % (sub, FOLDERS[folder][1]))

for key in values[sub][folder].keys():
if key == 'Summary':
continue
if not skeys.has_key(key):
if key not in skeys:
skeys[key] = []
skeys[key].append(folder)

Expand Down
2 changes: 1 addition & 1 deletion DQM/Integration/scripts/contentValuesFiles.py
Expand Up @@ -39,7 +39,7 @@ def getNodeText(nodelist):
if opts['from'] != None:
query['number'] = '>= ' + str(opts['from'])
if opts['to'] != None:
if query.has_key('number'):
if 'number' in query:
query['number'] += ' and <= ' + str(opts['to'])
else:
query['number'] = '<= ' + str(opts['to'])
Expand Down

0 comments on commit 50ca38b

Please sign in to comment.