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

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 498 of file runTheMatrix.py.

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

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

◆ complete_runWorkflow()

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

Definition at line 635 of file runTheMatrix.py.

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

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

◆ complete_searchInWorkflow()

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

Definition at line 679 of file runTheMatrix.py.

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

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

◆ complete_showWorkflow()

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

Definition at line 559 of file runTheMatrix.py.

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

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

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 520 of file runTheMatrix.py.

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

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

512  def do_clear(self, arg):
513  """Clear the screen, put prompt at the top"""
514  os.system("clear")
515 

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 726 of file runTheMatrix.py.

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

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

References print().

Referenced by runTheMatrix.TheMatrix.default().

516  def do_exit(self, arg):
517  print("Leaving the Matrix")
518  return True
519 
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 661 of file runTheMatrix.py.

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

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

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

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

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

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

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

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

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

Referenced by runTheMatrix.TheMatrix.do_search().

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

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

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

References join(), and print().

722  def help_dumpWorkflowId(self):
723  print("\n".join(["dumpWorkflowId [wfl-id1 [...]]\n",
724  "Dumps the details (cmsDriver commands for all steps) of the space-separated workflow-ids in input."]))
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:21

◆ help_jobs()

def runTheMatrix.TheMatrix.help_jobs (   self)

Definition at line 670 of file runTheMatrix.py.

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

def runTheMatrix.TheMatrix.help_search (   self)

Definition at line 709 of file runTheMatrix.py.

References join(), and print().

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

References join(), and print().

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

◆ help_showWorkflow()

def runTheMatrix.TheMatrix.help_showWorkflow (   self)

Definition at line 554 of file runTheMatrix.py.

References join(), and print().

554  def help_showWorkflow(self):
555  print("\n".join(["showWorkflow [workflow1 [...]]\n",
556  "Run w/o arguments, it will print the list of registered macro-workflows.",
557  "Run with space-separated workflows, it will print the full list of workflow-ids registered to them"]))
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:21

Member Data Documentation

◆ do_EOF

runTheMatrix.TheMatrix.do_EOF
static

Definition at line 749 of file runTheMatrix.py.

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 495 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 500 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 496 of file runTheMatrix.py.