Skip to content

Commit

Permalink
Merge pull request #46163 from iarspider/iarspider-patches-20240930-0
Browse files Browse the repository at this point in the history
[ALCA] Fix syntax in python scripts
  • Loading branch information
cmsbuild authored Oct 2, 2024
2 parents ca7a9e9 + 1b6fb6c commit 231fb53
Show file tree
Hide file tree
Showing 25 changed files with 569 additions and 567 deletions.
8 changes: 4 additions & 4 deletions Alignment/OfflineValidation/scripts/createIOVlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parser():

##Called in fillJson function in parallel
def getFileInfo(filename):
print "Processing: {}".format(filename)
print("Processing: {}".format(filename))

##Get file info
try:
Expand All @@ -37,7 +37,7 @@ def getFileInfo(filename):

##File not at CERN
except:
print "Not at CERN {}".format(filename)
print("Not at CERN {}".format(filename))
runInfo = filename

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

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

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

else:
print "Not at CERN {}".format(dataset)
print("Not at CERN {}".format(dataset))

return filelist, emptyfiles, nEvents

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ def miscalib(lumi,endcap,z,etaindex,phiindex,randval):
miscal_fac=miscalib(lumi,endcap,zindex,etaindex,phiindex,1)
# create line:
if endcap==0:
if zindex==-1:
if zindex==-1:
line=' <Cell eta_index="'+str(-etaindex)+'" phi_index="'+str(phiindex)+'" scale_factor="'+str(miscal_fac)+'"/>\n'
xmlfile.write(line)
count=count+1
else:
else:
line=' <Cell eta_index="'+str(+etaindex)+'" phi_index="'+str(phiindex)+'" scale_factor="'+str(miscal_fac)+'"/>\n'
xmlfile.write(line)
count=count+1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
#-------------- Getting Digis
EBdigiCollection = cms.string("ebDigis"),
EEdigiCollection = cms.string("eeDigis"),
)
#-------------- EcnaSystemPythoModuleInsert_2 / end
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
#-------------- Getting Digis
EBdigiCollection = cms.string("ebDigis"),
EEdigiCollection = cms.string("eeDigis"),
)
#-------------- EcnaSystemPythoModuleInsert_2 _data/ end

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
#-------------- Getting Digis
EBdigiCollection = cms.string("ebDigis"),
EEdigiCollection = cms.string("eeDigis"),
)
#-------------- EcnaSystemPythoModuleInsert_2 _simul/ end
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ def numberOfEvents(file,mode):

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

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

name = "Run_"+str(firstRun)+"_to_"+str(lastRun)
if len(calMode)>0: name = name+"_"+calMode
Expand Down
4 changes: 2 additions & 2 deletions CalibTracker/SiStripChannelGain/test/7TeVData/dataCert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def splitByTag(line,tags=["td","th"]):
for tag in tags:
posTag=line.find("<"+tag,pos)
if posTag<firstTagPos and posTag>-1:
firstTag=tag
firstTagPos=posTag
firstTag=tag
firstTagPos=posTag
if not firstTag:
break
tag=firstTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
import sys

Input_ConfigFile = "computeGain_cfg.py"
# The name of your config file
# where you have to replace the OutputAdresse by XXX_OUTPUT_XXX
# and the Number of Events by XXX_NEVENTS_XXX
# and the Number of Event to skip is XXX_SKIPEVENT_XXX
# The name of your config file
# where you have to replace the OutputAdresse by XXX_OUTPUT_XXX
# and the Number of Events by XXX_NEVENTS_XXX
# and the Number of Event to skip is XXX_SKIPEVENT_XXX
Input_CffFile = "InputFiles_cff.py"
Input_CffN = 1


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

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

FarmDirectory = "FARM"
QUEUE = "cmscaf1nd"
Expand All @@ -30,48 +30,48 @@

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

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

mylogo1 = "# -----------------------------------------------\n"
mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
mylogo3 = "# | Created by Loic Quertenmont |\n"
mylogo4 = "# | [email protected] |\n"
mylogo5 = "# -----------------------------------------------\n\n\n\n"
config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt

i=0
while i < len(config_txt) :
if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
Skip = INDEX*NEVENTS+Job_SEvents
MaxEvent = NEVENTS
print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
newconfig_file=open(newconfig_path,'w')
newconfig_file.write("%s" % config_txt[0:i])
newconfig_file.write("%d" % MaxEvent)
newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
newconfig_file.close()
newconfig_file=open(newconfig_path,'r')
config_txt = newconfig_file.read()
newconfig_file.close()
i = 0
if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
newconfig_file=open(newconfig_path,'w')
newconfig_file.write("%s" % config_txt[0:i])
newconfig_file.write("%s"% OUTPUTFILE)
newconfig_file.write("_%04i.root" % INDEX)
newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
newconfig_file.close()
newconfig_file=open(newconfig_path,'r')
config_txt = newconfig_file.read()
newconfig_file.close()
i = 0
mylogo1 = "# -----------------------------------------------\n"
mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
mylogo3 = "# | Created by Loic Quertenmont |\n"
mylogo4 = "# | [email protected] |\n"
mylogo5 = "# -----------------------------------------------\n\n\n\n"
config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt

i=0
while i < len(config_txt) :
if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
Skip = INDEX*NEVENTS+Job_SEvents
MaxEvent = NEVENTS
print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
newconfig_file=open(newconfig_path,'w')
newconfig_file.write("%s" % config_txt[0:i])
newconfig_file.write("%d" % MaxEvent)
newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
newconfig_file.close()
newconfig_file=open(newconfig_path,'r')
config_txt = newconfig_file.read()
newconfig_file.close()
i = 0
if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
newconfig_file=open(newconfig_path,'w')
newconfig_file.write("%s" % config_txt[0:i])
newconfig_file.write("%s"% OUTPUTFILE)
newconfig_file.write("_%04i.root" % INDEX)
newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
newconfig_file.close()
newconfig_file=open(newconfig_path,'r')
config_txt = newconfig_file.read()
newconfig_file.close()
i = 0
if config_txt[i:i+17]=='XXX_SKIPEVENT_XXX':
Skip = INDEX*NEVENTS+Job_SEvents
Skip = INDEX*NEVENTS+Job_SEvents
print("job #%d" %INDEX + "\tNumber of Event to skip is fixed to\t\t%i"%Skip)
newconfig_file=open(newconfig_path,'w')
newconfig_file.write("%s" % config_txt[0:i])
Expand Down Expand Up @@ -118,30 +118,30 @@ def CreateTheConfigFile(PATH,CONFIG_FILE,NEVENTS,OUTPUTFILE,INPUTFILE,INDEX):



i = i+1
i = i+1

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

config_file=open(INPUT_FILE,'r')
config_txt = ""
i=0
i=0
iMin = (INDEX+0)*Input_CffN
iMax = (INDEX+1)*Input_CffN-1
iMax = (INDEX+1)*Input_CffN-1
for line in config_file:
# if(line[0:1]!='\''):
# continue
# continue

if( (i>=iMin) and (i<=iMax) ):
config_txt = config_txt + line
config_txt = config_txt + line
i = i+1

if(iMax>=i):
return 0
return 0
config_file.close()


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

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


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

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

shell_file=open(shell_path,'w')
shell_file.write("#! /bin/sh\n")
shell_file.write("# ----------------------------------------------- \n")
shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
shell_file.write("# | Created by Loic Quertenmont |\n")
shell_file.write("# | [email protected] |\n")
shell_file.write("# ----------------------------------------------- \n\n\n\n")
shell_file=open(shell_path,'w')
shell_file.write("#! /bin/sh\n")
shell_file.write("# ----------------------------------------------- \n")
shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
shell_file.write("# | Created by Loic Quertenmont |\n")
shell_file.write("# | [email protected] |\n")
shell_file.write("# ----------------------------------------------- \n\n\n\n")
shell_file.write("%s" % "cd " + PATH + "/" + FarmDirectory + "\n")
shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
# shell_file.write("%s\n" % "export STAGE_SVCCLASS=cmscaf")
# shell_file.write("%s\n" % "export STAGER_TRACE=3")
shell_file.write("%s" % "cmsRun " + cfg_path +"\n")
shell_file.close()
chmod_path = "chmod 777 "+shell_path
os.system(chmod_path)
shell_file.close()
chmod_path = "chmod 777 "+shell_path
os.system(chmod_path)


path = os.getcwd() #Get the current path
path = os.getcwd() #Get the current path
os.system('mkdir '+FarmDirectory)
os.system('mkdir '+FarmDirectory+'/RootFiles')
os.system('mkdir '+FarmDirectory+'/Log')
os.system('mkdir '+FarmDirectory+'/InputFile')

for i in range(Job_Start,Job_End):
print('Submitting job number %d' %i)
print('Submitting job number %d' %i)

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

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

condor_path = "./"+FarmDirectory+"/InputFile/%04i_" % i
condor_path = "./"+FarmDirectory+"/InputFile/%04i_" % i
condor_path = condor_path + Output_RootFile + ".cmd"

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

print('\n')
print('\n')
NJobs = Job_End - Job_Start
print("\n\n")
print("\t\t\t%i Jobs submitted by the LaunchOnFarm script" % NJobs)
Expand Down
Loading

0 comments on commit 231fb53

Please sign in to comment.