#!/usr/bin/env python import sys import os import commands import string import glob import time #################### start MC run #################################### # # arguments: 1=run type (D,DSR,DSRA) # 2:=run log files # the program will loog for a corresponding mc_runjob script for each # run logfile. The script name is of the form LOGFILE.script, where # the LOGFILE is the run logfile name ################### Before we begin, let us define utility routine ### # decode the input cards: # open FileName, find line which starts with Card string, split the line # according to Separator, return the value of Card parameter or empty string # if nothing was found def get_card(FileName,Card,Separator): CardValue="" File=open(FileName,"r") for line in File.readlines(): if string.find(line,Card)==0: if Separator==" ": CardValue=string.strip(string.split(line)[1]) else: CardValue=string.strip(string.split(line,Separator)[1]) return CardValue # delete from file FileName all lines which contain keyword card def delete_lines(FileName,Card): (statut,FileContent)=commands.getstatusoutput("cat "+FileName) File=open(FileName,"w") for line in string.split(FileContent,"\n"): if string.find(line,Card)!=-1: File.write(line+"\n") File.close() ####################################################################### ########## End of utility routines, now the real stuff ############## # check if the run type makes sense: RunType=sys.argv[1] if RunType!="D" and RunType!="DSR" and RunType!="DSRA": print "unknown run type: "+RunType print "valid types are :D,DSR,DSRA" sys.exit(0) print "WARNING! This is a slow script, I suggest you go for coffee..." for LogFileName in sys.argv[2:]: print "Submitting run :",LogFileName ScriptFileName=LogFileName+".script" if not os.path.exists(ScriptFileName): print "script file "+ScriptFileName+" not found!" sys.exit(0) else: # prepare the script file, ie throw away mc_runjob cards which are not related # to requested run type if RunType=="D": delete_lines(ScriptFileName,"d0sim") delete_lines(ScriptFileName,"d0reco") delete_lines(ScriptFileName,"recoanalyze") if RunType=="DSR": delete_lines(ScriptFileName,"recoanalyze") # if RunType=="DSRA": # # do nothing # Set default number of events/job NumberOfEventsPerJob=500 Nevt =get_card(LogFileName,"NEVT"," ") Nbgnd =get_card(LogFileName,"NBGND", " ") GeneratorFileName = get_card(LogFileName,"Output",":") print "Nevt=",Nevt print "Nbgnd=",Nbgnd print "generatorfile=",GeneratorFileName if Nevt=="" or Nbgnd=="" or GeneratorFileName=="": print "NEVT or NBGND or generator file cards not found!" sys.exit(0) else: NumberOfJobs=string.atoi(Nevt)/NumberOfEventsPerJob print "NumberOfJobs=",NumberOfJobs LogFile=open(LogFileName,"a") LogFile.write(RunType+" run started at "+time.ctime(time.time())+"\n") LogFile.close() for job in range(0,NumberOfJobs): print "submitting job=",job, NumberOfJobs-job,"left" Nskip=str(job*NumberOfEventsPerJob) # prepare the reg_job command with correct parameters Command="reg_job "+ScriptFileName+" " Command=Command+"--skip_events="+Nskip+" " Command=Command+"--num_events="+str(NumberOfEventsPerJob)+" " Command=Command+"--iteration="+str(job+1)+" " Command=Command+"--input="+GeneratorFileName+" " Command=Command+"--chase_input=yes --delete_input=yes " if RunType=="D": Command=Command+"--d0gstar_disposition=cache " if RunType=="DSR": Command=Command+"--d0gstar_disposition=metadata " Command=Command+"--d0sim_disposition=metadata " Command=Command+"--d0reco_disposition=sam " Command=Command+"--d0sim_minbi_method=poisson " Command=Command+"--d0sim_minbi_percent=1 " Command=Command+"--d0sim_minbi_input_list=$FARM_MINBI_FILELIST " Command=Command+"--d0sim_minbi_average_events="+Nbgnd+" " if RunType=="DSRA": Command=Command+"--d0gstar_disposition=metadata " Command=Command+"--d0sim_disposition=metadata " Command=Command+"--d0reco_disposition=sam " Command=Command+"--recoa_disposition=sam " Command=Command+"--d0sim_minbi_method=poisson " Command=Command+"--d0sim_minbi_percent=1 " Command=Command+"--d0sim_minbi_input_list=$FARM_MINBI_FILELIST " Command=Command+"--d0sim_minbi_average_events="+Nbgnd (status,SubmitOutput)=commands.getstatusoutput(Command) # analyze the submit output for line in string.split(SubmitOutput,"\n"): if string.find(line,"Registered")!=-1 and string.find(line,":")!=-1: jobName=string.strip(string.split(line,":")[1]) LogFile=open(LogFileName,"a") LogFile.write(jobName+" "+str(job+1)+" submitted\n") LogFile.close() LogFile=open(LogFileName,"a") LogFile.write(RunType+" submission ended "+time.ctime(time.time())) LogFile.close() print "DONE!!!"