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

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 483 of file runTheMatrix.py.

483  def __init__(self, opt):
484  cmd.Cmd.__init__(self)
485  self.opt_ = opt
486  self.matrices_ = {}
487  tmp = MatrixReader(self.opt_)
488  self.processes_ = dict()
489  for what in tmp.files:
490  what = what.replace('relval_','')
491  self.opt_.what = what
492  self.matrices_[what] = MatrixReader(self.opt_)
493  self.matrices_[what].prepare(self.opt_.useInput, self.opt_.refRel,
494  self.opt_.fromScratch)
495  os.system("clear")
496 
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 520 of file runTheMatrix.py.

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

◆ complete_runWorkflow()

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

Definition at line 620 of file runTheMatrix.py.

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

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

◆ complete_searchInWorkflow()

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

Definition at line 664 of file runTheMatrix.py.

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

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

◆ complete_showWorkflow()

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

Definition at line 544 of file runTheMatrix.py.

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

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

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 505 of file runTheMatrix.py.

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

505  def default(self, inp):
506  if inp == 'x' or inp == 'q':
507  return self.do_exit(inp)
508  else:
509  is_pipe = not isatty(sys.stdin.fileno())
510  print(Fore.RED + "Error: " + Fore.RESET + "unrecognized command.")
511  # Quit only if given a piped command.
512  if is_pipe:
513  sys.exit(1)
514 
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 497 of file runTheMatrix.py.

497  def do_clear(self, arg):
498  """Clear the screen, put prompt at the top"""
499  os.system("clear")
500 

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 711 of file runTheMatrix.py.

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

711  def do_dumpWorkflowId(self, arg):
712  wflids = arg.split()
713  if len(wflids) == 0:
714  print("dumpWorkflowId [wfl-id1 [...]]")
715  return
716 
717  fmt = "[%s]: %s\n"
718  maxLen = 100
719  for wflid in wflids:
720  dump = True
721  for key, mrd in self.matrices_.items():
722  for wfl in mrd.workFlows:
723  if wfl.numId == float(wflid):
724  if dump:
725  dump = False
726  print(Fore.GREEN + str(wfl.numId) + Fore.RESET + " " + Fore.YELLOW + wfl.nameId + Fore.RESET)
727  for i,s in enumerate(wfl.cmds):
728  print(fmt % (Fore.RED + str(i+1) + Fore.RESET,
729  (str(s)+' ')))
730  print("\nWorkflow found in %s." % key)
731  else:
732  print("Workflow also found in %s." % key)
733 
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 501 of file runTheMatrix.py.

References print().

Referenced by runTheMatrix.TheMatrix.default().

501  def do_exit(self, arg):
502  print("Leaving the Matrix")
503  return True
504 
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 646 of file runTheMatrix.py.

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

646  def do_jobs(self, args):
647  print(Fore.GREEN + Style.BRIGHT + "List of jobs:")
648  for w in self.processes_.keys():
649  if self.processes_[w][0].poll() is None:
650  print(Fore.YELLOW + Style.BRIGHT + "Active job: {} since {:.2f} seconds.".format(w, time.time() - self.processes_[w][1]))
651  else:
652  print(Fore.RED + Style.BRIGHT + "Done job: {}".format(w))
653  print(Style.RESET_ALL)
654 
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 526 of file runTheMatrix.py.

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

526  def do_predefined(self, arg):
527  """Print the list of predefined workflows"""
528  print("List of predefined workflows")
529  if arg:
530  for w in arg.split():
531  if w in predefinedSet.keys():
532  print("Predefined Set: %s" % w)
533  print(predefinedSet[w])
534  else:
535  print("Unknown Set: %s" % w)
536  else:
537  print("[ " + Fore.RED + ", ".join([str(k) for k in predefinedSet.keys()]) + Fore.RESET + " ]")
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:21
#define str(s)

◆ do_runWorkflow()

def runTheMatrix.TheMatrix.do_runWorkflow (   self,
  arg 
)

Definition at line 567 of file runTheMatrix.py.

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

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

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

699  def do_search(self, arg):
700  args = arg.split()
701  if len(args) < 1:
702  print("search regexp")
703  return
704  for wfl in self.matrices_.keys():
705  self.do_searchInWorkflow(' '.join([wfl, args[0]]))
706 
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 670 of file runTheMatrix.py.

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

Referenced by runTheMatrix.TheMatrix.do_search().

670  def do_searchInWorkflow(self, arg):
671  args = arg.split()
672  if len(args) < 2:
673  print("searchInWorkflow name regexp")
674  return
675  if args[0] not in self.matrices_.keys():
676  print("Unknown workflow")
677  return
678  import re
679  pattern = None
680  try:
681  pattern = re.compile(args[1])
682  except:
683  print("Failed to compile regexp %s" % args[1])
684  return
685  counter = 0
686  for wfl in self.matrices_[args[0]].workFlows:
687  if re.match(pattern, wfl.nameId):
688  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
689  Fore.GREEN + wfl.nameId + Fore.RESET))
690  counter +=1
691  print("Found %s compatible workflows inside %s" % (Fore.RED + str(counter) + Fore.RESET,
692  Fore.YELLOW + str(args[0])) + Fore.RESET)
693 
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 550 of file runTheMatrix.py.

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

550  def do_showWorkflow(self, arg):
551  if arg == '':
552  print("Available workflows:")
553  for k in self.matrices_.keys():
554  print(Fore.RED + Style.BRIGHT + k)
555  print(Style.RESET_ALL)
556  else:
557  selected = arg.split()
558  for k in selected:
559  if k not in self.matrices_.keys():
560  print("Unknown workflow %s: skipping" % k)
561  else:
562  for wfl in self.matrices_[k].workFlows:
563  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
564  Fore.GREEN + wfl.nameId + Fore.RESET))
565  print("%s contains %d workflows" % (Fore.RED + k + Fore.RESET, len(self.matrices_[k].workFlows)))
566 
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 707 of file runTheMatrix.py.

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

626  def help_runWorkflow(self):
627  print("\n".join(["runWorkflow workflow_class workflow_id\n",
628  "This command will launch a new and independent process that invokes",
629  "the command:\n",
630  "runTheMatrix.py -w workflow_class -l workflow_id [runTheMatrix.py options]",
631  "\nYou can specify just one workflow_class and workflow_id per invocation.",
632  "The job will continue even after quitting the interactive session.",
633  "stdout and stderr of the new process will be automatically",
634  "redirected to 2 logfiles whose names contain the workflow_class",
635  "and workflow_id. Mutiple command can be issued one after the other.",
636  "The working directory of the new process will be the directory",
637  "from which the interactive session has started.",
638  "Autocompletion is available for workflow_class, but",
639  "not for workflow_id. Supplying a wrong workflow_class or",
640  "a non-existing workflow_id for a valid workflow_class",
641  "will trigger an error and no process will be invoked.",
642  "The interactive shell will keep track of all active processes",
643  "and will prevent the accidental resubmission of an already",
644  "active jobs."]))
645 
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 694 of file runTheMatrix.py.

References join(), and print().

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

References join(), and print().

659  def help_searchInWorkflow(self):
660  print("\n".join(["searchInWorkflow wfl_name search_regexp\n",
661  "This command will search for a match within all workflows registered to wfl_name.",
662  "The search is done on both the workflow name and the names of steps registered to it."]))
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_showWorkflow()

def runTheMatrix.TheMatrix.help_showWorkflow (   self)

Definition at line 539 of file runTheMatrix.py.

References join(), and print().

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

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 480 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 485 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 481 of file runTheMatrix.py.