Skip to content

Commit 231fb53

Browse files
authored
Merge pull request #46163 from iarspider/iarspider-patches-20240930-0
[ALCA] Fix syntax in python scripts
2 parents ca7a9e9 + 1b6fb6c commit 231fb53

File tree

25 files changed

+569
-567
lines changed

25 files changed

+569
-567
lines changed

Alignment/OfflineValidation/scripts/createIOVlist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def parser():
2727

2828
##Called in fillJson function in parallel
2929
def getFileInfo(filename):
30-
print "Processing: {}".format(filename)
30+
print("Processing: {}".format(filename))
3131

3232
##Get file info
3333
try:
@@ -37,7 +37,7 @@ def getFileInfo(filename):
3737

3838
##File not at CERN
3939
except:
40-
print "Not at CERN {}".format(filename)
40+
print("Not at CERN {}".format(filename))
4141
runInfo = filename
4242

4343
return runInfo
@@ -52,7 +52,7 @@ def getFileList(dataset):
5252
##Find files in dataset
5353
dbs = DbsApi('https://cmsweb.cern.ch/dbs/prod/global/DBSReader')
5454

55-
print "Processing: {}".format(dataset)
55+
print("Processing: {}".format(dataset))
5656
sites = subprocess.check_output(["dasgoclient", "--query", "site dataset={}".format(dataset)]).split()
5757

5858
if "T2_CH_CERN" in sites:
@@ -68,7 +68,7 @@ def getFileList(dataset):
6868
emptyfiles.append(filename)
6969

7070
else:
71-
print "Not at CERN {}".format(dataset)
71+
print("Not at CERN {}".format(dataset))
7272

7373
return filelist, emptyfiles, nEvents
7474

CalibCalorimetry/CaloMiscalibTools/test/make_ecal_miscaplibration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ def miscalib(lumi,endcap,z,etaindex,phiindex,randval):
152152
miscal_fac=miscalib(lumi,endcap,zindex,etaindex,phiindex,1)
153153
# create line:
154154
if endcap==0:
155-
if zindex==-1:
155+
if zindex==-1:
156156
line=' <Cell eta_index="'+str(-etaindex)+'" phi_index="'+str(phiindex)+'" scale_factor="'+str(miscal_fac)+'"/>\n'
157157
xmlfile.write(line)
158158
count=count+1
159-
else:
159+
else:
160160
line=' <Cell eta_index="'+str(+etaindex)+'" phi_index="'+str(phiindex)+'" scale_factor="'+str(miscal_fac)+'"/>\n'
161161
xmlfile.write(line)
162162
count=count+1

CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/data/EcnaSystemPythonModuleInsert_2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
#-------------- Getting Digis
2525
EBdigiCollection = cms.string("ebDigis"),
2626
EEdigiCollection = cms.string("eeDigis"),
27+
)
2728
#-------------- EcnaSystemPythoModuleInsert_2 / end

CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/data/EcnaSystemPythonModuleInsert_2_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
#-------------- Getting Digis
2424
EBdigiCollection = cms.string("ebDigis"),
2525
EEdigiCollection = cms.string("eeDigis"),
26+
)
2627
#-------------- EcnaSystemPythoModuleInsert_2 _data/ end
2728

CalibCalorimetry/EcalCorrelatedNoiseAnalysisModules/data/EcnaSystemPythonModuleInsert_2_simul.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
#-------------- Getting Digis
2525
EBdigiCollection = cms.string("ebDigis"),
2626
EEdigiCollection = cms.string("eeDigis"),
27+
)
2728
#-------------- EcnaSystemPythoModuleInsert_2 _simul/ end

CalibTracker/SiStripChannelGain/test/7TeVData/automatic_RunOnCalibTree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ def numberOfEvents(file,mode):
208208

209209
print("RunRange=[" + str(firstRun) + "," + str(lastRun) + "] --> NEvents=" + str(NTotalEvents/1000)+"K")
210210

211-
if(automatic==True and NTotalEvents<2e6): #ask at least 2M events to perform the calibration
212-
print('Not Enough events to run the calibration')
211+
if(automatic==True and NTotalEvents<2e6): #ask at least 2M events to perform the calibration
212+
print('Not Enough events to run the calibration')
213213
os.system('echo "Gain calibration postponed" | mail -s "Gain calibration postponed ('+str(firstRun)+' to '+str(lastRun)+') NEvents=' + str(NTotalEvents/1000)+'K" ' + mail)
214-
exit(0);
214+
exit(0)
215215

216216
name = "Run_"+str(firstRun)+"_to_"+str(lastRun)
217217
if len(calMode)>0: name = name+"_"+calMode

CalibTracker/SiStripChannelGain/test/7TeVData/dataCert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def splitByTag(line,tags=["td","th"]):
1616
for tag in tags:
1717
posTag=line.find("<"+tag,pos)
1818
if posTag<firstTagPos and posTag>-1:
19-
firstTag=tag
20-
firstTagPos=posTag
19+
firstTag=tag
20+
firstTagPos=posTag
2121
if not firstTag:
2222
break
2323
tag=firstTag

CalibTracker/SiStripChannelGain/test/CodeExample/computeGain_cfg_OnBatch.py

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
import sys
88

99
Input_ConfigFile = "computeGain_cfg.py"
10-
# The name of your config file
11-
# where you have to replace the OutputAdresse by XXX_OUTPUT_XXX
12-
# and the Number of Events by XXX_NEVENTS_XXX
13-
# and the Number of Event to skip is XXX_SKIPEVENT_XXX
10+
# The name of your config file
11+
# where you have to replace the OutputAdresse by XXX_OUTPUT_XXX
12+
# and the Number of Events by XXX_NEVENTS_XXX
13+
# and the Number of Event to skip is XXX_SKIPEVENT_XXX
1414
Input_CffFile = "InputFiles_cff.py"
1515
Input_CffN = 1
1616

1717

1818
Output_RootFile = "SST_MERGE_GAIN" # The name of your output file (will replace XXX_OUTPUT_XXX)
1919

20-
Job_NEvents = -1 # Number of Events by job (will replace XXX_NEVENTS_XXX)
21-
Job_Start = 0 # The Index of your first job
22-
Job_End = 1 # The Index of your last job
23-
Job_SEvents = 0 # Event that you want to skip
24-
# The first event will be Job_SEvents+1
20+
Job_NEvents = -1 # Number of Events by job (will replace XXX_NEVENTS_XXX)
21+
Job_Start = 0 # The Index of your first job
22+
Job_End = 1 # The Index of your last job
23+
Job_SEvents = 0 # Event that you want to skip
24+
# The first event will be Job_SEvents+1
2525

2626
FarmDirectory = "FARM"
2727
QUEUE = "cmscaf1nd"
@@ -30,48 +30,48 @@
3030

3131
def CreateTheConfigFile(PATH,CONFIG_FILE,NEVENTS,OUTPUTFILE,INPUTFILE,INDEX):
3232

33-
config_file=open(CONFIG_FILE,'r')
34-
config_txt = config_file.read() # Read all data
35-
config_file.close()
36-
newconfig_path = PATH + "/"+FarmDirectory+"/InputFile/%04i_" % INDEX
33+
config_file=open(CONFIG_FILE,'r')
34+
config_txt = config_file.read() # Read all data
35+
config_file.close()
36+
newconfig_path = PATH + "/"+FarmDirectory+"/InputFile/%04i_" % INDEX
3737
newconfig_path = newconfig_path + Output_RootFile + "_cfg.py"
3838

39-
mylogo1 = "# -----------------------------------------------\n"
40-
mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
41-
mylogo3 = "# | Created by Loic Quertenmont |\n"
42-
mylogo4 = "# | [email protected] |\n"
43-
mylogo5 = "# -----------------------------------------------\n\n\n\n"
44-
config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt
45-
46-
i=0
47-
while i < len(config_txt) :
48-
if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
49-
Skip = INDEX*NEVENTS+Job_SEvents
50-
MaxEvent = NEVENTS
51-
print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
52-
newconfig_file=open(newconfig_path,'w')
53-
newconfig_file.write("%s" % config_txt[0:i])
54-
newconfig_file.write("%d" % MaxEvent)
55-
newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
56-
newconfig_file.close()
57-
newconfig_file=open(newconfig_path,'r')
58-
config_txt = newconfig_file.read()
59-
newconfig_file.close()
60-
i = 0
61-
if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
62-
print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
63-
newconfig_file=open(newconfig_path,'w')
64-
newconfig_file.write("%s" % config_txt[0:i])
65-
newconfig_file.write("%s"% OUTPUTFILE)
66-
newconfig_file.write("_%04i.root" % INDEX)
67-
newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
68-
newconfig_file.close()
69-
newconfig_file=open(newconfig_path,'r')
70-
config_txt = newconfig_file.read()
71-
newconfig_file.close()
72-
i = 0
39+
mylogo1 = "# -----------------------------------------------\n"
40+
mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
41+
mylogo3 = "# | Created by Loic Quertenmont |\n"
42+
mylogo4 = "# | [email protected] |\n"
43+
mylogo5 = "# -----------------------------------------------\n\n\n\n"
44+
config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt
45+
46+
i=0
47+
while i < len(config_txt) :
48+
if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
49+
Skip = INDEX*NEVENTS+Job_SEvents
50+
MaxEvent = NEVENTS
51+
print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
52+
newconfig_file=open(newconfig_path,'w')
53+
newconfig_file.write("%s" % config_txt[0:i])
54+
newconfig_file.write("%d" % MaxEvent)
55+
newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
56+
newconfig_file.close()
57+
newconfig_file=open(newconfig_path,'r')
58+
config_txt = newconfig_file.read()
59+
newconfig_file.close()
60+
i = 0
61+
if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
62+
print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
63+
newconfig_file=open(newconfig_path,'w')
64+
newconfig_file.write("%s" % config_txt[0:i])
65+
newconfig_file.write("%s"% OUTPUTFILE)
66+
newconfig_file.write("_%04i.root" % INDEX)
67+
newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
68+
newconfig_file.close()
69+
newconfig_file=open(newconfig_path,'r')
70+
config_txt = newconfig_file.read()
71+
newconfig_file.close()
72+
i = 0
7373
if config_txt[i:i+17]=='XXX_SKIPEVENT_XXX':
74-
Skip = INDEX*NEVENTS+Job_SEvents
74+
Skip = INDEX*NEVENTS+Job_SEvents
7575
print("job #%d" %INDEX + "\tNumber of Event to skip is fixed to\t\t%i"%Skip)
7676
newconfig_file=open(newconfig_path,'w')
7777
newconfig_file.write("%s" % config_txt[0:i])
@@ -118,30 +118,30 @@ def CreateTheConfigFile(PATH,CONFIG_FILE,NEVENTS,OUTPUTFILE,INPUTFILE,INDEX):
118118

119119

120120

121-
i = i+1
121+
i = i+1
122122

123123
def GetInputFiles(PATH,INPUT_FILE,NEVENTS,OUTPUTFILE,INDEX):
124124

125125
config_file=open(INPUT_FILE,'r')
126126
config_txt = ""
127-
i=0
127+
i=0
128128
iMin = (INDEX+0)*Input_CffN
129-
iMax = (INDEX+1)*Input_CffN-1
129+
iMax = (INDEX+1)*Input_CffN-1
130130
for line in config_file:
131131
# if(line[0:1]!='\''):
132-
# continue
132+
# continue
133133

134134
if( (i>=iMin) and (i<=iMax) ):
135-
config_txt = config_txt + line
135+
config_txt = config_txt + line
136136
i = i+1
137137

138138
if(iMax>=i):
139-
return 0
139+
return 0
140140
config_file.close()
141141

142142

143143
if(config_txt[len(config_txt)-2:len(config_txt)-1]==','):
144-
config_txt = config_txt[0:len(config_txt)-2]
144+
config_txt = config_txt[0:len(config_txt)-2]
145145
newconfig_path = PATH + "/"+FarmDirectory+"/InputFile/%04i_" % INDEX
146146
newconfig_path = newconfig_path + Output_RootFile + "_cff.py"
147147

@@ -150,37 +150,37 @@ def GetInputFiles(PATH,INPUT_FILE,NEVENTS,OUTPUTFILE,INDEX):
150150

151151

152152
def CreateTheShellFile(PATH,INDEX):
153-
shell_path = "./"+FarmDirectory+"/InputFile/%04i_" % INDEX
153+
shell_path = "./"+FarmDirectory+"/InputFile/%04i_" % INDEX
154154
shell_path = shell_path + Output_RootFile + ".sh"
155155

156156
cfg_path = PATH + "/" + FarmDirectory + "/InputFile/%04i_" % INDEX
157157
cfg_path = cfg_path + Output_RootFile + "_cfg.py"
158158

159-
shell_file=open(shell_path,'w')
160-
shell_file.write("#! /bin/sh\n")
161-
shell_file.write("# ----------------------------------------------- \n")
162-
shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
163-
shell_file.write("# | Created by Loic Quertenmont |\n")
164-
shell_file.write("# | [email protected] |\n")
165-
shell_file.write("# ----------------------------------------------- \n\n\n\n")
159+
shell_file=open(shell_path,'w')
160+
shell_file.write("#! /bin/sh\n")
161+
shell_file.write("# ----------------------------------------------- \n")
162+
shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
163+
shell_file.write("# | Created by Loic Quertenmont |\n")
164+
shell_file.write("# | [email protected] |\n")
165+
shell_file.write("# ----------------------------------------------- \n\n\n\n")
166166
shell_file.write("%s" % "cd " + PATH + "/" + FarmDirectory + "\n")
167-
shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
167+
shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
168168
# shell_file.write("%s\n" % "export STAGE_SVCCLASS=cmscaf")
169169
# shell_file.write("%s\n" % "export STAGER_TRACE=3")
170170
shell_file.write("%s" % "cmsRun " + cfg_path +"\n")
171-
shell_file.close()
172-
chmod_path = "chmod 777 "+shell_path
173-
os.system(chmod_path)
171+
shell_file.close()
172+
chmod_path = "chmod 777 "+shell_path
173+
os.system(chmod_path)
174174

175175

176-
path = os.getcwd() #Get the current path
176+
path = os.getcwd() #Get the current path
177177
os.system('mkdir '+FarmDirectory)
178178
os.system('mkdir '+FarmDirectory+'/RootFiles')
179179
os.system('mkdir '+FarmDirectory+'/Log')
180180
os.system('mkdir '+FarmDirectory+'/InputFile')
181181

182182
for i in range(Job_Start,Job_End):
183-
print('Submitting job number %d' %i)
183+
print('Submitting job number %d' %i)
184184

185185
input_path = FarmDirectory + ".InputFile.%04i_" % i
186186
input_path = input_path + Output_RootFile + "_cff.py"
@@ -189,18 +189,18 @@ def CreateTheShellFile(PATH,INDEX):
189189
# if( GetInputFiles(path,Input_CffFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,i) == 0)
190190
# print('error during the _cfg.py file creation --> are you sure InputFile_cff.py contains enough lines? \n')
191191
# continue
192-
192+
193193

194-
# cff_created = 0
194+
# cff_created = 0
195195
# if(len(Input_CffFile)>3):
196-
# cff_created = CreateTheInputFile(path,Input_CffFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,i)
196+
# cff_created = CreateTheInputFile(path,Input_CffFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,i)
197197
# if(cff_created==0):
198198
# print('error during the cff file creation --> are you sure it contains enough lines? \n')
199-
# continue
200-
CreateTheConfigFile(path,Input_ConfigFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,input_path,i)
201-
CreateTheShellFile(path,i)
199+
# continue
200+
CreateTheConfigFile(path,Input_ConfigFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,input_path,i)
201+
CreateTheShellFile(path,i)
202202

203-
condor_path = "./"+FarmDirectory+"/InputFile/%04i_" % i
203+
condor_path = "./"+FarmDirectory+"/InputFile/%04i_" % i
204204
condor_path = condor_path + Output_RootFile + ".cmd"
205205

206206
shell_path = path + "/" + FarmDirectory + "/InputFile/%04i_" % i
@@ -214,9 +214,9 @@ def CreateTheShellFile(PATH,INDEX):
214214
# batchSubmit = "bsub -q" + QUEUE + " -J" + JobName + "'" + shell_path + " 0 ele'"
215215
# batchSubmit = "bsub -q " + QUEUE + " -J " + JobName + " -oo " + OutputPath + " -eo " + OutputPath + " '" + shell_path + " 0 ele'"
216216
batchSubmit = "bsub -q " + QUEUE + " -J " + JobName + " '" + shell_path + " 0 ele'"
217-
os.system (batchSubmit)
217+
os.system (batchSubmit)
218218

219-
print('\n')
219+
print('\n')
220220
NJobs = Job_End - Job_Start
221221
print("\n\n")
222222
print("\t\t\t%i Jobs submitted by the LaunchOnFarm script" % NJobs)

0 commit comments

Comments
 (0)