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

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 502 of file runTheMatrix.py.

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

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

◆ complete_runWorkflow()

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

Definition at line 639 of file runTheMatrix.py.

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

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

◆ complete_searchInWorkflow()

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

Definition at line 683 of file runTheMatrix.py.

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

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

◆ complete_showWorkflow()

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

Definition at line 563 of file runTheMatrix.py.

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

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

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 524 of file runTheMatrix.py.

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

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

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

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 730 of file runTheMatrix.py.

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

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

References print().

Referenced by runTheMatrix.TheMatrix.default().

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

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

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

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

545  def do_predefined(self, arg):
546  """Print the list of predefined workflows"""
547  print("List of predefined workflows")
548  if arg:
549  for w in arg.split():
550  if w in predefinedSet.keys():
551  print("Predefined Set: %s" % w)
552  print(predefinedSet[w])
553  else:
554  print("Unknown Set: %s" % w)
555  else:
556  print("[ " + Fore.RED + ", ".join([str(k) for k in predefinedSet.keys()]) + Fore.RESET + " ]")
557 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#define str(s)

◆ do_runWorkflow()

def runTheMatrix.TheMatrix.do_runWorkflow (   self,
  arg 
)

Definition at line 586 of file runTheMatrix.py.

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

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

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

718  def do_search(self, arg):
719  args = arg.split()
720  if len(args) < 1:
721  print("search regexp")
722  return
723  for wfl in self.matrices_.keys():
724  self.do_searchInWorkflow(' '.join([wfl, args[0]]))
725 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ do_searchInWorkflow()

def runTheMatrix.TheMatrix.do_searchInWorkflow (   self,
  arg 
)

Definition at line 689 of file runTheMatrix.py.

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

Referenced by runTheMatrix.TheMatrix.do_search().

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

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

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

References join(), and print().

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

◆ help_jobs()

def runTheMatrix.TheMatrix.help_jobs (   self)

Definition at line 674 of file runTheMatrix.py.

References join(), and print().

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

◆ help_predefined()

def runTheMatrix.TheMatrix.help_predefined (   self)

Definition at line 534 of file runTheMatrix.py.

References join(), and print().

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

◆ help_runWorkflow()

def runTheMatrix.TheMatrix.help_runWorkflow (   self)

Definition at line 645 of file runTheMatrix.py.

References join(), and print().

645  def help_runWorkflow(self):
646  print("\n".join(["runWorkflow workflow_class workflow_id\n",
647  "This command will launch a new and independent process that invokes",
648  "the command:\n",
649  "runTheMatrix.py -w workflow_class -l workflow_id [runTheMatrix.py options]",
650  "\nYou can specify just one workflow_class and workflow_id per invocation.",
651  "The job will continue even after quitting the interactive session.",
652  "stdout and stderr of the new process will be automatically",
653  "redirected to 2 logfiles whose names contain the workflow_class",
654  "and workflow_id. Mutiple command can be issued one after the other.",
655  "The working directory of the new process will be the directory",
656  "from which the interactive session has started.",
657  "Autocompletion is available for workflow_class, but",
658  "not for workflow_id. Supplying a wrong workflow_class or",
659  "a non-existing workflow_id for a valid workflow_class",
660  "will trigger an error and no process will be invoked.",
661  "The interactive shell will keep track of all active processes",
662  "and will prevent the accidental resubmission of an already",
663  "active jobs."]))
664 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ help_search()

def runTheMatrix.TheMatrix.help_search (   self)

Definition at line 713 of file runTheMatrix.py.

References join(), and print().

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

◆ help_searchInWorkflow()

def runTheMatrix.TheMatrix.help_searchInWorkflow (   self)

Definition at line 678 of file runTheMatrix.py.

References join(), and print().

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

◆ help_showWorkflow()

def runTheMatrix.TheMatrix.help_showWorkflow (   self)

Definition at line 558 of file runTheMatrix.py.

References join(), and print().

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

Member Data Documentation

◆ do_EOF

runTheMatrix.TheMatrix.do_EOF
static

Definition at line 753 of file runTheMatrix.py.

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 499 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 504 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 500 of file runTheMatrix.py.