test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
def do_exec
 
def do_init
 
def make_args
 
def start_run
 
- Public Member Functions inherited from personalPlayback.Applet
def __init__
 
def do_exec
 
def do_init
 
def log
 
def write
 

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
 
def _prepare_files
 
def _set_name
 

Additional Inherited Members

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

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.

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

Definition at line 273 of file personalPlayback.py.

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

Definition at line 246 of file personalPlayback.py.

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

247  def _set_name(self):
248  x = os.path.basename(self.cfg_file)
249  x = re.sub(r'(.*)\.py', r'\1', x)
250  x = re.sub(r'(.*)_cfg', r'\1', x)
251  x = re.sub(r'(.*)-live', r'\1', x)
252  x = re.sub(r'(.*)_sourceclient', r'\1', x)
253  x = re.sub(r'(.*)_dqm', r'\1', x)
254 
255  x = "".join([c for c in x if c.isalnum()])
256  self.tag = x
257  self.name = "cmssw_%s" % x
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 bookConverter.max, personalPlayback.Playback.ramdisk, personalPlayback.FrameworkJob.ramdisk, and personalPlayback.RunDesc.

Referenced by personalPlayback.FrameworkJob.do_exec().

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

Definition at line 414 of file personalPlayback.py.

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

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

Definition at line 334 of file personalPlayback.py.

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

Referenced by personalPlayback.FrameworkJob.start_run().

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

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

Member Data Documentation

personalPlayback.FrameworkJob.cfg_file

Definition at line 338 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob._find_release(), and personalPlayback.FrameworkJob._set_name().

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

Definition at line 412 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.do_exec(), and personalPlayback.FrameworkJob.start_run().

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(), cuy.divideElement.__init__(), cuy.plotElement.__init__(), cuy.additionElement.__init__(), cuy.superimposeElement.__init__(), cuy.graphElement.__init__(), 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

Definition at line 337 of file personalPlayback.py.

Referenced by generateEDF.LumiInfo.__str__(), Types.EventID.cppID(), Types.LuminosityBlockID.cppID(), generateEDF.LumiInfo.fixXingInfo(), and dqm_interfaces.DirWalkerFile.walk().

personalPlayback.FrameworkJob.tag

Definition at line 255 of file personalPlayback.py.

Referenced by Inspector.Inspector.SetTag().