CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
batchHippy.MyBatchManager Class Reference

Public Member Functions

def __init__
 
def checkLastIteration
 
def checkProxy
 
def finalize
 
def mkdir
 
def notify
 
def redirectProxy
 
def submitJobs
 

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

Member Function Documentation

def batchHippy.MyBatchManager.checkLastIteration (   self)

Definition at line 104 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.finalize().

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

Definition at line 162 of file batchHippy.py.

References print().

163  def checkProxy(self):
164  try:
165  subprocess.check_call(["voms-proxy-info", "--exists"])
166  except subprocess.CalledProcessError:
167  print("Please initialize your proxy before submitting.")
168  sys.exit(1)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def batchHippy.MyBatchManager.finalize (   self,
  ret 
)

Definition at line 114 of file batchHippy.py.

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

Referenced by batchHippy.MyBatchManager.submitJobs().

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

Definition at line 91 of file batchHippy.py.

References if(), and print().

Referenced by batchmanager.BatchManager.PrepareJob().

91 
92  def mkdir(self, dirname):
93  mkdir = 'mkdir -p %s' % dirname
94  ret = os.system( mkdir )
95  if( ret != 0 ):
96  print('Please remove or rename directory: ', dirname)
97  sys.exit(4)
if(conf_.getParameter< bool >("UseStripCablingDB"))
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def batchHippy.MyBatchManager.notify (   self,
  desc 
)

Definition at line 98 of file batchHippy.py.

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

Referenced by batchHippy.MyBatchManager.finalize().

98 
99  def notify(self, desc):
100  print(desc)
101  if self.opt.sendto is not None:
102  strcmd = "mail -s {1} {0} <<< \"{2}\"".format(self.opt.sendto, self.jobname, desc)
103  os.system(strcmd)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def batchHippy.MyBatchManager.redirectProxy (   self)

Definition at line 169 of file batchHippy.py.

References print(), and digitizers_cfi.strip.

170  def redirectProxy(self):
171  local_proxy = subprocess.check_output(["voms-proxy-info", "--path"]).strip()
172  new_proxy_path = os.path.join(self.opt.outputdir,".user_proxy")
173  print("Copying local proxy {} to the job directory as {}.".format(local_proxy,new_proxy_path))
174  shutil.copyfile(local_proxy, new_proxy_path)
175 
176 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def batchHippy.MyBatchManager.submitJobs (   self)

Definition at line 136 of file batchHippy.py.

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

137  def submitJobs(self):
138  jobcmd=""
139  if self.opt.resubmit:
140  jobcmd = 'scripts/reiterator_py {} {} {} {} {} {}'.format(
141  self.opt.niter,
142  self.opt.outputdir,
143  self.opt.iovfile
144  )
145  else:
146  if self.opt.dryRun > 0:
147  print('Dry run option is enabled. Will not submit jobs to the queue')
148  jobcmd = 'scripts/iterator_py {} {} {} {} {} {} {} {} {} {}'.format(
149  self.opt.niter,
150  self.opt.outputdir,
151  self.opt.lstfile,
152  self.opt.iovfile,
153  self.opt.commoncfg,
154  self.opt.aligncfg,
155  self.opt.trkselcfg,
156  self.SDflag,
157  self.redirectproxyflag,
158  self.opt.dryRun
159  )
160  ret = os.system( jobcmd )
161  self.finalize(ret)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Member Data Documentation

batchHippy.MyBatchManager.jobname

Definition at line 75 of file batchHippy.py.

Referenced by batchHippy.MyBatchManager.finalize(), and batchHippy.MyBatchManager.notify().

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().