File indexing completed on 2025-05-29 03:17:18
0001 import sys,os,time
0002 import subprocess
0003 from .tools import loadCmsProcess
0004 from .DTWorkflow import DTWorkflow
0005 from .DTTtrigWorkflow import DTttrigWorkflow
0006 from .DTVdriftWorkflow import DTvdriftWorkflow
0007 from .DTT0WireWorkflow import DTT0WireWorkflow
0008 import logging
0009
0010 log = logging.getLogger(__name__)
0011
0012
0013 class DTCalibrationWorker(object):
0014 """ This class serves as a top level helper to perform all available
0015 workflows. Additional workflow classes should use the naming scheme
0016 DT${WORKFLOWNAME}Workflow and implement a classmethod function add_parser_options.
0017 """
0018 available_workflows = ["ttrig","vdrift","T0Wire"]
0019 def __init__(self, options):
0020 self.options = options
0021 if not self.has_crab3_env:
0022 self.setup_crab_env()
0023
0024 def run(self):
0025
0026 class_name = "DT" + self.options.workflow + "Workflow"
0027 workflow_class = eval(class_name)
0028 workflow_class_instance = workflow_class(self.options)
0029 workflow_class_instance.run()
0030 return workflow_class_instance.local_path
0031
0032 @property
0033 def has_crab3_env(self):
0034 if not "/crabclient/3" in os.environ["PATH"]:
0035 return False
0036 return True
0037
0038 def setup_crab_env(self):
0039 log.info('Setting up crab environment')
0040
0041
0042 command = ['bash', '-c', 'unset module;source /cvmfs/cms.cern.ch/crab3/crab.sh && env']
0043 proc = subprocess.Popen(command, executable = '/bin/bash', stdout = subprocess.PIPE)
0044
0045 for line in proc.stdout:
0046 (key, _, value) = line.partition(b"=")
0047 os.environ[key.decode()] = value.decode().replace("\n","")
0048 for path in os.environ['PYTHONPATH'].split(':'):
0049 sys.path.append(path)
0050 proc.communicate()
0051
0052 @classmethod
0053 def add_arguments(cls, parser):
0054 workflow_parser = DTWorkflow.add_parser_options(parser)
0055 for workflow in cls.available_workflows:
0056 class_name = "DT" + workflow + "Workflow"
0057 try:
0058 workflow_class = eval( class_name )
0059 workflow_class.add_parser_options(workflow_parser)
0060 except:
0061 log.error("No class with name: %s exists but workflow exists in %s" %
0062 (class_name, DTCalibrationWorker)
0063 )
0064