CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Static Public Attributes
runTheMatrix.TheMatrix Class Reference
Inheritance diagram for runTheMatrix.TheMatrix:

Public Member Functions

def __init__ (self, opt)
 
def complete_predefined (self, text, line, start_idx, end_idx)
 
def complete_runWorkflow (self, text, line, start_idx, end_idx)
 
def complete_searchInWorkflow (self, text, line, start_idx, end_idx)
 
def complete_showWorkflow (self, text, line, start_idx, end_idx)
 
def default (self, inp)
 
def do_clear (self, arg)
 
def do_dumpWorkflowId (self, arg)
 
def do_exit (self, arg)
 
def do_jobs (self, args)
 
def do_predefined (self, arg)
 
def do_runWorkflow (self, arg)
 
def do_search (self, arg)
 
def do_searchInWorkflow (self, arg)
 
def do_showWorkflow (self, arg)
 
def help_dumpWorkflowId (self)
 
def help_jobs (self)
 
def help_predefined (self)
 
def help_runWorkflow (self)
 
def help_search (self)
 
def help_searchInWorkflow (self)
 
def help_showWorkflow (self)
 

Public Attributes

 matrices_
 
 opt_
 
 processes_
 

Static Public Attributes

 do_EOF
 
 intro
 
 prompt
 

Detailed Description

Definition at line 476 of file runTheMatrix.py.

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 480 of file runTheMatrix.py.

480  def __init__(self, opt):
481  cmd.Cmd.__init__(self)
482  self.opt_ = opt
483  self.matrices_ = {}
484  tmp = MatrixReader(self.opt_)
485  self.processes_ = dict()
486  for what in tmp.files:
487  what = what.replace('relval_','')
488  self.opt_.what = what
489  self.matrices_[what] = MatrixReader(self.opt_)
490  self.matrices_[what].prepare(self.opt_.useInput, self.opt_.refRel,
491  self.opt_.fromScratch)
492  os.system("clear")
493 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ complete_predefined()

def runTheMatrix.TheMatrix.complete_predefined (   self,
  text,
  line,
  start_idx,
  end_idx 
)

Definition at line 517 of file runTheMatrix.py.

517  def complete_predefined(self, text, line, start_idx, end_idx):
518  if text and len(text) > 0:
519  return [t for t in predefinedSet.keys() if t.startswith(text)]
520  else:
521  return predefinedSet.keys()
522 

◆ complete_runWorkflow()

def runTheMatrix.TheMatrix.complete_runWorkflow (   self,
  text,
  line,
  start_idx,
  end_idx 
)

Definition at line 617 of file runTheMatrix.py.

References relativeConstraints.keys, and runTheMatrix.TheMatrix.matrices_.

617  def complete_runWorkflow(self, text, line, start_idx, end_idx):
618  if text and len(text) > 0:
619  return [t for t in self.matrices_.keys() if t.startswith(text)]
620  else:
621  return self.matrices_.keys()
622 

◆ complete_searchInWorkflow()

def runTheMatrix.TheMatrix.complete_searchInWorkflow (   self,
  text,
  line,
  start_idx,
  end_idx 
)

Definition at line 661 of file runTheMatrix.py.

References relativeConstraints.keys, and runTheMatrix.TheMatrix.matrices_.

661  def complete_searchInWorkflow(self, text, line, start_idx, end_idx):
662  if text and len(text) > 0:
663  return [t for t in self.matrices_.keys() if t.startswith(text)]
664  else:
665  return self.matrices_.keys()
666 

◆ complete_showWorkflow()

def runTheMatrix.TheMatrix.complete_showWorkflow (   self,
  text,
  line,
  start_idx,
  end_idx 
)

Definition at line 541 of file runTheMatrix.py.

References relativeConstraints.keys, and runTheMatrix.TheMatrix.matrices_.

541  def complete_showWorkflow(self, text, line, start_idx, end_idx):
542  if text and len(text) > 0:
543  return [t for t in self.matrices_.keys() if t.startswith(text)]
544  else:
545  return self.matrices_.keys()
546 

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 502 of file runTheMatrix.py.

References runTheMatrix.TheMatrix.do_exit(), and print().

502  def default(self, inp):
503  if inp == 'x' or inp == 'q':
504  return self.do_exit(inp)
505  else:
506  is_pipe = not isatty(sys.stdin.fileno())
507  print(Fore.RED + "Error: " + Fore.RESET + "unrecognized command.")
508  # Quit only if given a piped command.
509  if is_pipe:
510  sys.exit(1)
511 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ do_clear()

def runTheMatrix.TheMatrix.do_clear (   self,
  arg 
)
Clear the screen, put prompt at the top

Definition at line 494 of file runTheMatrix.py.

494  def do_clear(self, arg):
495  """Clear the screen, put prompt at the top"""
496  os.system("clear")
497 

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 708 of file runTheMatrix.py.

References ALCARECOEcalPhiSym_cff.float, mps_monitormerge.items, runTheMatrix.TheMatrix.matrices_, print(), and str.

708  def do_dumpWorkflowId(self, arg):
709  wflids = arg.split()
710  if len(wflids) == 0:
711  print("dumpWorkflowId [wfl-id1 [...]]")
712  return
713 
714  fmt = "[%s]: %s\n"
715  maxLen = 100
716  for wflid in wflids:
717  dump = True
718  for key, mrd in self.matrices_.items():
719  for wfl in mrd.workFlows:
720  if wfl.numId == float(wflid):
721  if dump:
722  dump = False
723  print(Fore.GREEN + str(wfl.numId) + Fore.RESET + " " + Fore.YELLOW + wfl.nameId + Fore.RESET)
724  for i,s in enumerate(wfl.cmds):
725  print(fmt % (Fore.RED + str(i+1) + Fore.RESET,
726  (str(s)+' ')))
727  print("\nWorkflow found in %s." % key)
728  else:
729  print("Workflow also found in %s." % key)
730 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

◆ do_exit()

def runTheMatrix.TheMatrix.do_exit (   self,
  arg 
)

Definition at line 498 of file runTheMatrix.py.

References print().

Referenced by runTheMatrix.TheMatrix.default().

498  def do_exit(self, arg):
499  print("Leaving the Matrix")
500  return True
501 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ do_jobs()

def runTheMatrix.TheMatrix.do_jobs (   self,
  args 
)

Definition at line 643 of file runTheMatrix.py.

References relativeConstraints.keys, print(), and runTheMatrix.TheMatrix.processes_.

643  def do_jobs(self, args):
644  print(Fore.GREEN + Style.BRIGHT + "List of jobs:")
645  for w in self.processes_.keys():
646  if self.processes_[w][0].poll() is None:
647  print(Fore.YELLOW + Style.BRIGHT + "Active job: {} since {:.2f} seconds.".format(w, time.time() - self.processes_[w][1]))
648  else:
649  print(Fore.RED + Style.BRIGHT + "Done job: {}".format(w))
650  print(Style.RESET_ALL)
651 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ do_predefined()

def runTheMatrix.TheMatrix.do_predefined (   self,
  arg 
)
Print the list of predefined workflows

Definition at line 523 of file runTheMatrix.py.

References join(), print(), and str.

523  def do_predefined(self, arg):
524  """Print the list of predefined workflows"""
525  print("List of predefined workflows")
526  if arg:
527  for w in arg.split():
528  if w in predefinedSet.keys():
529  print("Predefined Set: %s" % w)
530  print(predefinedSet[w])
531  else:
532  print("Unknown Set: %s" % w)
533  else:
534  print("[ " + Fore.RED + ", ".join([str(k) for k in predefinedSet.keys()]) + Fore.RESET + " ]")
535 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21
#define str(s)

◆ do_runWorkflow()

def runTheMatrix.TheMatrix.do_runWorkflow (   self,
  arg 
)

Definition at line 564 of file runTheMatrix.py.

References ALCARECOEcalPhiSym_cff.float, relativeConstraints.keys, runTheMatrix.TheMatrix.matrices_, print(), runTheMatrix.TheMatrix.processes_, and mkLumiAveragedPlots.tuple.

564  def do_runWorkflow(self, arg):
565  # Split the input arguments into a list
566  args = arg.split()
567  if len(args) < 2:
568  print(Fore.RED + Style.BRIGHT + "Wrong number of parameters passed")
569  print(Style.RESET_ALL)
570  return
571  workflow_class = args[0]
572  workflow_id = args[1]
573  passed_down_args = list()
574  if len(args) > 2:
575  passed_down_args = args[2:]
576  print(Fore.YELLOW + Style.BRIGHT + "Running with the following options:\n")
577  print(Fore.GREEN + Style.BRIGHT + "Workflow class: {}".format(workflow_class))
578  print(Fore.GREEN + Style.BRIGHT + "Workflow ID: {}".format(workflow_id))
579  print(Fore.GREEN + Style.BRIGHT + "Additional runTheMatrix options: {}".format(passed_down_args))
580  print(Style.RESET_ALL)
581  if workflow_class not in self.matrices_.keys():
582  print(Fore.RED + Style.BRIGHT + "Unknown workflow selected: {}".format(workflow_class))
583  print("Available workflows:")
584  for k in self.matrices_.keys():
585  print(Fore.RED + Style.BRIGHT + k)
586  print(Style.RESET_ALL)
587  return
588  wflnums = [x.numId for x in self.matrices_[workflow_class].workFlows]
589  if float(workflow_id) not in wflnums:
590  print(Fore.RED + Style.BRIGHT + "Unknown workflow {}".format(workflow_id))
591  print(Fore.GREEN + Style.BRIGHT)
592  print(wflnums)
593  print(Style.RESET_ALL)
594  return
595  if workflow_id in self.processes_.keys():
596  # Check if the process is still active
597  if self.processes_[workflow_id][0].poll() is None:
598  print(Fore.RED + Style.BRIGHT + "Workflow {} already running!".format(workflow_id))
599  print(Style.RESET_ALL)
600  return
601  # If it was there but it's gone, proceeed and update the value for the same key
602  # run a job, redirecting standard output and error to files
603  lognames = ['stdout', 'stderr']
604  logfiles = tuple('%s_%s_%s.log' % (workflow_class, workflow_id, name) for name in lognames)
605  stdout = open(logfiles[0], 'w')
606  stderr = open(logfiles[1], 'w')
607  command = ('runTheMatrix.py', '-w', workflow_class, '-l', workflow_id)
608  if len(passed_down_args) > 0:
609  command += tuple(passed_down_args)
610  print(command)
611  p = subprocess.Popen(command,
612  stdout = stdout,
613  stderr = stderr)
614  self.processes_[workflow_id] = (p, time.time())
615 
616 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ do_search()

def runTheMatrix.TheMatrix.do_search (   self,
  arg 
)

Definition at line 696 of file runTheMatrix.py.

References runTheMatrix.TheMatrix.do_searchInWorkflow(), join(), relativeConstraints.keys, runTheMatrix.TheMatrix.matrices_, and print().

696  def do_search(self, arg):
697  args = arg.split()
698  if len(args) < 1:
699  print("search regexp")
700  return
701  for wfl in self.matrices_.keys():
702  self.do_searchInWorkflow(' '.join([wfl, args[0]]))
703 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ do_searchInWorkflow()

def runTheMatrix.TheMatrix.do_searchInWorkflow (   self,
  arg 
)

Definition at line 667 of file runTheMatrix.py.

References relativeConstraints.keys, runTheMatrix.TheMatrix.matrices_, print(), and str.

Referenced by runTheMatrix.TheMatrix.do_search().

667  def do_searchInWorkflow(self, arg):
668  args = arg.split()
669  if len(args) < 2:
670  print("searchInWorkflow name regexp")
671  return
672  if args[0] not in self.matrices_.keys():
673  print("Unknown workflow")
674  return
675  import re
676  pattern = None
677  try:
678  pattern = re.compile(args[1])
679  except:
680  print("Failed to compile regexp %s" % args[1])
681  return
682  counter = 0
683  for wfl in self.matrices_[args[0]].workFlows:
684  if re.match(pattern, wfl.nameId):
685  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
686  Fore.GREEN + wfl.nameId + Fore.RESET))
687  counter +=1
688  print("Found %s compatible workflows inside %s" % (Fore.RED + str(counter) + Fore.RESET,
689  Fore.YELLOW + str(args[0])) + Fore.RESET)
690 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

◆ do_showWorkflow()

def runTheMatrix.TheMatrix.do_showWorkflow (   self,
  arg 
)

Definition at line 547 of file runTheMatrix.py.

References relativeConstraints.keys, runTheMatrix.TheMatrix.matrices_, print(), and str.

547  def do_showWorkflow(self, arg):
548  if arg == '':
549  print("Available workflows:")
550  for k in self.matrices_.keys():
551  print(Fore.RED + Style.BRIGHT + k)
552  print(Style.RESET_ALL)
553  else:
554  selected = arg.split()
555  for k in selected:
556  if k not in self.matrices_.keys():
557  print("Unknown workflow %s: skipping" % k)
558  else:
559  for wfl in self.matrices_[k].workFlows:
560  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
561  Fore.GREEN + wfl.nameId + Fore.RESET))
562  print("%s contains %d workflows" % (Fore.RED + k + Fore.RESET, len(self.matrices_[k].workFlows)))
563 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

◆ help_dumpWorkflowId()

def runTheMatrix.TheMatrix.help_dumpWorkflowId (   self)

Definition at line 704 of file runTheMatrix.py.

References join(), and print().

704  def help_dumpWorkflowId(self):
705  print("\n".join(["dumpWorkflowId [wfl-id1 [...]]\n",
706  "Dumps the details (cmsDriver commands for all steps) of the space-separated workflow-ids in input."]))
707 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ help_jobs()

def runTheMatrix.TheMatrix.help_jobs (   self)

Definition at line 652 of file runTheMatrix.py.

References join(), and print().

652  def help_jobs(self):
653  print("\n".join(["Print a full list of active and done jobs submitted",
654  "in the ongoing interactive session"]))
655 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ help_predefined()

def runTheMatrix.TheMatrix.help_predefined (   self)

Definition at line 512 of file runTheMatrix.py.

References join(), and print().

512  def help_predefined(self):
513  print("\n".join(["predefined [predef1 [...]]\n",
514  "Run w/o argument, it will print the list of known predefined workflows.",
515  "Run with space-separated predefined workflows, it will print the workflow-ids registered to them"]))
516 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ help_runWorkflow()

def runTheMatrix.TheMatrix.help_runWorkflow (   self)

Definition at line 623 of file runTheMatrix.py.

References join(), and print().

623  def help_runWorkflow(self):
624  print("\n".join(["runWorkflow workflow_class workflow_id\n",
625  "This command will launch a new and independent process that invokes",
626  "the command:\n",
627  "runTheMatrix.py -w workflow_class -l workflow_id [runTheMatrix.py options]",
628  "\nYou can specify just one workflow_class and workflow_id per invocation.",
629  "The job will continue even after quitting the interactive session.",
630  "stdout and stderr of the new process will be automatically",
631  "redirected to 2 logfiles whose names contain the workflow_class",
632  "and workflow_id. Mutiple command can be issued one after the other.",
633  "The working directory of the new process will be the directory",
634  "from which the interactive session has started.",
635  "Autocompletion is available for workflow_class, but",
636  "not for workflow_id. Supplying a wrong workflow_class or",
637  "a non-existing workflow_id for a valid workflow_class",
638  "will trigger an error and no process will be invoked.",
639  "The interactive shell will keep track of all active processes",
640  "and will prevent the accidental resubmission of an already",
641  "active jobs."]))
642 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ help_search()

def runTheMatrix.TheMatrix.help_search (   self)

Definition at line 691 of file runTheMatrix.py.

References join(), and print().

691  def help_search(self):
692  print("\n".join(["search search_regexp\n",
693  "This command will search for a match within all workflows registered.",
694  "The search is done on both the workflow name and the names of steps registered to it."]))
695 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ help_searchInWorkflow()

def runTheMatrix.TheMatrix.help_searchInWorkflow (   self)

Definition at line 656 of file runTheMatrix.py.

References join(), and print().

656  def help_searchInWorkflow(self):
657  print("\n".join(["searchInWorkflow wfl_name search_regexp\n",
658  "This command will search for a match within all workflows registered to wfl_name.",
659  "The search is done on both the workflow name and the names of steps registered to it."]))
660 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ help_showWorkflow()

def runTheMatrix.TheMatrix.help_showWorkflow (   self)

Definition at line 536 of file runTheMatrix.py.

References join(), and print().

536  def help_showWorkflow(self):
537  print("\n".join(["showWorkflow [workflow1 [...]]\n",
538  "Run w/o arguments, it will print the list of registered macro-workflows.",
539  "Run with space-separated workflows, it will print the full list of workflow-ids registered to them"]))
540 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

Member Data Documentation

◆ do_EOF

runTheMatrix.TheMatrix.do_EOF
static

Definition at line 731 of file runTheMatrix.py.

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 477 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 482 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 478 of file runTheMatrix.py.