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

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 503 of file runTheMatrix.py.

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

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

◆ complete_runWorkflow()

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

Definition at line 640 of file runTheMatrix.py.

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

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

◆ complete_searchInWorkflow()

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

Definition at line 684 of file runTheMatrix.py.

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

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

◆ complete_showWorkflow()

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

Definition at line 564 of file runTheMatrix.py.

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

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

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 525 of file runTheMatrix.py.

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

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

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

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 731 of file runTheMatrix.py.

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

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

References print().

Referenced by runTheMatrix.TheMatrix.default().

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

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

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

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

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

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

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

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

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

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

Referenced by runTheMatrix.TheMatrix.do_search().

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

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

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 500 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 505 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 501 of file runTheMatrix.py.