77import sys
88
99Input_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
1414Input_CffFile = "InputFiles_cff.py"
1515Input_CffN = 1
1616
1717
1818Output_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
2626FarmDirectory = "FARM"
2727QUEUE = "cmscaf1nd"
3030
3131def 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 \t Number 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 + "\t Output 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 \t Number 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 + "\t Output 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 + "\t Number 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
123123def 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
152152def 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
177177os .system ('mkdir ' + FarmDirectory )
178178os .system ('mkdir ' + FarmDirectory + '/RootFiles' )
179179os .system ('mkdir ' + FarmDirectory + '/Log' )
180180os .system ('mkdir ' + FarmDirectory + '/InputFile' )
181181
182182for 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 ' )
220220NJobs = Job_End - Job_Start
221221print ("\n \n " )
222222print ("\t \t \t %i Jobs submitted by the LaunchOnFarm script" % NJobs )
0 commit comments