From 7ed98770daa83c765faf715e8b4576b3c783330b Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Tue, 18 Aug 2020 12:53:23 -0500 Subject: [PATCH] Apply necessary changes to work with python3 --- .../SiPixelGenErrorDBObjectUploader_cfg.py | 21 +++++++++-------- .../SiPixelTemplateDBObjectUploader_cfg.py | 23 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader_cfg.py b/CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader_cfg.py index 1d6811e8db71a..5391bd00ef1c1 100644 --- a/CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader_cfg.py +++ b/CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader_cfg.py @@ -1,6 +1,7 @@ import FWCore.ParameterSet.Config as cms import FWCore.ParameterSet.VarParsing as opts import csv +from io import open options = opts.VarParsing ('standard') @@ -62,37 +63,37 @@ options.parseArguments() MagFieldValue = 10.*options.MagField #code needs it in deciTesla -print '\nMagField = %f deciTesla \n'%(MagFieldValue) +print('\nMagField = %f deciTesla \n'%(MagFieldValue)) version = options.Version -print'\nVersion = %s \n'%(version) +print('\nVersion = %s \n'%(version)) magfieldstrsplit = str(options.MagField).split('.') MagFieldString = magfieldstrsplit[0] if len(magfieldstrsplit)>1 : MagFieldString+=magfieldstrsplit[1] #open the map file -mapfile = open(options.Map,'rUb') +mapfile = open(options.Map,'rU', newline='') #read the csv file into a reader mapfilereader = csv.reader(mapfile,delimiter=options.Delimiter,quotechar=options.Quotechar) #separate into the different sections barrel_rule_lines = []; endcap_rule_lines = [] barrel_exception_lines = []; endcap_exception_lines = [] sections = [barrel_rule_lines, endcap_rule_lines, barrel_exception_lines, endcap_exception_lines] -i=0; line = mapfilereader.next() +i=0; line = next(mapfilereader) for i in range(len(sections)) : while line[0].find('TEMPLATE ID')==-1 : #skip to just before the section of info - line=mapfilereader.next() + line=next(mapfilereader) try : - line=mapfilereader.next() + line=next(mapfilereader) except StopIteration : - print 'Done reading input file' + print('Done reading input file') break while line[1]!='' : #add the lines that are the barrel rules sections[i].append(line) try : - line=mapfilereader.next() + line=next(mapfilereader) except StopIteration : - print 'Done reading input file' + print('Done reading input file') break #print 'barrel rules = %s\nendcap rules = %s\nbarrel exceptions = %s\nendcap exceptions = %s'%(barrel_rule_lines,endcap_rule_lines,barrel_exception_lines,endcap_exception_lines) #DEBUG #Make the lists of location strings and template IDs @@ -187,7 +188,7 @@ #output SQLite filename sqlitefilename = 'sqlite_file:'+generror_base+'.db' -print '\nUploading %s with record SiPixelGenErrorDBObjectRcd in file %s\n' % (generror_base,sqlitefilename) +print( '\nUploading %s with record SiPixelGenErrorDBObjectRcd in file %s\n' % (generror_base,sqlitefilename)) process.source = cms.Source("EmptyIOVSource", timetype = cms.string('runnumber'), diff --git a/CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader_cfg.py b/CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader_cfg.py index df8d8b3f3f67a..c790e271a766f 100644 --- a/CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader_cfg.py +++ b/CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader_cfg.py @@ -1,6 +1,7 @@ import FWCore.ParameterSet.Config as cms import FWCore.ParameterSet.VarParsing as opts import csv +from io import open options = opts.VarParsing ('standard') @@ -62,37 +63,37 @@ options.parseArguments() MagFieldValue = 10.*options.MagField #code needs it in deciTesla -print '\nMagField = %f deciTesla \n'%(MagFieldValue) +print('\nMagField = %f deciTesla \n'%(MagFieldValue)) version = options.Version -print'\nVersion = %s \n'%(version) +print('\nVersion = %s \n'%(version)) magfieldstrsplit = str(options.MagField).split('.') MagFieldString = magfieldstrsplit[0] if len(magfieldstrsplit)>1 : MagFieldString+=magfieldstrsplit[1] #open the map file -mapfile = open(options.Map,'rUb') +mapfile = open(options.Map,'rU', newline='') #read the csv file into a reader mapfilereader = csv.reader(mapfile,delimiter=options.Delimiter,quotechar=options.Quotechar) #separate into the different sections barrel_rule_lines = []; endcap_rule_lines = [] barrel_exception_lines = []; endcap_exception_lines = [] sections = [barrel_rule_lines, endcap_rule_lines, barrel_exception_lines, endcap_exception_lines] -i=0; line = mapfilereader.next() +i=0; line = next(mapfilereader) for i in range(len(sections)) : while line[0].find('TEMPLATE ID')==-1 : #skip to just before the section of info - line=mapfilereader.next() + line=next(mapfilereader) try : - line=mapfilereader.next() + line=next(mapfilereader) except StopIteration : - print 'Done reading input file' + print('Done reading input file') break while line[1]!='' : #add the lines that are the barrel rules sections[i].append(line) try : - line=mapfilereader.next() + line=next(mapfilereader) except StopIteration : - print 'Done reading input file' + print('Done reading input file') break #print 'barrel rules = %s\nendcap rules = %s\nbarrel exceptions = %s\nendcap exceptions = %s'%(barrel_rule_lines,endcap_rule_lines,barrel_exception_lines,endcap_exception_lines) #DEBUG #Make the lists of location strings and template IDs @@ -187,7 +188,7 @@ #output SQLite filename sqlitefilename = 'sqlite_file:'+template_base+'.db' -print '\nUploading %s with record SiPixelTemplateDBObjectRcd in file %s\n' % (template_base,sqlitefilename) +print('\nUploading %s with record SiPixelTemplateDBObjectRcd in file %s\n' % (template_base,sqlitefilename)) process.source = cms.Source("EmptyIOVSource", timetype = cms.string('runnumber'), @@ -225,4 +226,4 @@ process.p = cms.Path(process.uploader) process.CondDB.connect = sqlitefilename process.CondDB.DBParameters.messageLevel = 0 -process.CondDB.DBParameters.authenticationPath = './' \ No newline at end of file +process.CondDB.DBParameters.authenticationPath = './'