Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DQM] Fix syntax in python scripts #46166

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DPGAnalysis/HcalTools/scripts/cmt/das_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, key=None, cert=None, capath=None, level=0):
urllib2.HTTPSHandler.__init__(self)
self.key = key
self.cert = cert
self.capath = capath
self.capath = capath

def https_open(self, req):
"""Open request method"""
Expand Down Expand Up @@ -307,8 +307,8 @@ def get_data(host, query, idx, limit, debug, threshold=300, ckey=None,
data = fdesc.read()
fdesc.close()
except urllib2.HTTPError as error:
print(error.read())
sys.exit(1)
print(error.read())
sys.exit(1)

pat = re.compile(r'^[a-z0-9]{32}')
if data and isinstance(data, str) and pat.match(data) and len(data) == 32:
Expand Down
2 changes: 1 addition & 1 deletion DPGAnalysis/HcalTools/scripts/rmt/hcal_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def main(rf, rt):
for t in ["pedestal","LED","laser"]:
if re.search(t, r[3], flags=re.IGNORECASE) != None:
d = get_single(TIME, { "p.run": int(r[0])})
print r[0], t, "\"" + d + "\"", r[2]
print(r[0], t, "\"" + d + "\"", r[2])
break


Expand Down
2 changes: 1 addition & 1 deletion DPGAnalysis/HcalTools/scripts/rmt/hcal_runs_valdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main(rf, rt):
d = get_single(TIME, { "p.run": int(r[0])})
if d is not None:
d = "\"" + d + "\""
print r[0], t, d, r[2]
print(r[0], t, d, r[2])
break


Expand Down
2 changes: 1 addition & 1 deletion DQM/SiTrackerPhase2/test/harvestingstep_phase2tk_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T21', '')

# Path and EndPath definitions
process.trackerphase2ValidationHarvesting_step = cms.Path(process.trackerphase2ValidationHarvesting_standalone
process.trackerphase2ValidationHarvesting_step = cms.Path(process.trackerphase2ValidationHarvesting_standalone)
##default path in production
#process.trackerphase2ValidationHarvesting_step = cms.Path(process.trackerphase2ValidationHarvesting)
process.dqmsave_step = cms.Path(process.DQMSaver)
Expand Down
24 changes: 12 additions & 12 deletions DQMOffline/CalibCalo/test/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#print error/help message and exit
def help_message():
print "Usage:\n\
print("Usage:\n\
compare [folder_name] [options] -v versions_to_compare -f files_to_compare\n\
Versions and files must be whitespace separated.\n\
If no folder is specified the pwd will be used.\n\
Expand All @@ -18,7 +18,7 @@ def help_message():
--html produce html output\n\
--canvas with --html option and without --no_exec option produces output directly in png, if not specified output is produced in eps and then converted in png format with an external program (but can be used in batch mode).\n\
Example:\n\
./compare.py myDir -v CMSSW_X_Y_Z CMSSW_J_K_W -f file1.root file2.root --no_exec --outfile out.root"
./compare.py myDir -v CMSSW_X_Y_Z CMSSW_J_K_W -f file1.root file2.root --no_exec --outfile out.root")
sys.exit()

#run command in the command line with specified environment
Expand Down Expand Up @@ -65,9 +65,9 @@ def srcpath(fldr):
try:
cwd=os.getcwd()
os.chdir(name)
except OSError, inst:
except OSError as inst:
if inst.errno==errno.ENOENT:
print "Error: the specified working folder does not exist"
print("Error: the specified working folder does not exist")
help_message()
else: help_message()

Expand Down Expand Up @@ -109,7 +109,7 @@ def srcpath(fldr):
try:
from ROOT import gSystem, TFile, TLegend, TCanvas, gDirectory
except ImportError:
print "Warning: environment variables not set, proceeding anyway running this script with the environment variables of the higher version of CMSSW specified in -v"
print("Warning: environment variables not set, proceeding anyway running this script with the environment variables of the higher version of CMSSW specified in -v")
#storing cmsenv environment variables
os.chdir(max(ver))
env=os.popen("scramv1 runtime -sh","r")
Expand All @@ -129,7 +129,7 @@ def srcpath(fldr):
runcmd2(environment,"./compare.py",tuple(sys.argv[1:-1]))#works only if compare.py is located in the pwd
else:
gSystem.Load("libFWCoreFWLite.so")
FWLiteEnabler::enable()
ROOT.FWLiteEnabler.enable()
outfile=TFile(root_out,"recreate")
histo=[]
canvas=[]
Expand Down Expand Up @@ -165,17 +165,17 @@ def srcpath(fldr):
outfile.cd()
canvas[nf].Write()
if execute:
print "Press enter to end the program"
print("Press enter to end the program")
os.system("read")
if html:
if cnv:
if execute:
for nf,f in enumerate(fil):
try:
os.mkdir(f[:len(f)-5])
except OSError,inst:
except OSError as inst:
if inst.errno==errno.EEXIST:
print "Possibly overwriting images"
print("Possibly overwriting images")
os.system("cp "+cwd+"/temp.html "+f[:len(f)-5]+"/index.html")
os.chdir(f[:len(f)-5])
canvas[nf].cd()
Expand All @@ -193,14 +193,14 @@ def srcpath(fldr):
#os.system("sleep 2")
os.chdir("../")
else:
print "Warning:to use --canvas option do not use --no_exec option. Rerun without --canvas option."
print("Warning:to use --canvas option do not use --no_exec option. Rerun without --canvas option.")
else:
for nf,f in enumerate(fil):
try:
os.mkdir(f[:len(f)-5])
except OSError,inst:
except OSError as inst:
if inst.errno==errno.EEXIST:
print "Possibly overwriting images"
print("Possibly overwriting images")
os.system("cp "+cwd+"temp.html "+f[:len(f)-5]+"/index.html")
os.chdir(f[:len(f)-5])
canvas[nf].cd()
Expand Down
2 changes: 1 addition & 1 deletion DQMOffline/Configuration/scripts/cmsswConfigtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def trace_python(prog_argv, path):
code = compile(fp.read(), progname, 'exec')
globals = {}
try:
exec code in globals, globals
exec (code, globals, globals)
except:
print(traceback.format_exc())
finally:
Expand Down
2 changes: 1 addition & 1 deletion DQMOffline/Configuration/scripts/cmsswFiletrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def exec_hook(*args):
# now turn on the traceing
sys.settrace(tracefunc)
try:
exec code in globals, globals
exec(code, globals, globals)
finally:
sys.settrace(None)

Expand Down
6 changes: 3 additions & 3 deletions HLTriggerOffline/Btag/test/testSequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def add_rawRelVals(process, inputName):
'The parenthood is needed to add RAW secondary input files' % process.source.fileNames[0]
)
for i in dataset['data']:
try: n_files = i['dataset'][0]['num_file']
except: pass
try: n_files = i['dataset'][0]['num_file']
except: pass
raw_files = cmssw_das_client.get_data('file '+query, limit = 0)
files = []
for i in raw_files['data']:
files.append( i['file'][0]['name'])
files.append( i['file'][0]['name'])

raw_files = ['root://cms-xrd-global.cern.ch/'+str(i) for i in files]
process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(raw_files))
Expand Down
8 changes: 4 additions & 4 deletions Validation/CaloTowers/test/client_data_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

class config: pass
config.runNumber = int(sys.argv[1])
print config.runNumber
print(config.runNumber)

for arg in sys.argv:
print arg
print(arg)

readFiles = cms.untracked.vstring()

Expand All @@ -20,9 +20,9 @@ class config: pass
fileToRead = "file:"+argument
readFiles.append(fileToRead)

print "readFiles : \n", readFiles
print("readFiles : \n", readFiles)

print config.runNumber
print(config.runNumber)

##########

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
options.register('SLHC' , 0, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Run SLHC mode (default false) doesn't do anything yet.")

options.parseArguments()
print options
print(options)

### RANDOM setting (change last digit(s) to make runs different !)
process.load("Configuration.StandardSequences.SimulationRandomNumberGeneratorSeeds_cff")
Expand Down
2 changes: 1 addition & 1 deletion Validation/HcalHits/test/ZdcSimHitStudy_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
process.dqmsave_step = cms.Path(process.DQMSaver)


print process.ZDCDigiStudy.Verbose
print(process.ZDCDigiStudy.Verbose)
process.p1 = cms.Path(
process.ZDCDigiStudy
*process.zdcSimHitStudy)
Expand Down
4 changes: 2 additions & 2 deletions Validation/MuonGEMHits/test/Compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def draw_plot( file1, file2, tDir,oDir ) :
options, args = parser.parse_args()

if len(args)==0 :
print "Input file name is None."
print "Use default name.[ DQM_v6.root and DQM_v7.root]"
print("Input file name is None.")
print("Use default name.[ DQM_v6.root and DQM_v7.root]")
args.append("DQM_v6.root")
args.append("DQM_v7.root")

Expand Down
18 changes: 9 additions & 9 deletions Validation/MuonGEMHits/test/MakePlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def getEtaRange( station ) :
if ( station ==1 or station==2 ) :
return etaRange[ (station-1)*2], etaRange[ (station-1)*2+1 ]
else :
print "Something is wrong"
print("Something is wrong")
return 1.5,2.6

def draw_occ(target_dir, h, ext =".png", opt = ""):
Expand Down Expand Up @@ -171,7 +171,7 @@ def draw_eff(target_dir, h, ext = ".png", opt = ""):
elif ( h.GetName().find("st2") != -1 ) :
xmin,xmax = getEtaRange(2)
else :
print "Use default setting."
print("Use default setting.")

f1 = TF1("fit1","pol0", xmin, xmax )
r = h.Fit("fit1","RQS")
Expand Down Expand Up @@ -216,7 +216,7 @@ def draw_plot( file, tDir,oDir ) :
try :
tlist = d1.GetListOfKeys()
except :
print oDir
print(oDir)
if ( oDir.find("Digi") != -1 ):
tDir = "DQMData/Run 1/MuonGEMDigisV/Run summary/GEMDigiTask"
d1 = dqm_file.Get(tDir)
Expand All @@ -226,7 +226,7 @@ def draw_plot( file, tDir,oDir ) :
d1 = dqm_file.Get(tDir)
tlist = d1.GetListOfKeys()
else :
print "error"
print("error")
exit(-1)
for x in tlist :
key_list.append(x.GetName())
Expand All @@ -249,7 +249,7 @@ def draw_plot( file, tDir,oDir ) :
draw_col_overflow( oDir, d1.Get(hist) )
elif ( hist.find("eff") != -1 ) :
draw_eff( oDir, d1.Get(hist) )
#print "found "
#print("found ")
elif ( hist.find("geo_phi") != -1) :
draw_col_userRange( oDir, d1.Get(hist))
else :
Expand All @@ -273,12 +273,12 @@ def draw_plot( file, tDir,oDir ) :
exit()
# If no argument, default name will be used.
if len(args)==0 :
print "Input file name is None."
print "Use default name."
print("Input file name is None.")
print("Use default name.")
args.append("DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root")

if len(args) != 1 :
print "Can not understand input argument"
print("Can not understand input argument")
parser.print_help()

steps= []
Expand All @@ -299,5 +299,5 @@ def draw_plot( file, tDir,oDir ) :
oDir = options.directory+"_%s"%(step)+'/'
os.system("mkdir -p "+oDir )
draw_plot(args[0],tDir,oDir)
#print args[0],tDir, oDir
#print (args[0],tDir, oDir)

12 changes: 6 additions & 6 deletions Validation/MuonGEMHits/test/phiView.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def draw_plot( file, tDir,oDir,min,max ) :
try :
tlist = d1.GetListOfKeys()
except :
print oDir
print(oDir)
if ( oDir.find("Digi") != -1 ):
tDir = "DQMData/Run 1/MuonGEMDigisV/Run summary/GEMDigiTask"
d1 = dqm_file.Get(tDir)
tlist = d1.GetListOfKeys()
else :
print "error"
print("error")
exit(-1)
for x in tlist :
key_list.append(x.GetName())
Expand All @@ -66,20 +66,20 @@ def draw_plot( file, tDir,oDir,min,max ) :
parser.add_option("--max",dest='range_max',help='Maximum of phi degree',default=15.5)
options, args = parser.parse_args()

print options.range_min, options.range_max
print(options.range_min, options.range_max)
min = options.range_min
max = options.range_max
if len(sys.argv) ==1 :
parser.print_help()
exit()
# If no argument, default name will be used.
if len(args)==0 :
print "Input file name is None."
print "Use default name."
print("Input file name is None.")
print("Use default name.")
args.append("DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root")

if len(args) != 1 :
print "Can not understand input argument"
print("Can not understand input argument")
parser.print_help()

steps= []
Expand Down
14 changes: 7 additions & 7 deletions Validation/RecoMuon/test/muonReleaseSummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def GetLabel(params):
label += '-' + params['Version']

if (params['PileUp']!='no'):
label = 'PU' + params['PileUp']+ '_' + label
label = 'PU' + params['PileUp']+ '_' + label

return label

Expand Down Expand Up @@ -95,13 +95,13 @@ def downloadfile(url):
output=stream.readlines()
if output[0]=='200':
print(' + OK!')
return True
return True
else:
print(' + ERROR! ' + str(output[0]))
print("Skipping " + url)
print("Please check the name of the file in the repository: "+GetGuiRepository(userparams.NewParams))
print("Skipping " + url)
print("Please check the name of the file in the repository: "+GetGuiRepository(userparams.NewParams))
sys.exit('Exiting...');
# return False
# return False

def GetSamplePath(params, sample):
return params['Release']+'/'+GetTag(params)+'/'+sample
Expand Down Expand Up @@ -175,8 +175,8 @@ def getSampleFiles(params, sample):
#os.system('wget --ca-directory $X509_CERT_DIR/ --certificate=$X509_USER_PROXY --private-key=$X509_USER_PROXY '+GetGuiRepository(params)+guiFileName)
#os.system('/usr/bin/curl -O -L --capath $X509_CERT_DIR --key $X509_USER_PROXY --cert $X509_USER_PROXY '+ guiFullURL)
if (downloadfile(guiFullURL)==True):
print(' + Moving ' + guiFileName + ' to ' + localsample)
shutil.move(guiFileName,localsample)
print(' + Moving ' + guiFileName + ' to ' + localsample)
shutil.move(guiFileName,localsample)

elif (params['GetFilesFrom']=='CASTOR'):
print(' + Getting new file from castor')
Expand Down
10 changes: 5 additions & 5 deletions Validation/RecoMuon/test/new_muonReleaseSummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def GetLabel(params):
label += '-' + params['Version']

if (params['PileUp']!='no'):
label = 'PU' + params['PileUp']+ '_' + label
label = 'PU' + params['PileUp']+ '_' + label

return label

Expand Down Expand Up @@ -98,13 +98,13 @@ def downloadfile(url):
output=stream.readlines()
if output[0]=='200':
print(' + OK!')
return True
return True
else:
print(' + ERROR! ' + str(output[0]))
print("Skipping " + url)
print("Please check the name of the file in the repository: "+GetGuiRepository(new_userparams.NewParams))
print("Skipping " + url)
print("Please check the name of the file in the repository: "+GetGuiRepository(new_userparams.NewParams))
sys.exit('Exiting...');
return False
return False

def GetSamplePath(params, sample):
return params['Release']+'/'+GetTag(params)+'/'+sample+'_'+params['Energy']
Expand Down
Loading