CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions
personalPlayback.FrameworkJob Class Reference
Inheritance diagram for personalPlayback.FrameworkJob:
personalPlayback.Applet

Public Member Functions

def discover_latest (self)
 
def do_exec (self)
 
def do_init (self)
 
def make_args (self, run)
 
def start_run (self, current)
 
- Public Member Functions inherited from personalPlayback.Applet
def __init__ (self, name, opts, kwargs)
 
def do_exec (self)
 
def do_init (self)
 
def log (self)
 
def write (self, fp)
 

Public Attributes

 cfg_file
 
 cfg_fp
 
 cfg_link
 
 cmsenv_path
 
 current_state
 
 exec_file
 
 home_path
 
 log_path
 
 name
 
 output_path
 
 ramdisk
 
 ramdisk_fp
 
 run
 
 tag
 
- Public Attributes inherited from personalPlayback.Applet
 control_fp
 
 kwargs
 
 name
 
 opts
 

Private Member Functions

def _find_release (self)
 
def _prepare_files (self)
 
def _set_name (self)
 

Additional Inherited Members

- Static Public Member Functions inherited from personalPlayback.Applet
def read (fp)
 

Detailed Description

Definition at line 245 of file personalPlayback.py.

Member Function Documentation

def personalPlayback.FrameworkJob._find_release (   self)
private

Definition at line 258 of file personalPlayback.py.

References personalPlayback.FrameworkJob.cfg_file.

258  def _find_release(self):
259  fp = os.path.realpath(self.cfg_file)
260  while len(fp) > 3:
261  bn = os.path.basename(fp)
262  fp = os.path.dirname(fp)
263 
264  if bn == "src":
265  break
266 
267  if len(fp) <= 3:
268  raise Exception("Could not find the cmssw release area.")
269 
270  self.cmsenv_path = fp
271  self.log.info("cmsenv path: %s", self.cmsenv_path)
272 
def personalPlayback.FrameworkJob._prepare_files (   self)
private

Definition at line 273 of file personalPlayback.py.

273  def _prepare_files(self):
274  self.home_path = os.path.join(self.opts.work_home, "%s_%s" % (self.name, hex(id(self))))
275  self.home_path = os.path.realpath(self.home_path)
276  os.makedirs(self.home_path)
277 
278  self.log_path = self.opts.work_logs
279  self.log.info("logs path: %s", self.log_path)
280 
281  self.exec_file = os.path.join(self.home_path, "startDqmRun.sh")
282  self.log.info("Creating: %s", self.exec_file)
283  f = open(self.exec_file, "w")
284  template = start_dqm_job
285  body = template.format(log_path=self.log_path, cmsRun=self.opts.cmsRun)
286  f.write(body)
287  f.close()
288  os.chmod(self.exec_file, 0o755)
289 
290  cmsset_globs = ["/afs/cern.ch/cms/cmsset_default.sh", "/home/dqm*local/base/cmsset_default.sh"]
291  cmsset_target = None
292  for t in cmsset_globs:
293  files = glob.glob(t)
294  for f in files:
295  cmsset_target = f
296  break
297 
298  if cmsset_target is not None:
299  base = os.path.join(self.home_path, "base")
300  os.makedirs(base)
301 
302  cmsset_link = os.path.join(base, "cmsset_default.sh")
303  self.log.info("Linking : %s -> %s", cmsset_link, cmsset_target)
304  os.symlink(cmsset_target, cmsset_link)
305  else:
306  self.log.warning("Couldn't find cmsset_default.sh, source it yourself!")
307 
308  current_link = os.path.join(self.home_path, "current")
309  target = os.path.relpath(self.cmsenv_path, self.home_path)
310  self.log.info("Linking : %s -> %s", current_link, target)
311  os.symlink(target, current_link)
312 
313  # check if current is outside the release directory
314  # otherwise scram gets stuck forever
315  cp = os.path.commonprefix([self.home_path, self.cmsenv_path])
316  if self.cmsenv_path == cp:
317  self.log.error("Working directory (incl. control directory), have to be outside the cmssw release. Otherwise scram fails due to recursive links.")
318  raise Exception("Invalid home_path: %s" % self.home_path)
319 
320  output_link = os.path.join(self.home_path, "output")
321  output_target = os.path.realpath(self.opts.work_output)
322  target = os.path.relpath(output_target, self.home_path)
323  self.log.info("Linking : %s -> %s", output_link, target)
324  os.symlink(target, output_link)
325  self.output_path = output_link
326 
327  cfg_link = os.path.join(self.home_path, os.path.basename(self.cfg_file))
328  target = self.cfg_fp
329  self.log.info("Linking : %s -> %s", cfg_link, target)
330  os.symlink(target, cfg_link)
331  self.cfg_link = cfg_link
332 
333 
def personalPlayback.FrameworkJob._set_name (   self)
private

Definition at line 246 of file personalPlayback.py.

References personalPlayback.FrameworkJob.cfg_file, and join().

246  def _set_name(self):
247  x = os.path.basename(self.cfg_file)
248  x = re.sub(r'(.*)\.py', r'\1', x)
249  x = re.sub(r'(.*)_cfg', r'\1', x)
250  x = re.sub(r'(.*)-live', r'\1', x)
251  x = re.sub(r'(.*)_sourceclient', r'\1', x)
252  x = re.sub(r'(.*)_dqm', r'\1', x)
253 
254  x = "".join([c for c in x if c.isalnum()])
255  self.tag = x
256  self.name = "cmssw_%s" % x
257 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def personalPlayback.FrameworkJob.discover_latest (   self)

Definition at line 364 of file personalPlayback.py.

References createfilelist.int, SiStripPI.max, personalPlayback.Playback.ramdisk, and personalPlayback.FrameworkJob.ramdisk.

Referenced by personalPlayback.FrameworkJob.do_exec().

364  def discover_latest(self):
365  re_run = re.compile(r'run([0-9]+)')
366  re_global = re.compile(r'\.run([0-9]+)\.global')
367 
368  # find runs
369  runs = {}
370  globals = {}
371  for x in os.listdir(self.ramdisk):
372  m = re_run.match(x)
373  if m:
374  runs[int(m.group(1))] = x
375 
376  m = re_global.match(x)
377  if m:
378  globals[int(m.group(1))] = x
379 
380  # find max global for which there is a run directory
381  run_set = set(runs.keys())
382  run_set = run_set.intersection(globals.keys())
383 
384  if self.opts.run < 0:
385  largest = max(run_set)
386  else:
387  largest = self.opts.run
388 
389  #self.log.info("Largest: %s", largest)
390  global_fp = os.path.join(self.ramdisk, globals[largest])
391  with open(global_fp, "r") as f:
392  global_param = f.read()
393 
394  return RunDesc(
395  run = largest,
396  run_fp = os.path.join(self.ramdisk, runs[largest]),
397  global_fp = global_fp,
398  global_param = global_param,
399  )
400 
def personalPlayback.FrameworkJob.do_exec (   self)

Definition at line 414 of file personalPlayback.py.

References personalPlayback.FrameworkJob.current_state, personalPlayback.FrameworkJob.discover_latest(), triggerObjects_cff.id, and personalPlayback.FrameworkJob.start_run().

414  def do_exec(self):
415  time.sleep(1)
416 
417  self.current_state = None
418 
419  while True:
420  latest = self.discover_latest()
421  if self.current_state is None or latest != self.current_state.desc:
422  self.log.info("Found latest run: %s", latest)
423 
424  self.start_run(latest)
425 
426  if not self.current_state:
427  self.log.info("Run not found, waiting 1 sec.")
428  else:
429  r = self.current_state.proc.poll()
430  if r is not None:
431  self.log.info("Process exitted: %s", r)
432 
433  return 0
434 
435  time.sleep(1)
436 
def personalPlayback.FrameworkJob.do_init (   self)

Definition at line 334 of file personalPlayback.py.

334  def do_init(self):
335  # check if our input directory is okay
336  self.ramdisk = self.opts.work_ramdisk
337  self.run = self.opts.run
338  self.cfg_file = self.kwargs["cfg_file"]
339 
340  if not os.path.isfile(self.cfg_file):
341  raise Exception("Configuration file not found: %s" % self.cfg_file)
342 
343  self.cfg_fp = os.path.realpath(self.cfg_file)
344  self.ramdisk_fp = os.path.realpath(self.ramdisk)
345 
346  self._set_name()
347  self._find_release()
348  self._prepare_files()
349 
def personalPlayback.FrameworkJob.make_args (   self,
  run 
)

Definition at line 350 of file personalPlayback.py.

References personalPlayback.FrameworkJob.cfg_link, personalPlayback.FrameworkJob.exec_file, personalPlayback.FrameworkJob.home_path, personalPlayback.FrameworkJob.output_path, personalPlayback.FrameworkJob.ramdisk_fp, and harvestTrackValidationPlots.str.

Referenced by personalPlayback.FrameworkJob.start_run().

350  def make_args(self, run):
351  args = []
352  args.append("bash") # arg 0
353  args.append(self.exec_file) # arg 0
354  args.append(self.home_path) # home path
355  args.append("slc6_amd64_gcc491") # release
356  args.append(self.output_path) # cwd/output path
357  args.append(str(run)) # run
358  args.append(self.ramdisk_fp) # ramdisk
359  args.append(self.cfg_link) # cmsRun arg 1
360  args.append("runkey=pp_run") # cmsRun arg 2
361 
362  return args
363 
def personalPlayback.FrameworkJob.start_run (   self,
  current 
)

Definition at line 401 of file personalPlayback.py.

References personalPlayback.FrameworkJob.current_state, join(), and personalPlayback.FrameworkJob.make_args().

Referenced by personalPlayback.FrameworkJob.do_exec().

401  def start_run(self, current):
402  old_state = self.current_state
403 
404  # kill the old run
405  # nope, since it involves eof and i am lazy
406  if old_state:
407  return
408 
409  args = self.make_args(current.run)
410  self.log.info("Executing: %s", " ".join(args))
411  proc = subprocess.Popen(args, preexec_fn=preexec_kill_on_pdeath)
412  self.current_state = RunState(desc=current, proc=proc)
413 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18

Member Data Documentation

personalPlayback.FrameworkJob.cfg_file
personalPlayback.FrameworkJob.cfg_fp

Definition at line 343 of file personalPlayback.py.

personalPlayback.FrameworkJob.cfg_link

Definition at line 331 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.cmsenv_path

Definition at line 270 of file personalPlayback.py.

personalPlayback.FrameworkJob.current_state
personalPlayback.FrameworkJob.exec_file

Definition at line 281 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.home_path

Definition at line 274 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.log_path

Definition at line 278 of file personalPlayback.py.

personalPlayback.FrameworkJob.name

Definition at line 256 of file personalPlayback.py.

Referenced by ElectronMVAID.ElectronMVAID.__call__(), dirstructure.Directory.__create_pie_image(), DisplayManager.DisplayManager.__del__(), dqm_interfaces.DirID.__eq__(), dirstructure.Directory.__get_full_path(), dirstructure.Comparison.__get_img_name(), dataset.Dataset.__getDataType(), dataset.Dataset.__getFileInfoList(), dirstructure.Comparison.__make_image(), core.autovars.NTupleVariable.__repr__(), core.autovars.NTupleObjectType.__repr__(), core.autovars.NTupleObject.__repr__(), core.autovars.NTupleCollection.__repr__(), dirstructure.Directory.__repr__(), dqm_interfaces.DirID.__repr__(), dirstructure.Comparison.__repr__(), config.Service.__setattr__(), config.CFG.__str__(), counter.Counter.__str__(), average.Average.__str__(), core.autovars.NTupleObjectType.addSubObjects(), core.autovars.NTupleObjectType.addVariables(), core.autovars.NTupleObjectType.allVars(), dirstructure.Directory.calcStats(), validation.Sample.digest(), python.rootplot.utilities.Hist.divide(), python.rootplot.utilities.Hist.divide_wilson(), DisplayManager.DisplayManager.Draw(), TreeCrawler.Package.dump(), core.autovars.NTupleVariable.fillBranch(), core.autovars.NTupleObject.fillBranches(), core.autovars.NTupleCollection.fillBranchesScalar(), core.autovars.NTupleCollection.fillBranchesVector(), core.autovars.NTupleCollection.get_cpp_declaration(), core.autovars.NTupleCollection.get_cpp_wrapper_class(), core.autovars.NTupleCollection.get_py_wrapper_class(), utils.StatisticalTest.get_status(), production_tasks.Task.getname(), dataset.CMSDataset.getPrimaryDatasetEntries(), dataset.PrivateDataset.getPrimaryDatasetEntries(), VIDSelectorBase.VIDSelectorBase.initialize(), core.autovars.NTupleVariable.makeBranch(), core.autovars.NTupleObject.makeBranches(), core.autovars.NTupleCollection.makeBranchesScalar(), core.autovars.NTupleCollection.makeBranchesVector(), dirstructure.Directory.print_report(), dataset.BaseDataset.printInfo(), dataset.Dataset.printInfo(), production_tasks.MonitorJobs.run(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), Vispa.Views.PropertyView.Property.valueChanged(), counter.Counter.write(), and average.Average.write().

personalPlayback.FrameworkJob.output_path

Definition at line 325 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.ramdisk

Definition at line 336 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.discover_latest().

personalPlayback.FrameworkJob.ramdisk_fp

Definition at line 344 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.run
personalPlayback.FrameworkJob.tag

Definition at line 255 of file personalPlayback.py.