CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
batchHippy.MyBatchManager Class Reference

Public Member Functions

def __init__ (self)
 
def checkLastIteration (self)
 
def checkProxy (self)
 
def finalize (self, ret)
 
def mkdir (self, dirname)
 
def notify (self, desc)
 
def redirectProxy (self)
 
def submitJobs (self)
 

Public Attributes

 jobname
 
 parser
 
 redirectproxyflag
 
 SDflag
 

Detailed Description

Batch manager specific to cmsRun processes.

Definition at line 16 of file batchHippy.py.

Constructor & Destructor Documentation

def batchHippy.MyBatchManager.__init__ (   self)

Definition at line 19 of file batchHippy.py.

19  def __init__(self):
20  # define options and arguments ====================================
21  self.parser = OptionParser()
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.",
24  default="./")
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",
33  default="15")
34  self.parser.add_option("--lst", "--listfile", "--lstfile", dest="lstfile", type="string",
35  help="lst file to read",
36  default=None)
37  self.parser.add_option("--iovs", "--iovfile", dest="iovfile", type="string",
38  help="IOV list to read",
39  default=None)
40  self.parser.add_option("--trkselcfg", "--trackselectionconfig", dest="trkselcfg", type="string",
41  help="Track selection config location",
42  default="python")
43  self.parser.add_option("--notify", "--sendto", dest="sendto", type="string",
44  help="Email addresses (comma-separated) to notify when job is complete.",
45  default=None)
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",
59  default=0,
60  help="Do not submit jobs, just set up the cfg files")
61  (self.opt,self.args) = self.parser.parse_args()
62 
63  self.checkProxy() # Check if Grid proxy initialized
64 
65  self.mkdir(self.opt.outputdir)
66 
67  if self.opt.lstfile is None:
68  print "Unspecified lst file."
69  sys.exit(1)
70  if self.opt.iovfile is None:
71  print "Unspecified IOV list."
72  sys.exit(1)
73 
74  self.jobname = self.opt.outputdir.split('/')[-1]
75 
76  if self.opt.redirectproxy:
77  print "Job {} is configured to redirect its Grid proxy.".format(self.jobname)
78  self.redirectProxy()
79 
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)
84 
85  # Set numerical flags for iterator_py
86  self.SDflag = 1 if self.opt.useSD else 0
87  self.redirectproxyflag = 1 if self.opt.redirectproxy else 0
88 
89 
def mkdir(self, dirname)
Definition: batchHippy.py:90

Member Function Documentation

def batchHippy.MyBatchManager.checkLastIteration (   self)

Definition at line 103 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.finalize().

104  lastIter=self.opt.niter
105  doesExist=os.system("test -s {}/alignments_iter{}.db".format(self.opt.outputdir, lastIter))
106  while (doesExist != 0):
107  lastIter -= 1
108  if lastIter < 0:
109  break
110  doesExist=os.system("test -s {}/alignments_iter{}.db".format(self.opt.outputdir, lastIter))
111  return lastIter
112 
def batchHippy.MyBatchManager.checkProxy (   self)

Definition at line 161 of file batchHippy.py.

161  def checkProxy(self):
162  try:
163  subprocess.check_call(["voms-proxy-info", "--exists"])
164  except subprocess.CalledProcessError:
165  print "Please initialize your proxy before submitting."
166  sys.exit(1)
167 
def batchHippy.MyBatchManager.finalize (   self,
  ret 
)

Definition at line 113 of file batchHippy.py.

References batchHippy.MyBatchManager.checkLastIteration(), reco.if(), batchHippy.MyBatchManager.jobname, and batchHippy.MyBatchManager.notify().

Referenced by batchHippy.MyBatchManager.submitJobs().

113  def finalize(self, ret):
114  strresult=""
115  exitCode=0
116  if( ret != 0 ):
117  strresult = "Jobs cannot be submitted for {}. Exiting...".format(self.jobname)
118  exitCode=1
119  elif self.opt.dryRun > 0:
120  strresult = "Dry run setup is complete for {}.".format(self.jobname)
121  else:
122  lastIter=self.checkLastIteration()
123  if lastIter == self.opt.niter:
124  strresult = "The final iteration {}/alignments_iter{}.db is recorded successfully.".format(self.jobname, lastIter)
125  elif lastIter>0:
126  strresult = "The last successful iteration was {}/alignments_iter{}.db out of the {} requested iterations.".format(self.jobname, lastIter, self.opt.niter)
127  exitCode=1
128  else:
129  strresult = "None of the {} iterations were successful in job {}.".format(self.opt.niter, self.jobname)
130  exitCode=1
131  self.notify(strresult)
132  if exitCode!=0:
133  sys.exit(strresult)
134 
def finalize(self, ret)
Definition: batchHippy.py:113
def notify(self, desc)
Definition: batchHippy.py:97
if(dp >Float(M_PI)) dp-
def batchHippy.MyBatchManager.mkdir (   self,
  dirname 
)

Definition at line 90 of file batchHippy.py.

References reco.if().

Referenced by batchmanager.BatchManager.PrepareJob().

90  def mkdir(self, dirname):
91  mkdir = 'mkdir -p %s' % dirname
92  ret = os.system( mkdir )
93  if( ret != 0 ):
94  print 'Please remove or rename directory: ', dirname
95  sys.exit(4)
96 
if(dp >Float(M_PI)) dp-
def mkdir(self, dirname)
Definition: batchHippy.py:90
def batchHippy.MyBatchManager.notify (   self,
  desc 
)

Definition at line 97 of file batchHippy.py.

References batchHippy.MyBatchManager.jobname.

Referenced by batchHippy.MyBatchManager.finalize().

97  def notify(self, desc):
98  print desc
99  if self.opt.sendto is not None:
100  strcmd = "mail -s {1} {0} <<< \"{2}\"".format(self.opt.sendto, self.jobname, desc)
101  os.system(strcmd)
102 
def notify(self, desc)
Definition: batchHippy.py:97
def batchHippy.MyBatchManager.redirectProxy (   self)

Definition at line 168 of file batchHippy.py.

References digitizers_cfi.strip.

168  def redirectProxy(self):
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)
173 
174 
175 
def batchHippy.MyBatchManager.submitJobs (   self)

Definition at line 135 of file batchHippy.py.

References batchHippy.MyBatchManager.finalize(), batchHippy.MyBatchManager.redirectproxyflag, and batchHippy.MyBatchManager.SDflag.

135  def submitJobs(self):
136  jobcmd=""
137  if self.opt.resubmit:
138  jobcmd = 'scripts/reiterator_py {} {} {} {} {} {}'.format(
139  self.opt.niter,
140  self.opt.outputdir,
141  self.opt.iovfile
142  )
143  else:
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(
147  self.opt.niter,
148  self.opt.outputdir,
149  self.opt.lstfile,
150  self.opt.iovfile,
151  self.opt.commoncfg,
152  self.opt.aligncfg,
153  self.opt.trkselcfg,
154  self.SDflag,
155  self.redirectproxyflag,
156  self.opt.dryRun
157  )
158  ret = os.system( jobcmd )
159  self.finalize(ret)
160 
def finalize(self, ret)
Definition: batchHippy.py:113

Member Data Documentation

batchHippy.MyBatchManager.jobname
batchHippy.MyBatchManager.parser

Definition at line 21 of file batchHippy.py.

batchHippy.MyBatchManager.redirectproxyflag

Definition at line 87 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.submitJobs().

batchHippy.MyBatchManager.SDflag

Definition at line 86 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.submitJobs().