CMS 3D CMS Logo

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