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

Member Function Documentation

◆ _find_release()

def personalPlayback.FrameworkJob._find_release (   self)
private

Definition at line 259 of file personalPlayback.py.

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.")
270 
271  self.cmsenv_path = fp
272  self.log.info("cmsenv path: %s", self.cmsenv_path)
273 

References personalPlayback.FrameworkJob.cfg_file.

◆ _prepare_files()

def personalPlayback.FrameworkJob._prepare_files (   self)
private

Definition at line 274 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)
278 
279  self.log_path = self.opts.work_logs
280  self.log.info("logs path: %s", self.log_path)
281 
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 
334 

◆ _set_name()

def personalPlayback.FrameworkJob._set_name (   self)
private

Definition at line 247 of file personalPlayback.py.

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
258 

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

◆ discover_latest()

def personalPlayback.FrameworkJob.discover_latest (   self)

Definition at line 365 of file personalPlayback.py.

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  )
401 

References personalPlayback.int, SiStripPI.max, personalPlayback.Applet.opts, personalPlayback.Playback.ramdisk, personalPlayback.FrameworkJob.ramdisk, and personalPlayback.RunDesc.

Referenced by personalPlayback.FrameworkJob.do_exec().

◆ do_exec()

def personalPlayback.FrameworkJob.do_exec (   self)

Reimplemented from personalPlayback.Applet.

Definition at line 415 of file personalPlayback.py.

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)
437 

References personalPlayback.FrameworkJob.current_state, personalPlayback.FrameworkJob.discover_latest(), info(), personalPlayback.Applet.log(), conddbCopyTest.CopyTest.log(), conditionUploadTest.UploadTest.log(), cond::persistency::Logger.log(), cond::CredentialStore.log(), crabFunctions.CrabTask.log, and personalPlayback.FrameworkJob.start_run().

◆ do_init()

def personalPlayback.FrameworkJob.do_init (   self)

Reimplemented from personalPlayback.Applet.

Definition at line 335 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)
343 
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()
350 

◆ make_args()

def personalPlayback.FrameworkJob.make_args (   self,
  run 
)

Definition at line 351 of file personalPlayback.py.

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
364 

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

Referenced by personalPlayback.FrameworkJob.start_run().

◆ start_run()

def personalPlayback.FrameworkJob.start_run (   self,
  current 
)

Definition at line 402 of file personalPlayback.py.

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)
414 

References personalPlayback.FrameworkJob.current_state, info(), join(), personalPlayback.Applet.log(), conddbCopyTest.CopyTest.log(), conditionUploadTest.UploadTest.log(), cond::persistency::Logger.log(), cond::CredentialStore.log(), crabFunctions.CrabTask.log, and personalPlayback.FrameworkJob.make_args().

Referenced by personalPlayback.FrameworkJob.do_exec().

Member Data Documentation

◆ cfg_file

personalPlayback.FrameworkJob.cfg_file

◆ cfg_fp

personalPlayback.FrameworkJob.cfg_fp

Definition at line 344 of file personalPlayback.py.

◆ cfg_link

personalPlayback.FrameworkJob.cfg_link

Definition at line 332 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

◆ cmsenv_path

personalPlayback.FrameworkJob.cmsenv_path

Definition at line 271 of file personalPlayback.py.

◆ current_state

personalPlayback.FrameworkJob.current_state

◆ exec_file

personalPlayback.FrameworkJob.exec_file

Definition at line 282 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

◆ home_path

personalPlayback.FrameworkJob.home_path

Definition at line 275 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

◆ log_path

personalPlayback.FrameworkJob.log_path

Definition at line 279 of file personalPlayback.py.

◆ name

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(), dataset.CMSDataset.buildListOfFiles(), dataset.LocalDataset.buildListOfFiles(), dataset.CMSDataset.buildListOfFilesDBS(), 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(), counter.Counter.write(), and average.Average.write().

◆ output_path

personalPlayback.FrameworkJob.output_path

Definition at line 326 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

◆ ramdisk

personalPlayback.FrameworkJob.ramdisk

Definition at line 337 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.discover_latest().

◆ ramdisk_fp

personalPlayback.FrameworkJob.ramdisk_fp

Definition at line 345 of file personalPlayback.py.

Referenced by personalPlayback.FrameworkJob.make_args().

◆ run

personalPlayback.FrameworkJob.run

◆ tag

personalPlayback.FrameworkJob.tag
personalPlayback.RunDesc
RunDesc
Definition: personalPlayback.py:243
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
relativeConstraints.error
error
Definition: relativeConstraints.py:53
MessageLogger_cfi.warning
warning
Definition: MessageLogger_cfi.py:18
str
#define str(s)
Definition: TestProcessor.cc:53
personalPlayback.RunState
RunState
Definition: personalPlayback.py:244
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Exception
personalPlayback.int
int
Definition: personalPlayback.py:465
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29