#! /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) != 4: # 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" 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 config file os.system("cp "+configargname+" "+configname) # The Alpgen grid file os.system("cp "+gridargname+" "+gridname) # 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)