-
Notifications
You must be signed in to change notification settings - Fork 19
/
submitCondor
executable file
·115 lines (106 loc) · 3.78 KB
/
submitCondor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
import os, sys, time,glob,re
from optparse import OptionParser
class submitCondor :
path = None
input_list = []
title = None
pyCfg = None
jdl = None
def __init__(self) :
self.getVariable()
self.makeDirectory()
self.pwd = os.getcwd()
def makeDirectory(self) :
time_dir = time.strftime(self.path+"__%d%b%Y_%HH%MM/",time.localtime())
os.mkdir(time_dir)
os.system("cp %s %s"%(self.pyCfg, time_dir))
self.path = time_dir
os.chdir( time_dir)
self.makeCmdFiles( )
for idx, inputfile in enumerate(self.input_list) :
subdir = self.jobName+'_'+str(idx)
os.mkdir(subdir )
self.addCmdFiles( inputfile, self.jobName+"_"+str(idx)+".root")
self.writeCmdFiles()
def getVariable( self ) :
usage = """%prog [options] pyROOT_Script.py
egs)submitCondor -f filelist.txt -j ANA -o ntuple.root -n 5"""
parser = OptionParser(usage)
parser.add_option("-f","--txtfile",action="store",type="string",dest="textFile",metavar='filelist.txt',help="input files(.ROOT)'s list (text)")
parser.add_option("-n","--number",action="store",type="int",dest="num",metavar=1,help="# of files per job")
parser.add_option("-p","--path",action="store",type="string",default="ANA_ROOT",metavar='ANA_ROOT',dest="path",help="Path of outputs. (Default : ANA_ROOT)")
parser.add_option("-o","--outputh",action="store",type="string",default="ntuple.root",metavar='ntuple.root',dest="output",help="output file. (Default : ntuple.root)")
parser.add_option("-a","--argument",action="store",type="string",default=None,dest="argument",help="Argumnt for Input variables")
parser.add_option("-j","--jobName",action="store",type="string",default="ANA",metavar='ANA', dest="jobName",help="Job Name.(Default : ANA) ")
(options,args) = parser.parse_args()
self.path = options.path
self.jobName = options.jobName
self.pyCfg = args[0]
self.argument = options.argument
self.output= options.output
if ( options.textFile is not None) :
self.input_list = open( options.textFile).readlines()
else :
print "Did not input source"
def makeCmdFiles(self ) :
jdl = """
executable = %s
universe = vanilla
input =
getenv = True
should_transfer_files = YES
when_to_transfer_output = ON_EXIT
log = condor.log
"""%(self.pyCfg)
self.jdl = jdl
def addCmdFiles(self, input, output) :
flag = False
if ( self.argument == None) :
only_filename = input.split('/')[-1]
self.argument = "%s %s"%(only_filename.strip(),output )
flag = True
self.jdl += """
InitialDir = %s_$(Process)
arguments = %s
output = job_$(Process).log
error = job_$(Process).err
#transfer_input_files = %s
transfer_output_files = %s
queue
""" %(self.jobName, self.argument, input, output)
if flag :
self.argument = None
def writeCmdFiles( self) :
jdl_file = file( "run.jdl","w")
jdl_file.write( self.jdl )
jdl_file.close()
return
def Print(self) :
print self.path
print "# of files : %d"%(len(self.input_list))
print self.pyCfg
def Ana(self) :
pass
"""
def Ana(self) :
print "Ana"
for input in self.input_list :
idx = re.search(r'\d+',input)
if ( idx.group() is not None) :
n_idx = int(idx.group())
output = self.output_path+"/"+self.title+"_%03d.root"%(int(n_idx))
config = self.makeCmdFiles(n_idx,input,output )
tmp_sc = open(self.output_path+"/batch_%d"%n_idx+".cmd","w")
tmp_sc.write( config )
tmp_sc.write("python %s %s %s"%(self.pyCfg, input, output))
tmp_sc.close()
command = "qsub -q %s %s/batch_%d.cmd"%(self.queue,self.output_path,n_idx)
print command
os.system(command)
"""
if __name__ == "__main__" :
filename = sys.argv[1]
sb = submitCondor()
sb.Ana()
sb.Print()