Skip to content

Commit

Permalink
clean six.iter usage
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlange6 committed Jul 17, 2021
1 parent 3bb685f commit fedd10b
Show file tree
Hide file tree
Showing 152 changed files with 420 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def insertValToPSet(name,val,thePSet):
setattr(thePSet,name,val)

def insertPSetToPSet(inPSet, outPSet):
for key,val in getPSetDict(six.iteritems(inPSet)):
for key,val in getPSetDict(inPSet.items()):
insertValToPSet(key,val,outPSet)

def insertPSetToVPSet(inPSet, outVPSet):
Expand Down Expand Up @@ -112,7 +112,7 @@ def parseOptions(self):

def interpretOptions(self):
gttogetpsets=[]
for key,val in six.iteritems(self.optdict):
for key,val in self.optdict.items():
# Get GT name
if key=="gt":
autofind=val.find("auto")
Expand Down
4 changes: 2 additions & 2 deletions Alignment/MillePedeAlignmentAlgorithm/python/mpslib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create_single_iov_db(inputs, run_number, output_db):
"""

# find the IOV containing `run_number`
for record,tag in six.iteritems(inputs):
for record,tag in inputs.items():
run_is_covered = False
for iov in reversed(tag["iovs"]):
if iov <= run_number:
Expand All @@ -40,7 +40,7 @@ def create_single_iov_db(inputs, run_number, output_db):
result = {}
remove_existing_object(output_db)

for record,tag in six.iteritems(inputs):
for record,tag in inputs.items():
result[record] = {"connect": "sqlite_file:"+output_db,
"tag": "_".join([tag["tag"], tag["since"]])}

Expand Down
20 changes: 10 additions & 10 deletions Alignment/MillePedeAlignmentAlgorithm/scripts/mps_alisetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _create_mille_jobs(self):
json_regex = re.compile('setupJson\s*\=\s*.*$', re.M)

first_dataset = True
for name, dataset in six.iteritems(self._datasets):
for name, dataset in self._datasets.items():
print("="*75)
# Build config from template/Fill in variables
try:
Expand Down Expand Up @@ -453,7 +453,7 @@ def _create_additional_pede_jobs(self):
print("Properly set up the alignment before using the -w option.")
sys.exit(1)

firstDataset = next(six.itervalues(self._datasets))
firstDataset = next(self._datasets.values())
config_template = firstDataset["configTemplate"]
collection = firstDataset["collection"]

Expand Down Expand Up @@ -517,7 +517,7 @@ def _create_input_db(self):
run_number, input_db_name)

self._override_gt = ""
for record,tag in six.iteritems(tags):
for record,tag in tags.items():
if self._override_gt == "":
self._override_gt \
+= ("\nimport "
Expand Down Expand Up @@ -572,13 +572,13 @@ def _check_iov_definition(self):
print(self._first_run, "!=", iovs[0])
sys.exit(1)

for inp in six.itervalues(inputs):
for inp in inputs.values():
inp["iovs"] = mps_tools.get_iovs(inp["connect"], inp["tag"])

# check consistency of input with output
problematic_gt_inputs = {}
input_indices = {key: len(value["iovs"]) -1
for key,value in six.iteritems(inputs)}
for key,value in inputs.items()}
for iov in reversed(iovs):
for inp in inputs:
if inputs[inp].pop("problematic", False):
Expand Down Expand Up @@ -618,7 +618,7 @@ def _check_iov_definition(self):

# check consistency of 'TrackerAlignmentRcd' with other inputs
input_indices = {key: len(value["iovs"]) -1
for key,value in six.iteritems(inputs)
for key,value in inputs.items()
if (key != "TrackerAlignmentRcd")
and (inp not in problematic_gt_inputs)}
for iov in reversed(inputs["TrackerAlignmentRcd"]["iovs"]):
Expand Down Expand Up @@ -680,7 +680,7 @@ def _fetch_defaults(self):
if var == "testMode": continue
print("No '" + var + "' given in [general] section.")

for dataset in six.itervalues(self._external_datasets):
for dataset in self._external_datasets.values():
dataset["general"] = {}
for var in ("globaltag", "configTemplate", "json"):
try:
Expand Down Expand Up @@ -715,7 +715,7 @@ def _fetch_datasets(self):
"weight": None}
all_configs.update(self._external_datasets)

for config in six.itervalues(all_configs):
for config in all_configs.values():
global_weight = "1" if config["weight"] is None else config["weight"]
if global_weight+self._config.config_path in self._common_weights:
global_weight = self._common_weights[global_weight+
Expand Down Expand Up @@ -865,8 +865,8 @@ def _fetch_datasets(self):
print("inputfilelist as the number of jobs.")

# check if local weights override global weights and resolve name clashes
for weight_name, weight_values in six.iteritems(common_weights):
for key, weight in six.iteritems(weight_dict):
for weight_name, weight_values in common_weights.items():
for key, weight in weight_dict.items():
if any([weight_name in w for w in weight]):
self._common_weights[weight_name+config["config"].config_path] = weight_values
self._weight_dict[key] = [mps_tools.replace_factors(w,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_num_evts_per_merged_dataset(merged_datasets,num_evts_per_dataset):
`merge_datasets' for an explanation of <merged_dataset>.
"""
num_evts_per_merged_dataset = {}
for merged_dataset,datasets in six.iteritems(merged_datasets):
for merged_dataset,datasets in merged_datasets.items():
num_evts = 0
for dataset in datasets:
num_evts = num_evts + num_evts_per_dataset[dataset]
Expand Down Expand Up @@ -106,7 +106,7 @@ def print_merging_scheme(merged_datasets):
of what is meant by merged dataset.
"""
print("Defining the following merged datasets:")
for merged_dataset,datasets in six.iteritems(merged_datasets):
for merged_dataset,datasets in merged_datasets.items():
print("\n `"+merged_dataset+"' from:")
for dataset in datasets:
print(" `"+dataset+"'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main(argv = None):
["TrackerAlignmentRcd",
"TrackerSurfaceDeformationRcd",
"TrackerAlignmentErrorExtendedRcd"])
for inp in six.itervalues(inputs):
for inp in inputs.values():
inp["iovs"] = mps_tools.get_iovs(inp["connect"], inp["tag"])
mps_tools.create_single_iov_db(inputs, args.run_number, args.output_db)

Expand Down
4 changes: 2 additions & 2 deletions Alignment/MillePedeAlignmentAlgorithm/scripts/mps_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def fill_time_info(mps_index, status, cpu_time):
job_status[job_id] = {"status": htcondor_jobstatus[status],
"cpu": float(cpu_time)}

for job_id, job_info in six.iteritems(job_status):
for job_id, job_info in job_status.items():
mps_index = submitted_jobs.get(job_id, -1)
# check for disabled Jobs
disabled = "DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index] else ""
Expand Down Expand Up @@ -118,7 +118,7 @@ def fill_time_info(mps_index, status, cpu_time):

################################################################################
# check for orphaned jobs
for job_id, mps_index in six.iteritems(submitted_jobs):
for job_id, mps_index in submitted_jobs.items():
for status in ("SETUP", "DONE", "FETCH", "TIMEL", "SUBTD"):
if status in lib.JOBSTATUS[mps_index]:
print("Funny entry index", mps_index, " job", lib.JOBID[mps_index], end=' ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def __getConditions( self, theConfig, theSection ):
rcdnames = collections.Counter(condition["rcdName"] for condition in conditions)
if rcdnames and max(rcdnames.values()) >= 2:
raise AllInOneError("Some conditions are specified multiple times (possibly through mp or hp options)!\n"
+ ", ".join(rcdname for rcdname, count in six.iteritems(rcdnames) if count >= 2))
+ ", ".join(rcdname for rcdname, count in rcdnames.items() if count >= 2))

for condition in conditions:
self.__testDbExist(condition["connectString"], condition["tagName"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def replaceByMap(target, the_map):
result = result.replace(".oO["+key+"]Oo.",the_map[key])
except TypeError: #try a dict
try:
for keykey, value in six.iteritems(the_map[key]):
for keykey, value in the_map[key].items():
result = result.replace(".oO[" + key + "['" + keykey + "']]Oo.", value)
result = result.replace(".oO[" + key + '["' + keykey + '"]]Oo.', value)
except AttributeError: #try a list
Expand Down Expand Up @@ -157,12 +157,12 @@ def cache(function):
cache = {}
def newfunction(*args, **kwargs):
try:
return cache[args, tuple(sorted(six.iteritems(kwargs)))]
return cache[args, tuple(sorted(kwargs.items()))]
except TypeError:
print(args, tuple(sorted(six.iteritems(kwargs))))
print(args, tuple(sorted(kwargs.items())))
raise
except KeyError:
cache[args, tuple(sorted(six.iteritems(kwargs)))] = function(*args, **kwargs)
cache[args, tuple(sorted(kwargs.items()))] = function(*args, **kwargs)
return newfunction(*args, **kwargs)
newfunction.__name__ = function.__name__
return newfunction
Expand Down
6 changes: 3 additions & 3 deletions Alignment/OfflineValidation/scripts/validateAlignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def runCondorJobs(outdir):

with open("{}/validation.dagman".format(outdir), "w") as dagman:
parents = {}
for (valType, valName, iov), alignments in six.iteritems(ValidationJob.condorConf):
for (valType, valName, iov), alignments in ValidationJob.condorConf.items():

parents[(valType, valName, iov)] = []
for jobInfo in alignments:
Expand All @@ -456,7 +456,7 @@ def runCondorJobs(outdir):
else:
raise AllInOneError("Merge script '[%s]' not found!"%path)

for (valType, valName, iov), alignments in six.iteritems(ValidationJob.condorConf):
for (valType, valName, iov), alignments in ValidationJob.condorConf.items():
if len(parents[(valType, valName, iov)]) != 0:
dagman.write('PARENT {} '.format(" ".join([parent for parent in parents[(valType, valName, iov)]])) + 'CHILD Merge_{}_{}_{}'.format(valType, valName, iov) + "\n")

Expand Down Expand Up @@ -536,7 +536,7 @@ def createMergeScript( path, validations, options ):
#pprint.pprint(comparisonLists)
anythingToMerge = []

for (validationtype, validationName, referenceName), validations in six.iteritems(comparisonLists):
for (validationtype, validationName, referenceName), validations in comparisonLists.items():
#pprint.pprint("validations")
#pprint.pprint(validations)
globalDictionaries.plottingOptions = {}
Expand Down
2 changes: 1 addition & 1 deletion CalibTracker/SiStripDCS/test/ManualO2OForRestart.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def insert_to_file(template, target, replace_dict):
with open(template, 'r') as input_file:
config=input_file.read()
with open(target, 'w') as output_file:
for key, value in six.iteritems(replace_dict):
for key, value in replace_dict.items():
config = config.replace(key, value)
output_file.write(config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def getFileInPath(rfile):
#print(detDict)

APVsToKill = []
for det,napv in six.iteritems(detDict):
for det,napv in detDict.items():
APVsToKill.append(
cms.PSet(
DetId = cms.uint32(int(det)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def customiseEarlyDeleteForCandIsoDeposits(process, products):
def _branchName(productType, moduleLabel, instanceLabel=""):
return "%s_%s_%s_%s" % (productType, moduleLabel, instanceLabel, process.name_())

for name, module in six.iteritems(process.producers_()):
for name, module in process.producers_().items():
cppType = module._TypedParameterizable__type
if cppType == "CandIsoDepositProducer":
if module.ExtractorPSet.ComponentName in ["CandViewExtractor", "PFCandWithSuperClusterExtractor"] :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
if process.schedule_() is not None:
process.schedule_().append( process.esout )

for name, module in six.iteritems(process.es_sources_()):
for name, module in process.es_sources_().items():
print("ESModules> provider:%s '%s'" % ( name, module.type_() ))
for name, module in six.iteritems(process.es_producers_()):
for name, module in process.es_producers_().items():
print("ESModules> provider:%s '%s'" % ( name, module.type_() ))
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
if process.schedule_() is not None:
process.schedule_().append( process.esout )

for name, module in six.iteritems(process.es_sources_()):
for name, module in process.es_sources_().items():
print("ESModules> provider:%s '%s'" % ( name, module.type_() ))
for name, module in six.iteritems(process.es_producers_()):
for name, module in process.es_producers_().items():
print("ESModules> provider:%s '%s'" % ( name, module.type_() ))
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
#if process.schedule_() is not None:
# process.schedule_().append( process.esout )

for name, module in six.iteritems(process.es_sources_()):
for name, module in process.es_sources_().items():
print("ESModules> provider:%s '%s'" % ( name, module.type_() ))
for name, module in six.iteritems(process.es_producers_()):
for name, module in process.es_producers_().items():
print("ESModules> provider:%s '%s'" % ( name, module.type_() ))
2 changes: 1 addition & 1 deletion CondTools/BTau/python/checkBTagCalibrationConsistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _check_sys_side(self, op, flav):
assert len(sys_dict) == len(entries)
sys_cent = sys_dict.pop('central', None)
x = discr if op == 3 else pt
for syst, e in six.iteritems(sys_dict):
for syst, e in sys_dict.items():
sys_val = e.tf1_func.Eval(x)
cent_val = sys_cent.tf1_func.Eval(x)
if syst.startswith('up') and not sys_val > cent_val:
Expand Down
6 changes: 3 additions & 3 deletions CondTools/BTau/python/combineBTagCalibrationData.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def main():
print('\n' + '='*80)
print('Checking consistency of individual input files...')
print('='*80)
for fname, csv_data in six.iteritems(all_csv_data):
for fname, csv_data in all_csv_data.items():
print('\nChecking file:', fname)
print('='*80)
check_csv_data(csv_data)

print('\n' + '='*80)
print('Checking consistency of combinations...')
print('='*80)
for one, two in itertools.combinations(six.iteritems(all_csv_data), 2):
for one, two in itertools.combinations(all_csv_data.items(), 2):
print('\nChecking combination:', one[0], two[0])
print('='*80)
check_csv_data(one[1] + two[1])
Expand All @@ -58,7 +58,7 @@ def main():
print('='*80)
with open(sys.argv[-1], 'w') as f:
f.write(header)
for csv_data in six.itervalues(all_csv_data):
for csv_data in all_csv_data.values():
f.write('\n')
f.writelines(csv_data)

Expand Down
2 changes: 1 addition & 1 deletion CondTools/BTau/python/generateFlavCfromFlavB.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def gen_flavb_csv_line(dicts):
central = d.pop('central')
central.params.jetFlavor = 1
yield central.makeCSVLine()
for e in six.itervalues(d):
for e in d.values():
e.params.jetFlavor = 1
e.formula = '2*(%s)-(%s)' % (e.formula, central.formula)
yield e.makeCSVLine()
Expand Down
2 changes: 1 addition & 1 deletion CondTools/SiStrip/python/o2o_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def insert_to_file(template, target, replace_dict):
with open(template, 'r') as input_file:
config=input_file.read()
with open(target, 'w') as output_file:
for key, value in six.iteritems(replace_dict):
for key, value in replace_dict.items():
config = config.replace(key, value)
output_file.write(config)
return config
Expand Down
2 changes: 1 addition & 1 deletion Configuration/AlCa/python/GlobalTag.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def GlobalTag(essource = None, globaltag = None, conditions = None):

# explicit payloads toGet from DB
if custom_conditions:
for ( (record, label), (tag, connection, snapshotTime) ) in sorted(six.iteritems(custom_conditions)):
for ( (record, label), (tag, connection, snapshotTime) ) in sorted(custom_conditions.items()):
payload = cms.PSet()
payload.record = cms.string( record )
if label:
Expand Down
4 changes: 2 additions & 2 deletions Configuration/AlCa/python/autoCondModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def autoCond0T(autoCond):

ConditionsFor0T = ','.join( ['RunInfo_0T_v1_mc', "RunInfoRcd", connectionString, "", "2020-07-01 12:00:00.000"] )
GlobalTags0T = {}
for key,val in six.iteritems(autoCond):
for key,val in autoCond.items():
if "phase" in key: # restrict to phase1 upgrade GTs
GlobalTags0T[key+"_0T"] = (autoCond[key], ConditionsFor0T)

Expand All @@ -25,7 +25,7 @@ def autoCondHLTHI(autoCond):
FullPedestalsForHLTHI = ','.join( ['SiStripFullPedestals_GR10_v1_hlt', "SiStripPedestalsRcd", connectionString, "", "2021-03-11 12:00:00.000"] )
MenuForHLTHI = ','.join( ['L1Menu_CollisionsHeavyIons2015_v5_uGT_xml', "L1TUtmTriggerMenuRcd", connectionString, "", "2021-03-11 12:00:00.000"] )

for key,val in six.iteritems(autoCond):
for key,val in autoCond.items():
if key == 'run2_hlt_relval': # modification of HLT relval GT
GlobalTagsHLTHI['run2_hlt_hi'] = (autoCond[key], FullPedestalsForHLTHI, MenuForHLTHI)

Expand Down
2 changes: 1 addition & 1 deletion Configuration/AlCa/python/autoCondPhase2.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

# method called in autoCond
def autoCondPhase2(autoCond):
for key,val in six.iteritems(phase2GTs):
for key,val in phase2GTs.items():
if len(val)==1 :
autoCond[key] = ( autoCond[val[0]] )
else:
Expand Down
2 changes: 1 addition & 1 deletion Configuration/Applications/python/ConfigBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ def prepare_HLT(self, sequence = None):
optionsForHLT['type'] = 'HIon'
else:
optionsForHLT['type'] = 'GRun'
optionsForHLTConfig = ', '.join('%s=%s' % (key, repr(val)) for (key, val) in six.iteritems(optionsForHLT))
optionsForHLTConfig = ', '.join('%s=%s' % (key, repr(val)) for (key, val) in optionsForHLT.items())
if sequence == 'run,fromSource':
if hasattr(self.process.source,'firstRun'):
self.executeAndRemember('process.loadHltConfiguration("run:%%d"%%(process.source.firstRun.value()),%s)'%(optionsForHLTConfig))
Expand Down
2 changes: 1 addition & 1 deletion Configuration/HLT/python/autoCondHLT.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

def autoCondHLT(autoCond):
import six
for key,val in six.iteritems(hltGTs):
for key,val in hltGTs.items():
if len(val)==1 :
autoCond[key] = ( autoCond[val[0]] )
else:
Expand Down
2 changes: 1 addition & 1 deletion Configuration/PyReleaseValidation/python/relval_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def convert_keys_to_string(dictionary):
if isinstance(dictionary, str):
return str(dictionary)
elif isinstance(dictionary, collections.Mapping):
return dict(map(convert_keys_to_string, six.iteritems(dictionary)))
return dict(map(convert_keys_to_string, dictionary.items()))
elif isinstance(dictionary, collections.Iterable):
return type(dictionary)(map(convert_keys_to_string, dictionary))
else:
Expand Down
Loading

0 comments on commit fedd10b

Please sign in to comment.