#! /usr/bin/env python import os import random import sys # This script helps you to prepare and submit CMSSW # MC generation jobs to the SPRACE cluster. It submits # only ONE job per CONDOR cluster. # Get parameters from command line if len(sys.argv) != 5: # the program name and the config file # stop the program and print an error message sys.exit("Usage: sprace_ALPGEN_submit.py ") # Set parameters to the job ############################################### configargname = sys.argv[1] executableargname = sys.argv[2] gridargname = sys.argv[3] dryrun = 0 ############################################### if dryrun != 0: print "*** DRY RUN *** (change to dryrun = 0 to really run)" # Getting the label ################################################ f = open(configargname,'r') f.readline() secondline = f.readline() f.close() label = secondline.split()[0] taskname = label # Prepare working directory ################################################ pwd = os.getcwd() workingdir = pwd+"/"+taskname+"_dir" workingdir = workingdir+"_"+str(sys.argv[4]) if not os.path.exists(workingdir): os.mkdir(workingdir) # 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) # Generate the task. ################################################ # Prepare the input scripts rundir = workingdir submitname = rundir+"/"+taskname+".src" shellname = rundir+"/"+taskname+".sh" configname = rundir+"/"+taskname+".input" gridname = rundir+"/"+taskname+".grid2" # Prepare the executable executablename = rundir+"/"+taskname+"_exe" # 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(executablename+" < "+configname+"\n") shellfile.close() # Copy the executable to the right place os.system("cp "+executableargname+" "+executablename) # The Alpgen grid file os.system("cp "+gridargname+" "+gridname) # Fix random seeds in the Alpgen config file. oldconfigfile = open(configargname,"r") newconfigfile = open(configname, "w") for line in oldconfigfile: if line.find("iseed1") >= 0: newline = "iseed1 "+str(random.randint(10000,99999))+"\n" elif line.find("iseed2") >= 0: newline = "iseed2 "+str(random.randint(10000,99999))+"\n" elif line.find("iseed3") >= 0: newline = "iseed3 "+str(random.randint(10000,99999))+"\n" elif line.find("iseed4") >= 0: newline = "iseed4 "+str(random.randint(10000,99999))+"\n" else: newline = line newconfigfile.write(newline) continue # Create and submit the task. ################################################ 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)