Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:10

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