Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:44

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