Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:44:17

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