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 17 of file batchHippy.py.

Constructor & Destructor Documentation

def batchHippy.MyBatchManager.__init__ (   self)

Definition at line 20 of file batchHippy.py.

20  def __init__(self):
21  # define options and arguments ====================================
22  self.parser = OptionParser()
23  self.parser.add_option("-o", "--outdir", dest="outputdir", type="string",
24  help="Name of the local output directory for your jobs. This directory will be created automatically.",
25  default="./")
26  self.parser.add_option("--commoncfg", dest="commoncfg", type="string",
27  help="Name of the common config file.",
28  default="python/common_cff_py.txt")
29  self.parser.add_option("--aligncfg", dest="aligncfg", type="string",
30  help="Name of the align. config file.",
31  default="python/align_tpl_py.txt")
32  self.parser.add_option("--niter", dest="niter", type="int",
33  help="Number of iterations",
34  default="15")
35  self.parser.add_option("--lst", "--listfile", "--lstfile", dest="lstfile", type="string",
36  help="lst file to read",
37  default=None)
38  self.parser.add_option("--iovs", "--iovfile", dest="iovfile", type="string",
39  help="IOV list to read",
40  default=None)
41  self.parser.add_option("--trkselcfg", "--trackselectionconfig", dest="trkselcfg", type="string",
42  help="Track selection config location",
43  default="python")
44  self.parser.add_option("--notify", "--sendto", dest="sendto", type="string",
45  help="Email addresses (comma-separated) to notify when job is complete.",
46  default=None)
47  self.parser.add_option("--deform", action="store_true",
48  dest="useSD", default=False,
49  help="Include surface deformations in alignment")
50  self.parser.add_option("-f", "--force", action="store_true",
51  dest="force", default=False,
52  help="Don't ask any questions, just over-write")
53  self.parser.add_option("--resubmit", action="store_true",
54  dest="resubmit", default=False,
55  help="Resubmit a job from the last iteration")
56  self.parser.add_option("--redirectproxy", action="store_true",
57  dest="redirectproxy", default=False,
58  help="Redirect the proxy to a path visible in batch")
59  self.parser.add_option("--dry", dest="dryRun", type="int",
60  default=0,
61  help="Do not submit jobs, just set up the cfg files")
62  (self.opt,self.args) = self.parser.parse_args()
63 
64  self.checkProxy() # Check if Grid proxy initialized
65 
66  self.mkdir(self.opt.outputdir)
67 
68  if self.opt.lstfile is None:
69  print("Unspecified lst file.")
70  sys.exit(1)
71  if self.opt.iovfile is None:
72  print("Unspecified IOV list.")
73  sys.exit(1)
74 
75  self.jobname = self.opt.outputdir.split('/')[-1]
76 
77  if self.opt.redirectproxy:
78  print("Job {} is configured to redirect its Grid proxy.".format(self.jobname))
79  self.redirectProxy()
80 
81  if self.opt.sendto is not None:
82  self.opt.sendto.strip()
83  self.opt.sendto.replace(","," ")
84  print("Job {} is configured to notify {}.".format(self.jobname, self.opt.sendto))
85 
86  # Set numerical flags for iterator_py
87  self.SDflag = 1 if self.opt.useSD else 0
88  self.redirectproxyflag = 1 if self.opt.redirectproxy else 0
89 
90 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def mkdir(self, dirname)
Definition: batchHippy.py:91

Member Function Documentation

def batchHippy.MyBatchManager.checkLastIteration (   self)

Definition at line 104 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.finalize().

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

Definition at line 162 of file batchHippy.py.

References edm.print().

162  def checkProxy(self):
163  try:
164  subprocess.check_call(["voms-proxy-info", "--exists"])
165  except subprocess.CalledProcessError:
166  print("Please initialize your proxy before submitting.")
167  sys.exit(1)
168 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def batchHippy.MyBatchManager.finalize (   self,
  ret 
)

Definition at line 114 of file batchHippy.py.

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

Referenced by batchHippy.MyBatchManager.submitJobs().

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

Definition at line 91 of file batchHippy.py.

References edm.print().

Referenced by batchmanager.BatchManager.PrepareJob().

91  def mkdir(self, dirname):
92  mkdir = 'mkdir -p %s' % dirname
93  ret = os.system( mkdir )
94  if( ret != 0 ):
95  print('Please remove or rename directory: ', dirname)
96  sys.exit(4)
97 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def mkdir(self, dirname)
Definition: batchHippy.py:91
def batchHippy.MyBatchManager.notify (   self,
  desc 
)

Definition at line 98 of file batchHippy.py.

References batchHippy.MyBatchManager.jobname, and edm.print().

Referenced by batchHippy.MyBatchManager.finalize().

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

Definition at line 169 of file batchHippy.py.

References edm.print(), and digitizers_cfi.strip.

169  def redirectProxy(self):
170  local_proxy = subprocess.check_output(["voms-proxy-info", "--path"]).strip()
171  new_proxy_path = os.path.join(self.opt.outputdir,".user_proxy")
172  print("Copying local proxy {} to the job directory as {}.".format(local_proxy,new_proxy_path))
173  shutil.copyfile(local_proxy, new_proxy_path)
174 
175 
176 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def batchHippy.MyBatchManager.submitJobs (   self)

Definition at line 136 of file batchHippy.py.

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

136  def submitJobs(self):
137  jobcmd=""
138  if self.opt.resubmit:
139  jobcmd = 'scripts/reiterator_py {} {} {} {} {} {}'.format(
140  self.opt.niter,
141  self.opt.outputdir,
142  self.opt.iovfile
143  )
144  else:
145  if self.opt.dryRun > 0:
146  print('Dry run option is enabled. Will not submit jobs to the queue')
147  jobcmd = 'scripts/iterator_py {} {} {} {} {} {} {} {} {} {}'.format(
148  self.opt.niter,
149  self.opt.outputdir,
150  self.opt.lstfile,
151  self.opt.iovfile,
152  self.opt.commoncfg,
153  self.opt.aligncfg,
154  self.opt.trkselcfg,
155  self.SDflag,
156  self.redirectproxyflag,
157  self.opt.dryRun
158  )
159  ret = os.system( jobcmd )
160  self.finalize(ret)
161 
def finalize(self, ret)
Definition: batchHippy.py:114
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65

Member Data Documentation

batchHippy.MyBatchManager.jobname
batchHippy.MyBatchManager.parser

Definition at line 22 of file batchHippy.py.

batchHippy.MyBatchManager.redirectproxyflag

Definition at line 88 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.submitJobs().

batchHippy.MyBatchManager.SDflag

Definition at line 87 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.submitJobs().