File indexing completed on 2023-03-17 10:44:18
0001
0002
0003 from __future__ import print_function
0004 import urllib
0005 import string
0006 import os
0007 import sys
0008
0009
0010 Input_ConfigFile = "MergeJob_cfg.py"
0011
0012
0013
0014
0015
0016 JobName = "MERGE"
0017 Output_Path = "."
0018
0019 Job_NEvents = -1
0020 Job_Start = 0
0021 Job_End = 1
0022 Job_SEvents = 0
0023
0024 Job_Seed = 123456789
0025
0026
0027 FarmDirectory = "FARM_Merge"
0028 QUEUE = "cmscaf"
0029
0030
0031
0032 def CreateTheConfigFile(CONFIG_FILE,NEVENTS,OUTPUTFILE,INDEX):
0033
0034 config_file=open(CONFIG_FILE,'r')
0035 config_txt = config_file.read()
0036 config_file.close()
0037 newconfig_path = "./"+FarmDirectory+"/InputFile/%04i_" % INDEX
0038 newconfig_path = newconfig_path + JobName + "_cfg.py"
0039
0040 mylogo1 = "# -----------------------------------------------\n"
0041 mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
0042 mylogo3 = "# | Created by Loic Quertenmont |\n"
0043 mylogo4 = "# | Loic.quertenmont@cern.ch |\n"
0044 mylogo5 = "# -----------------------------------------------\n\n\n\n"
0045 config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt
0046
0047 newconfig_file=open(newconfig_path,'w')
0048 newconfig_file.write("%s" % config_txt)
0049 newconfig_file.close()
0050
0051
0052 i=0
0053 while i < len(config_txt) :
0054 if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
0055 Skip = INDEX*NEVENTS+Job_SEvents
0056 MaxEvent = NEVENTS
0057 print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
0058 newconfig_file=open(newconfig_path,'w')
0059 newconfig_file.write("%s" % config_txt[0:i])
0060 newconfig_file.write("%d" % MaxEvent)
0061 newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
0062 newconfig_file.close()
0063 newconfig_file=open(newconfig_path,'r')
0064 config_txt = newconfig_file.read()
0065 newconfig_file.close()
0066 i = 0
0067 if config_txt[i:i+12]=='XXX_SEED_XXX':
0068 Skip = INDEX*NEVENTS+Job_SEvents
0069 seed = Job_Seed + INDEX
0070 print("job #%d" %INDEX + "\t\tSeed fixed to \t\t%d"%seed)
0071 newconfig_file=open(newconfig_path,'w')
0072 newconfig_file.write("%s" % config_txt[0:i])
0073 newconfig_file.write("%d" % seed)
0074 newconfig_file.write("%s" % config_txt[i+12:len(config_txt)])
0075 newconfig_file.close()
0076 newconfig_file=open(newconfig_path,'r')
0077 config_txt = newconfig_file.read()
0078 newconfig_file.close()
0079 i = 0
0080 if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
0081 print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
0082 newconfig_file=open(newconfig_path,'w')
0083 newconfig_file.write("%s" % config_txt[0:i])
0084 newconfig_file.write("%s"% OUTPUTFILE)
0085 newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
0086 newconfig_file.close()
0087 newconfig_file=open(newconfig_path,'r')
0088 config_txt = newconfig_file.read()
0089 newconfig_file.close()
0090 i = 0
0091 if config_txt[i:i+17]=='XXX_SKIPEVENT_XXX':
0092 Skip = INDEX*NEVENTS+Job_SEvents
0093 print("job #%d" %INDEX + "\tNumber of Event to skip is fixed to\t\t%i"%Skip)
0094 newconfig_file=open(newconfig_path,'w')
0095 newconfig_file.write("%s" % config_txt[0:i])
0096 newconfig_file.write("%i"%Skip)
0097 newconfig_file.write("%s" % config_txt[i+17:len(config_txt)])
0098 newconfig_file.close()
0099 newconfig_file=open(newconfig_path,'r')
0100 config_txt = newconfig_file.read()
0101 newconfig_file.close()
0102 i = 0
0103 if config_txt[i:i+9]=='XXX_I_XXX':
0104 newconfig_file=open(newconfig_path,'w')
0105 newconfig_file.write("%s" % config_txt[0:i])
0106 newconfig_file.write("%04i"%INDEX)
0107 newconfig_file.write("%s" % config_txt[i+9:len(config_txt)])
0108 newconfig_file.close()
0109 newconfig_file=open(newconfig_path,'r')
0110 config_txt = newconfig_file.read()
0111 newconfig_file.close()
0112 i = 0
0113 if config_txt[i:i+12]=='XXX_PATH_XXX':
0114 newconfig_file=open(newconfig_path,'w')
0115 newconfig_file.write("%s" % config_txt[0:i])
0116 newconfig_file.write("%s" % path)
0117 newconfig_file.write("%s" % config_txt[i+12:len(config_txt)])
0118 newconfig_file.close()
0119 newconfig_file=open(newconfig_path,'r')
0120 config_txt = newconfig_file.read()
0121 newconfig_file.close()
0122 i = 0
0123
0124 i = i+1
0125
0126 def CreateTheShellFile(INITDIR,INDEX):
0127 shell_path = "./"+FarmDirectory+"/InputFile/%04i_" % INDEX
0128 shell_path = shell_path + JobName + ".sh"
0129
0130 cfg_path = INITDIR+"/"+FarmDirectory+"/InputFile/%04i_" % INDEX
0131 cfg_path = cfg_path + JobName + "_cfg.py"
0132
0133 TxtIndex = "%04i" % INDEX
0134
0135 shell_file=open(shell_path,'w')
0136 shell_file.write("#! /bin/sh\n")
0137 shell_file.write("# ----------------------------------------------- \n")
0138 shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
0139 shell_file.write("# | Created by Loic Quertenmont |\n")
0140 shell_file.write("# | Loic.quertenmont@cern.ch |\n")
0141 shell_file.write("# ----------------------------------------------- \n\n\n\n")
0142
0143
0144
0145
0146 shell_file.write("cd " + path + "\n")
0147 shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
0148 shell_file.write("%s\n" % "cd -")
0149 shell_file.write("%s" % "cmsRun " + cfg_path +"\n\n\n")
0150 shell_file.write("mv %s* " % JobName)
0151
0152 shell_file.write("%s/" % path)
0153 shell_file.write("%s/.\n" % Output_Path)
0154 shell_file.close()
0155 chmod_path = "chmod 777 "+shell_path
0156 os.system(chmod_path)
0157
0158
0159 path = os.getcwd()
0160 if os.path.isdir(FarmDirectory) == False:
0161 os.system('mkdir '+FarmDirectory)
0162 os.system('mkdir '+FarmDirectory+'/Outputs')
0163 os.system('mkdir '+FarmDirectory+'/Log')
0164 os.system('mkdir '+FarmDirectory+'/InputFile')
0165
0166 for i in range(Job_Start,Job_End):
0167 print('Submitting job number %d' %i)
0168
0169 CreateTheConfigFile(Input_ConfigFile,Job_NEvents,JobName,i)
0170 CreateTheShellFile(path,i)
0171
0172 condor_path = path + "/"+FarmDirectory+"/InputFile/%04i_" % i
0173 condor_path = condor_path + JobName + ".cmd"
0174
0175 shell_path = path + "/"+FarmDirectory + "/InputFile/%04i_" % i
0176 shell_path = shell_path + JobName + ".sh"
0177
0178 cdPath = "cd " + path
0179 cdFarm = "cd " + path + "/" + FarmDirectory
0180 os.system(cdFarm)
0181
0182 JobName = "'" + JobName + "%04i'" % i
0183 OutputPath = "'out/'"
0184 batchSubmit = "bsub -q " + QUEUE + " -J " + JobName + " '" + shell_path + " 0 ele'"
0185 os.system (batchSubmit)
0186
0187 print('\n')
0188 NJobs = Job_End - Job_Start
0189 print("\n\n")
0190 print("\t\t\t%i Jobs submitted by the LaunchOnFarm script" % NJobs)
0191 print("\t\t\t Created by Loic Quertenmont")
0192 print("\t\t\t Loic.quertenmont@cern.ch")
0193 print("\n\n")