CMS 3D CMS Logo

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