File indexing completed on 2024-11-25 02:29:10
0001
0002
0003 import urllib
0004 import string
0005 import os
0006 import sys
0007
0008 Input_ConfigFile = "computeGain_cfg.py"
0009
0010
0011
0012
0013 Input_CffFile = "InputFiles_cff.py"
0014 Input_CffN = 1
0015
0016
0017 Output_RootFile = "SST_MERGE_GAIN"
0018
0019 Job_NEvents = -1
0020 Job_Start = 0
0021 Job_End = 1
0022 Job_SEvents = 0
0023
0024
0025 FarmDirectory = "FARM"
0026 QUEUE = "cmscaf1nd"
0027
0028
0029
0030 def CreateTheConfigFile(PATH,CONFIG_FILE,NEVENTS,OUTPUTFILE,INPUTFILE,INDEX):
0031
0032 config_file=open(CONFIG_FILE,'r')
0033 config_txt = config_file.read()
0034 config_file.close()
0035 newconfig_path = PATH + "/"+FarmDirectory+"/InputFile/%04i_" % INDEX
0036 newconfig_path = newconfig_path + Output_RootFile + "_cfg.py"
0037
0038 mylogo1 = "# -----------------------------------------------\n"
0039 mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
0040 mylogo3 = "# | Created by Loic Quertenmont |\n"
0041 mylogo4 = "# | Loic.quertenmont@cern.ch |\n"
0042 mylogo5 = "# -----------------------------------------------\n\n\n\n"
0043 config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt
0044
0045 i=0
0046 while i < len(config_txt) :
0047 if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
0048 Skip = INDEX*NEVENTS+Job_SEvents
0049 MaxEvent = NEVENTS
0050 print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
0051 newconfig_file=open(newconfig_path,'w')
0052 newconfig_file.write("%s" % config_txt[0:i])
0053 newconfig_file.write("%d" % MaxEvent)
0054 newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
0055 newconfig_file.close()
0056 newconfig_file=open(newconfig_path,'r')
0057 config_txt = newconfig_file.read()
0058 newconfig_file.close()
0059 i = 0
0060 if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
0061 print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
0062 newconfig_file=open(newconfig_path,'w')
0063 newconfig_file.write("%s" % config_txt[0:i])
0064 newconfig_file.write("%s"% OUTPUTFILE)
0065 newconfig_file.write("_%04i.root" % INDEX)
0066 newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
0067 newconfig_file.close()
0068 newconfig_file=open(newconfig_path,'r')
0069 config_txt = newconfig_file.read()
0070 newconfig_file.close()
0071 i = 0
0072 if config_txt[i:i+17]=='XXX_SKIPEVENT_XXX':
0073 Skip = INDEX*NEVENTS+Job_SEvents
0074 print("job #%d" %INDEX + "\tNumber of Event to skip is fixed to\t\t%i"%Skip)
0075 newconfig_file=open(newconfig_path,'w')
0076 newconfig_file.write("%s" % config_txt[0:i])
0077 newconfig_file.write("%i"%Skip)
0078 newconfig_file.write("%s" % config_txt[i+17:len(config_txt)])
0079 newconfig_file.close()
0080 newconfig_file=open(newconfig_path,'r')
0081 config_txt = newconfig_file.read()
0082 newconfig_file.close()
0083 i = 0
0084 if config_txt[i:i+9]=='XXX_I_XXX':
0085 newconfig_file=open(newconfig_path,'w')
0086 newconfig_file.write("%s" % config_txt[0:i])
0087 newconfig_file.write("%04i"%INDEX)
0088 newconfig_file.write("%s" % config_txt[i+9:len(config_txt)])
0089 newconfig_file.close()
0090 newconfig_file=open(newconfig_path,'r')
0091 config_txt = newconfig_file.read()
0092 newconfig_file.close()
0093 i = 0
0094 if config_txt[i:i+13]=='XXX_INPUT_XXX':
0095 print("job #%d" %INDEX + "\tInput file fixed to\t\t%s"%INPUTFILE)
0096 newconfig_file=open(newconfig_path,'w')
0097 newconfig_file.write("%s" % config_txt[0:i])
0098 newconfig_file.write("%s" % GetInputFiles(PATH,Input_CffFile,NEVENTS,OUTPUTFILE,INDEX))
0099 newconfig_file.write("%s" % config_txt[i+13:len(config_txt)])
0100 newconfig_file.close()
0101 newconfig_file=open(newconfig_path,'r')
0102 config_txt = newconfig_file.read()
0103 newconfig_file.close()
0104 i = 0
0105 if config_txt[i:i+17]=='XXX_LOCALPATH_XXX':
0106 newconfig_file=open(newconfig_path,'w')
0107 newconfig_file.write("%s" % config_txt[0:i])
0108 newconfig_file.write("%s" % PATH)
0109 newconfig_file.write("%s" % config_txt[i+17:len(config_txt)])
0110 newconfig_file.close()
0111 newconfig_file=open(newconfig_path,'r')
0112 config_txt = newconfig_file.read()
0113 newconfig_file.close()
0114 i = 0
0115
0116
0117
0118
0119
0120 i = i+1
0121
0122 def GetInputFiles(PATH,INPUT_FILE,NEVENTS,OUTPUTFILE,INDEX):
0123
0124 config_file=open(INPUT_FILE,'r')
0125 config_txt = ""
0126 i=0
0127 iMin = (INDEX+0)*Input_CffN
0128 iMax = (INDEX+1)*Input_CffN-1
0129 for line in config_file:
0130
0131
0132
0133 if( (i>=iMin) and (i<=iMax) ):
0134 config_txt = config_txt + line
0135 i = i+1
0136
0137 if(iMax>=i):
0138 return 0
0139 config_file.close()
0140
0141
0142 if(config_txt[len(config_txt)-2:len(config_txt)-1]==','):
0143 config_txt = config_txt[0:len(config_txt)-2]
0144 newconfig_path = PATH + "/"+FarmDirectory+"/InputFile/%04i_" % INDEX
0145 newconfig_path = newconfig_path + Output_RootFile + "_cff.py"
0146
0147 return config_txt
0148
0149
0150
0151 def CreateTheShellFile(PATH,INDEX):
0152 shell_path = "./"+FarmDirectory+"/InputFile/%04i_" % INDEX
0153 shell_path = shell_path + Output_RootFile + ".sh"
0154
0155 cfg_path = PATH + "/" + FarmDirectory + "/InputFile/%04i_" % INDEX
0156 cfg_path = cfg_path + Output_RootFile + "_cfg.py"
0157
0158 shell_file=open(shell_path,'w')
0159 shell_file.write("#! /bin/sh\n")
0160 shell_file.write("# ----------------------------------------------- \n")
0161 shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
0162 shell_file.write("# | Created by Loic Quertenmont |\n")
0163 shell_file.write("# | Loic.quertenmont@cern.ch |\n")
0164 shell_file.write("# ----------------------------------------------- \n\n\n\n")
0165 shell_file.write("%s" % "cd " + PATH + "/" + FarmDirectory + "\n")
0166 shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
0167
0168
0169 shell_file.write("%s" % "cmsRun " + cfg_path +"\n")
0170 shell_file.close()
0171 chmod_path = "chmod 777 "+shell_path
0172 os.system(chmod_path)
0173
0174
0175 path = os.getcwd()
0176 os.system('mkdir '+FarmDirectory)
0177 os.system('mkdir '+FarmDirectory+'/RootFiles')
0178 os.system('mkdir '+FarmDirectory+'/Log')
0179 os.system('mkdir '+FarmDirectory+'/InputFile')
0180
0181 for i in range(Job_Start,Job_End):
0182 print('Submitting job number %d' %i)
0183
0184 input_path = FarmDirectory + ".InputFile.%04i_" % i
0185 input_path = input_path + Output_RootFile + "_cff.py"
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 CreateTheConfigFile(path,Input_ConfigFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,input_path,i)
0200 CreateTheShellFile(path,i)
0201
0202 condor_path = "./"+FarmDirectory+"/InputFile/%04i_" % i
0203 condor_path = condor_path + Output_RootFile + ".cmd"
0204
0205 shell_path = path + "/" + FarmDirectory + "/InputFile/%04i_" % i
0206 shell_path = shell_path + Output_RootFile + ".sh"
0207
0208 JobName = "'" + Output_RootFile + "%04i'" % i
0209
0210
0211 OutputPath = "'out/'"
0212
0213
0214
0215 batchSubmit = "bsub -q " + QUEUE + " -J " + JobName + " '" + shell_path + " 0 ele'"
0216 os.system (batchSubmit)
0217
0218 print('\n')
0219 NJobs = Job_End - Job_Start
0220 print("\n\n")
0221 print("\t\t\t%i Jobs submitted by the LaunchOnFarm script" % NJobs)
0222 print("\t\t\t Created by Loic Quertenmont")
0223 print("\t\t\t Loic.quertenmont@cern.ch")
0224 print("\n\n")