CMS 3D CMS Logo

DTCalibrationWorker.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from __future__ import absolute_import
3 import sys,os,time
4 import subprocess
5 from .tools import loadCmsProcess
6 from .DTWorkflow import DTWorkflow
7 from .DTTtrigWorkflow import DTttrigWorkflow
8 from .DTVdriftWorkflow import DTvdriftWorkflow
9 from .DTT0WireWorkflow import DTT0WireWorkflow
10 import logging
11 # setup logging
12 log = logging.getLogger(__name__)
13 
14 
16  """ This class serves as a top level helper to perform all available
17  workflows. Additional workflow classes should use the naming scheme
18  DT${WORKFLOWNAME}Workflow and implement a classmethod function add_parser_options.
19  """
20  available_workflows = ["ttrig","vdrift","T0Wire"]
21  def __init__(self, options):
22  self.options = options
23  if not self.has_crab3_env:
24  self.setup_crab_env()
25 
26  def run(self):
27  # get class object dependent on workflow
28  class_name = "DT" + self.options.workflow + "Workflow"
29  workflow_class = eval(class_name)
30  workflow_class_instance = workflow_class(self.options)
31  workflow_class_instance.run()
32  return workflow_class_instance.local_path
33 
34  @property
35  def has_crab3_env(self):
36  if not "/crabclient/3" in os.environ["PATH"]:
37  return False
38  return True
39 
40  def setup_crab_env(self):
41  # following
42  #http://.com/questions/3503719/emulating-bash-source-in-python
43  command = ['bash', '-c', 'unset module;source /cvmfs/cms.cern.ch/crab3/crab.sh && env']
44  proc = subprocess.Popen(command, executable = '/bin/bash', stdout = subprocess.PIPE)
45 
46  print('setting up crab')
47  for line in proc.stdout:
48  (key, _, value) = line.partition(b"=")
49  os.environ[key.decode()] = value.decode().replace("\n","")
50  for path in os.environ['PYTHONPATH'].split(':'):
51  sys.path.append(path)
52  proc.communicate()
53 
54  @classmethod
55  def add_arguments(cls, parser):
56  workflow_parser = DTWorkflow.add_parser_options(parser)
57  for workflow in cls.available_workflows:
58  class_name = "DT" + workflow + "Workflow"
59  try:
60  workflow_class = eval( class_name )
61  workflow_class.add_parser_options(workflow_parser)
62  except:
63  log.error("No class with name: %s exists but workflow exists in %s" %
64  (class_name, DTCalibrationWorker)
65  )
66 
def replace(string, replacements)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47