12 from datetime
import date
13 from optparse
import OptionParser
17 '''Batch manager specific to cmsRun processes.''' 22 self.parser.add_option(
"-o",
"--outdir", dest=
"outputdir", type=
"string",
23 help=
"Name of the local output directory for your jobs. This directory will be created automatically.",
25 self.parser.add_option(
"--commoncfg", dest=
"commoncfg", type=
"string",
26 help=
"Name of the common config file.",
27 default=
"python/common_cff_py.txt")
28 self.parser.add_option(
"--aligncfg", dest=
"aligncfg", type=
"string",
29 help=
"Name of the align. config file.",
30 default=
"python/align_tpl_py.txt")
31 self.parser.add_option(
"--niter", dest=
"niter", type=
"int",
32 help=
"Number of iterations",
34 self.parser.add_option(
"--lst",
"--listfile",
"--lstfile", dest=
"lstfile", type=
"string",
35 help=
"lst file to read",
37 self.parser.add_option(
"--iovs",
"--iovfile", dest=
"iovfile", type=
"string",
38 help=
"IOV list to read",
40 self.parser.add_option(
"--trkselcfg",
"--trackselectionconfig", dest=
"trkselcfg", type=
"string",
41 help=
"Track selection config location",
43 self.parser.add_option(
"--notify",
"--sendto", dest=
"sendto", type=
"string",
44 help=
"Email addresses (comma-separated) to notify when job is complete.",
46 self.parser.add_option(
"--deform", action=
"store_true",
47 dest=
"useSD", default=
False,
48 help=
"Include surface deformations in alignment")
49 self.parser.add_option(
"-f",
"--force", action=
"store_true",
50 dest=
"force", default=
False,
51 help=
"Don't ask any questions, just over-write")
52 self.parser.add_option(
"--resubmit", action=
"store_true",
53 dest=
"resubmit", default=
False,
54 help=
"Resubmit a job from the last iteration")
55 self.parser.add_option(
"--redirectproxy", action=
"store_true",
56 dest=
"redirectproxy", default=
False,
57 help=
"Redirect the proxy to a path visible in batch")
58 self.parser.add_option(
"--dry", dest=
"dryRun", type=
"int",
60 help=
"Do not submit jobs, just set up the cfg files")
61 (self.opt,self.args) = self.parser.parse_args()
65 self.
mkdir(self.opt.outputdir)
67 if self.opt.lstfile
is None:
68 print "Unspecified lst file." 70 if self.opt.iovfile
is None:
71 print "Unspecified IOV list." 74 self.
jobname = self.opt.outputdir.split(
'/')[-1]
76 if self.opt.redirectproxy:
77 print "Job {} is configured to redirect its Grid proxy.".
format(self.
jobname)
80 if self.opt.sendto
is not None:
81 self.opt.sendto.strip()
82 self.opt.sendto.replace(
",",
" ")
83 print "Job {} is configured to notify {}.".
format(self.
jobname, self.opt.sendto)
86 self.
SDflag = 1
if self.opt.useSD
else 0
91 mkdir =
'mkdir -p %s' % dirname
92 ret = os.system( mkdir )
94 print 'Please remove or rename directory: ', dirname
99 if self.opt.sendto
is not None:
100 strcmd =
"mail -s {1} {0} <<< \"{2}\"".
format(self.opt.sendto, self.
jobname, desc)
104 lastIter=self.opt.niter
105 doesExist=os.system(
"test -s {}/alignments_iter{}.db".
format(self.opt.outputdir, lastIter))
106 while (doesExist != 0):
110 doesExist=os.system(
"test -s {}/alignments_iter{}.db".
format(self.opt.outputdir, lastIter))
117 strresult =
"Jobs cannot be submitted for {}. Exiting...".
format(self.
jobname)
119 elif self.opt.dryRun > 0:
120 strresult =
"Dry run setup is complete for {}.".
format(self.
jobname)
123 if lastIter == self.opt.niter:
124 strresult =
"The final iteration {}/alignments_iter{}.db is recorded successfully.".
format(self.
jobname, lastIter)
126 strresult =
"The last successful iteration was {}/alignments_iter{}.db out of the {} requested iterations.".
format(self.
jobname, lastIter, self.opt.niter)
129 strresult =
"None of the {} iterations were successful in job {}.".
format(self.opt.niter, self.
jobname)
137 if self.opt.resubmit:
138 jobcmd =
'scripts/reiterator_py {} {} {} {} {} {}'.
format(
144 if self.opt.dryRun > 0:
145 print 'Dry run option is enabled. Will not submit jobs to the queue' 146 jobcmd =
'scripts/iterator_py {} {} {} {} {} {} {} {} {} {}'.
format(
158 ret = os.system( jobcmd )
163 subprocess.check_call([
"voms-proxy-info",
"--exists"])
164 except subprocess.CalledProcessError:
165 print "Please initialize your proxy before submitting." 169 local_proxy = subprocess.check_output([
"voms-proxy-info",
"--path"]).
strip()
170 new_proxy_path = os.path.join(self.opt.outputdir,
".user_proxy")
171 print "Copying local proxy {} to the job directory as {}.".
format(local_proxy,new_proxy_path)
172 shutil.copyfile(local_proxy, new_proxy_path)
176 if __name__ ==
'__main__':
178 batchManager.submitJobs()
def checkLastIteration(self)