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