#! /usr/bin/env python import os import random import sys # This script helps you to prepare and submit CMSSW # ALPGEN matching jobs to the SPRACE cluster. It submits # only ONE job per CONDOR cluster. # Get parameters from command line if len(sys.argv) != 2: # the program name and the taskname # stop the program and print an error message sys.exit("Usage: sprace_CMSSW_alpgmatch.py ") # Set parameters to the job ############################################### taskname = sys.argv[1] ptjmin = int(taskname.split("_")[1].split("G")[0]) dryrun = 0 ############################################### if dryrun != 0: print "*** DRY RUN ***" # Prepare working directory ################################################ pwd = os.getcwd() workingdir = pwd+"/"+taskname # Make a nice random seed ################################################ os.system("uuidgen > seedfile") seedfile = open("seedfile",'r') myseed = seedfile.readline() seedfile.close() os.system("\\rm seedfile") random.seed(myseed) # Prepare the job ################################################ # Prepare the input scripts rundir = workingdir submitname = rundir+"/match_"+taskname+".src" shellname = rundir+"/match_"+taskname+".sh" CMSSWconfigname = rundir+"/match_CMSSW_"+taskname+"_cfg.py" CMSSWskeletonname = "Alpgen_cfg.py" # The submit file submitfile = open(submitname,'w') submitfile.write("universe = vanilla\n") submitfile.write("executable = "+shellname+"\n") submitfile.write("initialdir = "+rundir+"\n") submitfile.write("output = "+rundir+"/STDOUT\n") submitfile.write("error = "+rundir+"/STDERR\n") submitfile.write("log = "+rundir+"/LOGFILE\n") submitfile.write("queue\n") submitfile.close() # The shell file shellfile = open(shellname,'w') shellfile.write("#!/bin/bash\n") shellfile.write("source /home/OSG_app/app/cmssoft/cms/cmsset_default.sh\n") shellfile.write("cd "+rundir+"\n") shellfile.write("eval `scramv1 runtime -sh`\n") shellfile.write("cmsRun "+CMSSWconfigname+"\n") shellfile.close() # The CMSSW config file CMSSWskeleton = open(CMSSWskeletonname,'r') CMSSWconfig = open(CMSSWconfigname,'w') for line in CMSSWskeleton: if line.find("$CONDORSEED")!=-1: newline = line.replace("$CONDORSEED",str(random.randint(100000,999999))) CMSSWconfig.write(newline) elif line.find("$CONDORINPUT")!=-1: newline = line.replace("$CONDORINPUT",'"'+taskname+'"') CMSSWconfig.write(newline) elif line.find("$CONDOROUTPUT")!=-1: newline = line.replace("$CONDOROUTPUT",'"'+taskname+'"') CMSSWconfig.write(newline) elif line.find("$CONDORETCLUS")!=-1: newline = line.replace("$CONDORETCLUS",'"'+str(1.2*ptjmin)+'"') CMSSWconfig.write(newline) else: CMSSWconfig.write(line) continue CMSSWconfig.close() CMSSWskeleton.close() if dryrun != 0: os.system("echo condor_submit "+submitname) else: os.system("echo condor_submit "+submitname) os.system("chmod +x "+shellname) os.system("condor_submit "+submitname)