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 497 of file runTheMatrix.py.

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 501 of file runTheMatrix.py.

501  def __init__(self, opt):
502  cmd.Cmd.__init__(self)
503  self.opt_ = opt
504  self.matrices_ = {}
505  tmp = MatrixReader(self.opt_)
506  self.processes_ = dict()
507  for what in tmp.files:
508  what = what.replace('relval_','')
509  self.opt_.what = what
510  self.matrices_[what] = MatrixReader(self.opt_)
511  self.matrices_[what].prepare(self.opt_.useInput, self.opt_.refRel,
512  self.opt_.fromScratch)
513  os.system("clear")
514 
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 538 of file runTheMatrix.py.

538  def complete_predefined(self, text, line, start_idx, end_idx):
539  if text and len(text) > 0:
540  return [t for t in predefinedSet.keys() if t.startswith(text)]
541  else:
542  return predefinedSet.keys()
543 

◆ complete_runWorkflow()

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

Definition at line 638 of file runTheMatrix.py.

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

638  def complete_runWorkflow(self, text, line, start_idx, end_idx):
639  if text and len(text) > 0:
640  return [t for t in self.matrices_.keys() if t.startswith(text)]
641  else:
642  return self.matrices_.keys()
643 

◆ complete_searchInWorkflow()

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

Definition at line 682 of file runTheMatrix.py.

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

682  def complete_searchInWorkflow(self, text, line, start_idx, end_idx):
683  if text and len(text) > 0:
684  return [t for t in self.matrices_.keys() if t.startswith(text)]
685  else:
686  return self.matrices_.keys()
687 

◆ complete_showWorkflow()

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

Definition at line 562 of file runTheMatrix.py.

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

562  def complete_showWorkflow(self, text, line, start_idx, end_idx):
563  if text and len(text) > 0:
564  return [t for t in self.matrices_.keys() if t.startswith(text)]
565  else:
566  return self.matrices_.keys()
567 

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 523 of file runTheMatrix.py.

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

523  def default(self, inp):
524  if inp == 'x' or inp == 'q':
525  return self.do_exit(inp)
526  else:
527  is_pipe = not isatty(sys.stdin.fileno())
528  print(Fore.RED + "Error: " + Fore.RESET + "unrecognized command.")
529  # Quit only if given a piped command.
530  if is_pipe:
531  sys.exit(1)
532 
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 515 of file runTheMatrix.py.

515  def do_clear(self, arg):
516  """Clear the screen, put prompt at the top"""
517  os.system("clear")
518 

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 729 of file runTheMatrix.py.

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

729  def do_dumpWorkflowId(self, arg):
730  wflids = arg.split()
731  if len(wflids) == 0:
732  print("dumpWorkflowId [wfl-id1 [...]]")
733  return
734 
735  fmt = "[%s]: %s\n"
736  maxLen = 100
737  for wflid in wflids:
738  dump = True
739  for key, mrd in self.matrices_.items():
740  for wfl in mrd.workFlows:
741  if wfl.numId == float(wflid):
742  if dump:
743  dump = False
744  print(Fore.GREEN + str(wfl.numId) + Fore.RESET + " " + Fore.YELLOW + wfl.nameId + Fore.RESET)
745  for i,s in enumerate(wfl.cmds):
746  print(fmt % (Fore.RED + str(i+1) + Fore.RESET,
747  (str(s)+' ')))
748  print("\nWorkflow found in %s." % key)
749  else:
750  print("Workflow also found in %s." % key)
751 
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 519 of file runTheMatrix.py.

References print().

Referenced by runTheMatrix.TheMatrix.default().

519  def do_exit(self, arg):
520  print("Leaving the Matrix")
521  return True
522 
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 664 of file runTheMatrix.py.

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

664  def do_jobs(self, args):
665  print(Fore.GREEN + Style.BRIGHT + "List of jobs:")
666  for w in self.processes_.keys():
667  if self.processes_[w][0].poll() is None:
668  print(Fore.YELLOW + Style.BRIGHT + "Active job: {} since {:.2f} seconds.".format(w, time.time() - self.processes_[w][1]))
669  else:
670  print(Fore.RED + Style.BRIGHT + "Done job: {}".format(w))
671  print(Style.RESET_ALL)
672 
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 544 of file runTheMatrix.py.

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

544  def do_predefined(self, arg):
545  """Print the list of predefined workflows"""
546  print("List of predefined workflows")
547  if arg:
548  for w in arg.split():
549  if w in predefinedSet.keys():
550  print("Predefined Set: %s" % w)
551  print(predefinedSet[w])
552  else:
553  print("Unknown Set: %s" % w)
554  else:
555  print("[ " + Fore.RED + ", ".join([str(k) for k in predefinedSet.keys()]) + Fore.RESET + " ]")
556 
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 585 of file runTheMatrix.py.

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

585  def do_runWorkflow(self, arg):
586  # Split the input arguments into a list
587  args = arg.split()
588  if len(args) < 2:
589  print(Fore.RED + Style.BRIGHT + "Wrong number of parameters passed")
590  print(Style.RESET_ALL)
591  return
592  workflow_class = args[0]
593  workflow_id = args[1]
594  passed_down_args = list()
595  if len(args) > 2:
596  passed_down_args = args[2:]
597  print(Fore.YELLOW + Style.BRIGHT + "Running with the following options:\n")
598  print(Fore.GREEN + Style.BRIGHT + "Workflow class: {}".format(workflow_class))
599  print(Fore.GREEN + Style.BRIGHT + "Workflow ID: {}".format(workflow_id))
600  print(Fore.GREEN + Style.BRIGHT + "Additional runTheMatrix options: {}".format(passed_down_args))
601  print(Style.RESET_ALL)
602  if workflow_class not in self.matrices_.keys():
603  print(Fore.RED + Style.BRIGHT + "Unknown workflow selected: {}".format(workflow_class))
604  print("Available workflows:")
605  for k in self.matrices_.keys():
606  print(Fore.RED + Style.BRIGHT + k)
607  print(Style.RESET_ALL)
608  return
609  wflnums = [x.numId for x in self.matrices_[workflow_class].workFlows]
610  if float(workflow_id) not in wflnums:
611  print(Fore.RED + Style.BRIGHT + "Unknown workflow {}".format(workflow_id))
612  print(Fore.GREEN + Style.BRIGHT)
613  print(wflnums)
614  print(Style.RESET_ALL)
615  return
616  if workflow_id in self.processes_.keys():
617  # Check if the process is still active
618  if self.processes_[workflow_id][0].poll() is None:
619  print(Fore.RED + Style.BRIGHT + "Workflow {} already running!".format(workflow_id))
620  print(Style.RESET_ALL)
621  return
622  # If it was there but it's gone, proceeed and update the value for the same key
623  # run a job, redirecting standard output and error to files
624  lognames = ['stdout', 'stderr']
625  logfiles = tuple('%s_%s_%s.log' % (workflow_class, workflow_id, name) for name in lognames)
626  stdout = open(logfiles[0], 'w')
627  stderr = open(logfiles[1], 'w')
628  command = ('runTheMatrix.py', '-w', workflow_class, '-l', workflow_id)
629  if len(passed_down_args) > 0:
630  command += tuple(passed_down_args)
631  print(command)
632  p = subprocess.Popen(command,
633  stdout = stdout,
634  stderr = stderr)
635  self.processes_[workflow_id] = (p, time.time())
636 
637 
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 717 of file runTheMatrix.py.

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

717  def do_search(self, arg):
718  args = arg.split()
719  if len(args) < 1:
720  print("search regexp")
721  return
722  for wfl in self.matrices_.keys():
723  self.do_searchInWorkflow(' '.join([wfl, args[0]]))
724 
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 688 of file runTheMatrix.py.

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

Referenced by runTheMatrix.TheMatrix.do_search().

688  def do_searchInWorkflow(self, arg):
689  args = arg.split()
690  if len(args) < 2:
691  print("searchInWorkflow name regexp")
692  return
693  if args[0] not in self.matrices_.keys():
694  print("Unknown workflow")
695  return
696  import re
697  pattern = None
698  try:
699  pattern = re.compile(args[1])
700  except:
701  print("Failed to compile regexp %s" % args[1])
702  return
703  counter = 0
704  for wfl in self.matrices_[args[0]].workFlows:
705  if re.match(pattern, wfl.nameId):
706  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
707  Fore.GREEN + wfl.nameId + Fore.RESET))
708  counter +=1
709  print("Found %s compatible workflows inside %s" % (Fore.RED + str(counter) + Fore.RESET,
710  Fore.YELLOW + str(args[0])) + Fore.RESET)
711 
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 568 of file runTheMatrix.py.

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

568  def do_showWorkflow(self, arg):
569  if arg == '':
570  print("Available workflows:")
571  for k in self.matrices_.keys():
572  print(Fore.RED + Style.BRIGHT + k)
573  print(Style.RESET_ALL)
574  else:
575  selected = arg.split()
576  for k in selected:
577  if k not in self.matrices_.keys():
578  print("Unknown workflow %s: skipping" % k)
579  else:
580  for wfl in self.matrices_[k].workFlows:
581  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
582  Fore.GREEN + wfl.nameId + Fore.RESET))
583  print("%s contains %d workflows" % (Fore.RED + k + Fore.RESET, len(self.matrices_[k].workFlows)))
584 
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 725 of file runTheMatrix.py.

References join(), and print().

725  def help_dumpWorkflowId(self):
726  print("\n".join(["dumpWorkflowId [wfl-id1 [...]]\n",
727  "Dumps the details (cmsDriver commands for all steps) of the space-separated workflow-ids in input."]))
728 
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 673 of file runTheMatrix.py.

References join(), and print().

673  def help_jobs(self):
674  print("\n".join(["Print a full list of active and done jobs submitted",
675  "in the ongoing interactive session"]))
676 
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 533 of file runTheMatrix.py.

References join(), and print().

533  def help_predefined(self):
534  print("\n".join(["predefined [predef1 [...]]\n",
535  "Run w/o argument, it will print the list of known predefined workflows.",
536  "Run with space-separated predefined workflows, it will print the workflow-ids registered to them"]))
537 
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 644 of file runTheMatrix.py.

References join(), and print().

644  def help_runWorkflow(self):
645  print("\n".join(["runWorkflow workflow_class workflow_id\n",
646  "This command will launch a new and independent process that invokes",
647  "the command:\n",
648  "runTheMatrix.py -w workflow_class -l workflow_id [runTheMatrix.py options]",
649  "\nYou can specify just one workflow_class and workflow_id per invocation.",
650  "The job will continue even after quitting the interactive session.",
651  "stdout and stderr of the new process will be automatically",
652  "redirected to 2 logfiles whose names contain the workflow_class",
653  "and workflow_id. Mutiple command can be issued one after the other.",
654  "The working directory of the new process will be the directory",
655  "from which the interactive session has started.",
656  "Autocompletion is available for workflow_class, but",
657  "not for workflow_id. Supplying a wrong workflow_class or",
658  "a non-existing workflow_id for a valid workflow_class",
659  "will trigger an error and no process will be invoked.",
660  "The interactive shell will keep track of all active processes",
661  "and will prevent the accidental resubmission of an already",
662  "active jobs."]))
663 
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 712 of file runTheMatrix.py.

References join(), and print().

712  def help_search(self):
713  print("\n".join(["search search_regexp\n",
714  "This command will search for a match within all workflows registered.",
715  "The search is done on both the workflow name and the names of steps registered to it."]))
716 
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 677 of file runTheMatrix.py.

References join(), and print().

677  def help_searchInWorkflow(self):
678  print("\n".join(["searchInWorkflow wfl_name search_regexp\n",
679  "This command will search for a match within all workflows registered to wfl_name.",
680  "The search is done on both the workflow name and the names of steps registered to it."]))
681 
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 557 of file runTheMatrix.py.

References join(), and print().

557  def help_showWorkflow(self):
558  print("\n".join(["showWorkflow [workflow1 [...]]\n",
559  "Run w/o arguments, it will print the list of registered macro-workflows.",
560  "Run with space-separated workflows, it will print the full list of workflow-ids registered to them"]))
561 
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 752 of file runTheMatrix.py.

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 498 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 503 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 499 of file runTheMatrix.py.