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

Constructor & Destructor Documentation

◆ __init__()

def runTheMatrix.TheMatrix.__init__ (   self,
  opt 
)

Definition at line 475 of file runTheMatrix.py.

475  def __init__(self, opt):
476  cmd.Cmd.__init__(self)
477  self.opt_ = opt
478  self.matrices_ = {}
479  tmp = MatrixReader(self.opt_)
480  self.processes_ = dict()
481  for what in tmp.files:
482  what = what.replace('relval_','')
483  self.opt_.what = what
484  self.matrices_[what] = MatrixReader(self.opt_)
485  self.matrices_[what].prepare(self.opt_.useInput, self.opt_.refRel,
486  self.opt_.fromScratch)
487  os.system("clear")
488 
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 512 of file runTheMatrix.py.

512  def complete_predefined(self, text, line, start_idx, end_idx):
513  if text and len(text) > 0:
514  return [t for t in predefinedSet.keys() if t.startswith(text)]
515  else:
516  return predefinedSet.keys()
517 

◆ complete_runWorkflow()

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

Definition at line 612 of file runTheMatrix.py.

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

612  def complete_runWorkflow(self, text, line, start_idx, end_idx):
613  if text and len(text) > 0:
614  return [t for t in self.matrices_.keys() if t.startswith(text)]
615  else:
616  return self.matrices_.keys()
617 

◆ complete_searchInWorkflow()

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

Definition at line 656 of file runTheMatrix.py.

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

656  def complete_searchInWorkflow(self, text, line, start_idx, end_idx):
657  if text and len(text) > 0:
658  return [t for t in self.matrices_.keys() if t.startswith(text)]
659  else:
660  return self.matrices_.keys()
661 

◆ complete_showWorkflow()

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

Definition at line 536 of file runTheMatrix.py.

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

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

◆ default()

def runTheMatrix.TheMatrix.default (   self,
  inp 
)

Definition at line 497 of file runTheMatrix.py.

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

497  def default(self, inp):
498  if inp == 'x' or inp == 'q':
499  return self.do_exit(inp)
500  else:
501  is_pipe = not isatty(sys.stdin.fileno())
502  print(Fore.RED + "Error: " + Fore.RESET + "unrecognized command.")
503  # Quit only if given a piped command.
504  if is_pipe:
505  sys.exit(1)
506 
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 489 of file runTheMatrix.py.

489  def do_clear(self, arg):
490  """Clear the screen, put prompt at the top"""
491  os.system("clear")
492 

◆ do_dumpWorkflowId()

def runTheMatrix.TheMatrix.do_dumpWorkflowId (   self,
  arg 
)

Definition at line 703 of file runTheMatrix.py.

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

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

References print().

Referenced by runTheMatrix.TheMatrix.default().

493  def do_exit(self, arg):
494  print("Leaving the Matrix")
495  return True
496 
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 638 of file runTheMatrix.py.

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

638  def do_jobs(self, args):
639  print(Fore.GREEN + Style.BRIGHT + "List of jobs:")
640  for w in self.processes_.keys():
641  if self.processes_[w][0].poll() is None:
642  print(Fore.YELLOW + Style.BRIGHT + "Active job: {} since {:.2f} seconds.".format(w, time.time() - self.processes_[w][1]))
643  else:
644  print(Fore.RED + Style.BRIGHT + "Done job: {}".format(w))
645  print(Style.RESET_ALL)
646 
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 518 of file runTheMatrix.py.

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

518  def do_predefined(self, arg):
519  """Print the list of predefined workflows"""
520  print("List of predefined workflows")
521  if arg:
522  for w in arg.split():
523  if w in predefinedSet.keys():
524  print("Predefined Set: %s" % w)
525  print(predefinedSet[w])
526  else:
527  print("Unknown Set: %s" % w)
528  else:
529  print("[ " + Fore.RED + ", ".join([str(k) for k in predefinedSet.keys()]) + Fore.RESET + " ]")
530 
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 559 of file runTheMatrix.py.

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

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

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

691  def do_search(self, arg):
692  args = arg.split()
693  if len(args) < 1:
694  print("search regexp")
695  return
696  for wfl in self.matrices_.keys():
697  self.do_searchInWorkflow(' '.join([wfl, args[0]]))
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:19

◆ do_searchInWorkflow()

def runTheMatrix.TheMatrix.do_searchInWorkflow (   self,
  arg 
)

Definition at line 662 of file runTheMatrix.py.

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

Referenced by runTheMatrix.TheMatrix.do_search().

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

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

542  def do_showWorkflow(self, arg):
543  if arg == '':
544  print("Available workflows:")
545  for k in self.matrices_.keys():
546  print(Fore.RED + Style.BRIGHT + k)
547  print(Style.RESET_ALL)
548  else:
549  selected = arg.split()
550  for k in selected:
551  if k not in self.matrices_.keys():
552  print("Unknown workflow %s: skipping" % k)
553  else:
554  for wfl in self.matrices_[k].workFlows:
555  print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
556  Fore.GREEN + wfl.nameId + Fore.RESET))
557  print("%s contains %d workflows" % (Fore.RED + k + Fore.RESET, len(self.matrices_[k].workFlows)))
558 
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 699 of file runTheMatrix.py.

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

References join(), and print().

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

◆ intro

runTheMatrix.TheMatrix.intro
static

Definition at line 472 of file runTheMatrix.py.

◆ matrices_

runTheMatrix.TheMatrix.matrices_

◆ opt_

runTheMatrix.TheMatrix.opt_

Definition at line 477 of file runTheMatrix.py.

◆ processes_

runTheMatrix.TheMatrix.processes_

◆ prompt

runTheMatrix.TheMatrix.prompt
static

Definition at line 473 of file runTheMatrix.py.