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 | 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 246 of file personalPlayback.py.

Member Function Documentation

def personalPlayback.FrameworkJob._find_release (   self)
private

Definition at line 259 of file personalPlayback.py.

References personalPlayback.FrameworkJob.cfg_file.

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

Definition at line 274 of file personalPlayback.py.

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

Definition at line 247 of file personalPlayback.py.

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

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

Definition at line 365 of file personalPlayback.py.

References SiStripPI.max, personalPlayback.Playback.ramdisk, personalPlayback.FrameworkJob.ramdisk, and personalPlayback.RunDesc.

Referenced by personalPlayback.FrameworkJob.do_exec().

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

Definition at line 415 of file personalPlayback.py.

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

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

Definition at line 335 of file personalPlayback.py.

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

Definition at line 351 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 str.

Referenced by personalPlayback.FrameworkJob.start_run().

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

Definition at line 402 of file personalPlayback.py.

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

Referenced by personalPlayback.FrameworkJob.do_exec().

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

Member Data Documentation

personalPlayback.FrameworkJob.cfg_file

Definition at line 339 of file personalPlayback.py.

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

personalPlayback.FrameworkJob.cfg_fp

Definition at line 344 of file personalPlayback.py.

personalPlayback.FrameworkJob.cfg_link

Definition at line 332 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.cmsenv_path

Definition at line 271 of file personalPlayback.py.

personalPlayback.FrameworkJob.current_state

Definition at line 413 of file personalPlayback.py.

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

personalPlayback.FrameworkJob.exec_file

Definition at line 282 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.home_path

Definition at line 275 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.log_path

Definition at line 279 of file personalPlayback.py.

personalPlayback.FrameworkJob.name

Definition at line 257 of file personalPlayback.py.

Referenced by ElectronMVAID.ElectronMVAID.__call__(), FWLite.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__(), FWLite.WorkingPoints._reformat_cut_definitions(), core.autovars.NTupleObjectType.addSubObjects(), core.autovars.NTupleObjectType.addVariables(), core.autovars.NTupleObjectType.allVars(), dirstructure.Directory.calcStats(), geometryComparison.GeometryComparison.createScript(), 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(), primaryVertexResolution.PrimaryVertexResolution.getRepMap(), primaryVertexValidation.PrimaryVertexValidation.getRepMap(), zMuMuValidation.ZMuMuValidation.getRepMap(), 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(), counter.Counter.write(), and average.Average.write().

personalPlayback.FrameworkJob.output_path

Definition at line 326 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.ramdisk

Definition at line 337 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.discover_latest().

personalPlayback.FrameworkJob.ramdisk_fp

Definition at line 345 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

personalPlayback.FrameworkJob.run

Definition at line 338 of file personalPlayback.py.

Referenced by generateEDF.LumiInfo.__str__(), DTWorkflow.DTWorkflow.all(), Types.EventID.cppID(), Types.LuminosityBlockID.cppID(), o2olib.O2OTool.execute(), generateEDF.LumiInfo.fixXingInfo(), and dqm_interfaces.DirWalkerFile.walk().

personalPlayback.FrameworkJob.tag

Definition at line 256 of file personalPlayback.py.

Referenced by FWLite.ElectronMVAID.__call__(), Inspector.Inspector.Loop(), DTTtrigWorkflow.DTttrigWorkflow.prepare_timeboxes_correction(), and DTWorkflow.DTWorkflow.remote_out_path().