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 = "MergeJob_cfg.py"
0009
0010
0011
0012
0013
0014 Output_RootFile = "MERGE"
0015
0016 Job_NEvents = 10000
0017 Job_Start = 0
0018 Job_End = 1
0019 Job_SEvents = 0
0020
0021
0022 FarmDirectory = "FARM_Merge"
0023 QUEUE = "cmscaf"
0024
0025
0026 def CreateTheConfigFile(PATH,CONFIG_FILE,NEVENTS,OUTPUTFILE,INDEX):
0027
0028 config_file=open(CONFIG_FILE,'r')
0029 config_txt = config_file.read()
0030 config_file.close()
0031 newconfig_path = PATH + "/"+FarmDirectory+"/InputFile/%04i_" % INDEX
0032 newconfig_path = newconfig_path + Output_RootFile + ".cfg"
0033
0034 mylogo1 = "# -----------------------------------------------\n"
0035 mylogo2 = "# | cfg modified by the LaunchOnFarm Script |\n"
0036 mylogo3 = "# | Created by Loic Quertenmont |\n"
0037 mylogo4 = "# | Loic.quertenmont@cern.ch |\n"
0038 mylogo5 = "# -----------------------------------------------\n\n\n\n"
0039 config_txt = mylogo1 + mylogo2 + mylogo3 + mylogo4 + mylogo5 + config_txt
0040
0041 i=0
0042 while i < len(config_txt) :
0043 if config_txt[i:i+15]=='XXX_NEVENTS_XXX':
0044 Skip = INDEX*NEVENTS+Job_SEvents
0045 MaxEvent = NEVENTS
0046 print("job #%d" %INDEX + "\t\tNumber of Events fixed to \t\t%d"%MaxEvent)
0047 newconfig_file=open(newconfig_path,'w')
0048 newconfig_file.write("%s" % config_txt[0:i])
0049 newconfig_file.write("%d" % MaxEvent)
0050 newconfig_file.write("%s" % config_txt[i+15:len(config_txt)])
0051 newconfig_file.close()
0052 newconfig_file=open(newconfig_path,'r')
0053 config_txt = newconfig_file.read()
0054 newconfig_file.close()
0055 i = 0
0056 if config_txt[i:i+14]=='XXX_OUTPUT_XXX':
0057 print("job #%d" %INDEX + "\tOutput file fixed to\t\t%s"%OUTPUTFILE)
0058 newconfig_file=open(newconfig_path,'w')
0059 newconfig_file.write("%s" % config_txt[0:i])
0060 newconfig_file.write("%s"% OUTPUTFILE)
0061 newconfig_file.write("_%04i.root" % INDEX)
0062 newconfig_file.write("%s" % config_txt[i+14:len(config_txt)])
0063 newconfig_file.close()
0064 newconfig_file=open(newconfig_path,'r')
0065 config_txt = newconfig_file.read()
0066 newconfig_file.close()
0067 i = 0
0068 if config_txt[i:i+17]=='XXX_SKIPEVENT_XXX':
0069 Skip = INDEX*NEVENTS+Job_SEvents
0070 print("job #%d" %INDEX + "\tNumber of Event to skip is fixed to\t\t%i"%Skip)
0071 newconfig_file=open(newconfig_path,'w')
0072 newconfig_file.write("%s" % config_txt[0:i])
0073 newconfig_file.write("%i"%Skip)
0074 newconfig_file.write("%s" % config_txt[i+17: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+9]=='XXX_I_XXX':
0081 newconfig_file=open(newconfig_path,'w')
0082 newconfig_file.write("%s" % config_txt[0:i])
0083 newconfig_file.write("%04i"%INDEX)
0084 newconfig_file.write("%s" % config_txt[i+9:len(config_txt)])
0085 newconfig_file.close()
0086 newconfig_file=open(newconfig_path,'r')
0087 config_txt = newconfig_file.read()
0088 newconfig_file.close()
0089 i = 0
0090
0091
0092 i = i+1
0093
0094 def CreateTheShellFile(PATH,INDEX):
0095 shell_path = "./"+FarmDirectory+"/InputFile/%04i_" % INDEX
0096 shell_path = shell_path + Output_RootFile + ".sh"
0097
0098 cfg_path = PATH + "/" + FarmDirectory + "/InputFile/%04i_" % INDEX
0099 cfg_path = cfg_path + Output_RootFile + ".cfg"
0100
0101 shell_file=open(shell_path,'w')
0102 shell_file.write("#! /bin/sh\n")
0103 shell_file.write("# ----------------------------------------------- \n")
0104 shell_file.write("# | Script created by the LaunchOnFarm Script |\n")
0105 shell_file.write("# | Created by Loic Quertenmont |\n")
0106 shell_file.write("# | Loic.quertenmont@cern.ch |\n")
0107 shell_file.write("# ----------------------------------------------- \n\n\n\n")
0108 shell_file.write("%s" % "cd " + PATH + "/" + FarmDirectory + "\n")
0109 shell_file.write("%s\n" % "eval `scramv1 runtime -sh`")
0110 shell_file.write("%s" % "cmsRun " + cfg_path +"\n")
0111 shell_file.close()
0112 chmod_path = "chmod 777 "+shell_path
0113 os.system(chmod_path)
0114
0115
0116 path = os.getcwd()
0117 os.system('mkdir '+FarmDirectory)
0118 os.system('mkdir '+FarmDirectory+'/RootFiles')
0119 os.system('mkdir '+FarmDirectory+'/Log')
0120 os.system('mkdir '+FarmDirectory+'/InputFile')
0121
0122 for i in range(Job_Start,Job_End):
0123 print('Submitting job number %d' %i)
0124
0125 CreateTheConfigFile(path,Input_ConfigFile,Job_NEvents,path+"/"+FarmDirectory+"/RootFiles/"+Output_RootFile,i)
0126 CreateTheShellFile(path,i)
0127
0128 condor_path = "./"+FarmDirectory+"/InputFile/%04i_" % i
0129 condor_path = condor_path + Output_RootFile + ".cmd"
0130
0131 shell_path = path + "/" + FarmDirectory + "/InputFile/%04i_" % i
0132 shell_path = shell_path + Output_RootFile + ".sh"
0133
0134 cdPath = "cd " + path
0135 cdFarm = "cd " + path + "/" + FarmDirectory
0136 os.system(cdFarm)
0137
0138 JobName = "'" + Output_RootFile + "%04i'" % i
0139
0140
0141 OutputPath = "'out/'"
0142
0143
0144
0145 batchSubmit = "bsub -q " + QUEUE + " -J " + JobName + " '" + shell_path + " 0 ele'"
0146 os.system (batchSubmit)
0147 os.system(cdPath)
0148
0149
0150 print('\n')
0151 NJobs = Job_End - Job_Start
0152 print("\n\n")
0153 print("\t\t\t%i Jobs submitted by the LaunchOnFarm script" % NJobs)
0154 print("\t\t\t Created by Loic Quertenmont")
0155 print("\t\t\t Loic.quertenmont@cern.ch")
0156 print("\n\n")