Skip to content

Commit

Permalink
Merge pull request #31166 from Dr15Jones/python3CondToolsSiPixel
Browse files Browse the repository at this point in the history
Apply necessary changes to work with python3
  • Loading branch information
cmsbuild authored Aug 19, 2020
2 parents 3381cc7 + 7ed9877 commit 8516175
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
21 changes: 11 additions & 10 deletions CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader_cfg.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand Down
23 changes: 12 additions & 11 deletions CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader_cfg.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -225,4 +226,4 @@
process.p = cms.Path(process.uploader)
process.CondDB.connect = sqlitefilename
process.CondDB.DBParameters.messageLevel = 0
process.CondDB.DBParameters.authenticationPath = './'
process.CondDB.DBParameters.authenticationPath = './'

0 comments on commit 8516175

Please sign in to comment.