Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:29

0001 from __future__ import absolute_import
0002 import os
0003 import logging
0004 
0005 from . import tools
0006 import FWCore.ParameterSet.Config as cms
0007 from .DTWorkflow import DTWorkflow
0008 
0009 log = logging.getLogger(__name__)
0010 
0011 class DTvdriftWorkflow( DTWorkflow ):
0012     """ This class creates and performce / submits vdrift workflow jobs"""
0013     def __init__(self, options):
0014         # call parent constructor
0015         super( DTvdriftWorkflow, self ).__init__( options )
0016 
0017         self.outpath_command_tag = "VdriftCalibration"
0018         output_file_dict = { "segment" : "DTVDriftHistos.root",
0019                              "meantimer" : "DTTMaxHistos.root",
0020                             }
0021         self.outpath_workflow_mode_dict = { "segment" : "Segments",
0022                                             "meantimer" : "MeanTimer",
0023                                             }
0024         self.output_file = output_file_dict[self.options.workflow_mode]
0025         self.output_files = [self.output_file]
0026 
0027     def prepare_workflow(self):
0028         """ Generalized function to prepare workflow dependent on workflow mode"""
0029         function_name = "prepare_" + self.options.workflow_mode + "_" + self.options.command
0030 
0031         try:
0032             fill_function = getattr(self, function_name)
0033         except AttributeError:
0034             errmsg = "Class `{}` does not implement `{}`"
0035             raise NotImplementedError( errmsg.format(self.__class__.__name__,
0036                                                      function_name))
0037         log.debug("Preparing workflow with function %s" % function_name)
0038         # call chosen function
0039         fill_function()
0040 
0041     def prepare_segment_submit(self):
0042         self.pset_name = 'dtVDriftSegmentCalibration_cfg.py'
0043         self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentCalibration_cfg'
0044         if self.options.datasettype == "Cosmics":
0045             self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentCalibration_cosmics_cfg'
0046 
0047         self.process = tools.loadCmsProcess(self.pset_template)
0048         self.process.GlobalTag.globaltag = self.options.globaltag
0049         self.process.dtVDriftSegmentCalibration.rootFileName = self.output_file
0050 
0051         if self.options.inputCalibDB:
0052             err = "Option inputCalibDB not available for segment."
0053             err += "Maybe you want to use option inputTtrigDB"
0054             raise ValueError(err)
0055         self.prepare_common_submit()
0056         if self.options.inputTtrigDB:
0057             label = ''
0058             if self.options.datasettype == "Cosmics":
0059                 label = 'cosmics'
0060             connect = os.path.basename(self.options.inputTtrigDB)
0061             self.addPoolDBESSource( process = self.process,
0062                                     moduleName = 'tTrigDB',
0063                                     record = 'DTTtrigRcd',
0064                                     tag = 'ttrig',
0065                                     connect = str("sqlite_file:%s" % connect),
0066                                     label = label
0067                                     )
0068             self.input_files.append( os.path.abspath(self.options.inputTtrigDB) )
0069         self.write_pset_file()
0070 
0071     def prepare_segment_check(self):
0072         self.load_options_command("submit")
0073 
0074     def prepare_segment_write(self):
0075         self.pset_name = 'dtVDriftSegmentWriter_cfg.py'
0076         self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentWriter_cfg'
0077         tag = self.prepare_common_write()
0078         merged_file = os.path.join(self.result_path, self.output_file)
0079         self.process = tools.loadCmsProcess(self.pset_template)
0080 
0081         if self.options.inputVDriftDB:
0082             self.add_local_vdrift_db(self)
0083         vdrift_db = "vDrift_segment"+ tag + ".db"
0084         vdrift_db = os.path.join(self.result_path, vdrift_db)
0085         self.process.dtVDriftSegmentWriter.vDriftAlgoConfig.rootFileName = "file:///" + merged_file
0086         self.process.PoolDBOutputService.connect = 'sqlite_file:%s' % vdrift_db
0087         self.process.source.firstRun = cms.untracked.uint32(self.options.run)
0088         self.process.GlobalTag.globaltag = cms.string(str(self.options.globaltag))
0089         self.write_pset_file()
0090 
0091     def prepare_segment_dump(self):
0092         self.pset_name = 'dumpDBToFile_vdrift_cfg.py'
0093         self.pset_template = 'CalibMuon.DTCalibration.dumpDBToFile_vdrift_cfg'
0094         if self.options.input_dumpDB:
0095             try:
0096                 test = self.result_path
0097                 self.load_options_command("write")
0098             except:
0099                 pass
0100             dbpath = os.path.abspath(self.options.input_dumpDB)
0101         else:
0102             crabtask = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
0103                                                initUpdate = False)
0104             tag = crabtask.crabConfig.Data.outputDatasetTag
0105             dbpath = os.path.abspath( os.path.join(self.result_path,
0106                                                    "vDrift_segment"+ tag + ".db"))
0107         self.prepare_common_dump(dbpath)
0108         self.write_pset_file()
0109 
0110     def prepare_segment_all(self):
0111         # individual prepare functions for all tasks will be called in
0112         # main implementation of all
0113         self.all_commands=["submit", "check", "write", "dump"]
0114 
0115     ####################################################################
0116     #                            Mean Timer                            #
0117     ####################################################################
0118     def prepare_meantimer_submit(self):
0119         self.pset_name = 'dtVDriftMeanTimerCalibration_cfg.py'
0120         self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerCalibration_cfg'
0121         if self.options.datasettype == "Cosmics":
0122             self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerCalibration_cosmics_cfg'
0123 
0124         self.process = tools.loadCmsProcess(self.pset_template)
0125         self.process.GlobalTag.globaltag = self.options.globaltag
0126         self.process.dtVDriftMeanTimerCalibration.rootFileName = self.output_file
0127 
0128         if self.options.inputCalibDB:
0129             err = "Option inputCalibDB not available for meantimer."
0130             err += "Maybe you want to use option inputTtrigDB"
0131             raise ValueError(err)
0132         self.prepare_common_submit()
0133         if self.options.inputTtrigDB:
0134             label = ''
0135             if self.options.datasettype == "Cosmics":
0136                 label = 'cosmics'
0137             connect = os.path.basename(self.options.inputTtrigDB)
0138             self.addPoolDBESSource( process = self.process,
0139                                     moduleName = 'tTrigDB',
0140                                     record = 'DTTtrigRcd',
0141                                     tag = 'ttrig',
0142                                     connect = str("sqlite_file:%s" % connect),
0143                                     label = label
0144                                     )
0145             self.input_files.append( os.path.abspath(self.options.inputTtrigDB) )
0146         self.write_pset_file()
0147 
0148     def prepare_meantimer_check(self):
0149         self.load_options_command("submit")
0150 
0151     def prepare_meantimer_write(self):
0152         self.pset_name = 'dtVDriftMeanTimerWriter_cfg.py'
0153         self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerWriter_cfg'
0154         tag = self.prepare_common_write()
0155         merged_file = os.path.join(self.result_path, self.output_file)
0156         self.process = tools.loadCmsProcess(self.pset_template)
0157 
0158         if self.options.inputVDriftDB:
0159             self.add_local_vdrift_db(self)
0160         vdrift_db = "vDrift_meantimer" + tag + ".db"
0161         vdrift_db = os.path.join(self.result_path, vdrift_db)
0162         self.process.dtVDriftMeanTimerWriter.vDriftAlgoConfig.rootFileName = "file:///" + merged_file
0163         self.process.PoolDBOutputService.connect = 'sqlite_file:%s' % vdrift_db
0164         self.process.source.firstRun = cms.untracked.uint32(self.options.run)
0165         self.process.GlobalTag.globaltag = cms.string(str(self.options.globaltag))
0166         self.write_pset_file()
0167 
0168     def prepare_meantimer_dump(self):
0169         self.pset_name = 'dumpDBToFile_vdrift_cfg.py'
0170         self.pset_template = 'CalibMuon.DTCalibration.dumpDBToFile_vdrift_cfg'
0171         if self.options.input_dumpDB:
0172             try:
0173                 test = self.result_path
0174                 self.load_options_command("write")
0175             except:
0176                 pass
0177             dbpath = os.path.abspath(self.options.input_dumpDB)
0178         else:
0179             crabtask = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
0180                                                initUpdate = False)
0181             tag = crabtask.crabConfig.Data.outputDatasetTag
0182             dbpath = os.path.abspath( os.path.join(self.result_path,
0183                                                    "vDrift_meantimer" + tag + ".db"))
0184         self.prepare_common_dump(dbpath)
0185         self.write_pset_file()
0186 
0187     def prepare_meantimer_all(self):
0188         # individual prepare functions for all tasks will be called in
0189         # main implementation of all
0190         self.all_commands=["submit", "check", "write", "dump"]
0191 
0192     ####################################################################
0193     #                           CLI creation                           #
0194     ####################################################################
0195     @classmethod
0196     def add_parser_options(cls, subparser_container):
0197         vdrift_parser = subparser_container.add_parser( "vdrift",
0198         #parents=[mutual_parent_parser, common_parent_parser],
0199         help = "" ) # What does ttrig
0200 
0201         ################################################################
0202         #                Sub parser options for workflow modes         #
0203         ################################################################
0204         vdrift_subparsers = vdrift_parser.add_subparsers( dest="workflow_mode",
0205             help="Possible workflow modes",)
0206         ## Add all workflow modes for ttrig
0207         vdrift_segment_subparser = vdrift_subparsers.add_parser( "segment",
0208             #parents=[mutual_parent_parser, common_parent_parser],
0209             help = "" )
0210         vdrift_meantimer_subparser = vdrift_subparsers.add_parser( "meantimer",
0211             #parents=[mutual_parent_parser, common_parent_parser],
0212             help = "" )
0213         ################################################################
0214         #        Sub parser options for workflow mode segment          #
0215         ################################################################
0216         vdrift_segment_subparsers = vdrift_segment_subparser.add_subparsers( dest="command",
0217             help="Possible commands for segments")
0218         vdrift_segment_submit_parser = vdrift_segment_subparsers.add_parser(
0219             "submit",
0220             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0221                     super(DTvdriftWorkflow,cls).get_submission_options_parser(),
0222                     super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
0223                     super(DTvdriftWorkflow,cls).get_input_db_options_parser()],
0224             help = "Submit job to the GRID via crab3")
0225         vdrift_segment_submit_parser.add_argument("--inputTtrigDB",
0226             help="Local alternative calib ttrig db")
0227 
0228         vdrift_segment_check_parser = vdrift_segment_subparsers.add_parser(
0229             "check",
0230             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0231                     super(DTvdriftWorkflow,cls).get_check_options_parser()],
0232             help = "Check status of submitted jobs")
0233 
0234         vdrift_segment_write_parser = vdrift_segment_subparsers.add_parser(
0235             "write",
0236             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0237                      super(DTvdriftWorkflow,cls).get_write_options_parser()
0238                     ],
0239             help = "Write result from root output to text file")
0240 
0241         vdrift_segment_dump_parser = vdrift_segment_subparsers.add_parser(
0242             "dump",
0243             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0244                      super(DTvdriftWorkflow,cls).get_dump_options_parser()],
0245             help = "Dump database to text file")
0246 
0247         vdrift_segment_all_parser = vdrift_segment_subparsers.add_parser(
0248             "all",
0249             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0250                      super(DTvdriftWorkflow,cls).get_submission_options_parser(),
0251                      super(DTvdriftWorkflow,cls).get_check_options_parser(),
0252                      super(DTvdriftWorkflow,cls).get_input_db_options_parser(),
0253                      super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
0254                      super(DTvdriftWorkflow,cls).get_write_options_parser(),
0255                      super(DTvdriftWorkflow,cls).get_dump_options_parser()
0256                     ],
0257             help = "Perform all steps: submit, check, write, dump in this order")
0258         vdrift_segment_all_parser.add_argument("--inputTtrigDB",
0259             help="Local alternative calib ttrig db")
0260         ################################################################
0261         #       Sub parser options for workflow mode meantimer         #
0262         ################################################################
0263         vdrift_meantimer_subparsers = vdrift_meantimer_subparser.add_subparsers( dest="command",
0264             help="Possible commands for meantimers")
0265         vdrift_meantimer_submit_parser = vdrift_meantimer_subparsers.add_parser(
0266             "submit",
0267             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0268                     super(DTvdriftWorkflow,cls).get_submission_options_parser(),
0269                     super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
0270                     super(DTvdriftWorkflow,cls).get_input_db_options_parser()],
0271             help = "Submit job to the GRID via crab3")
0272         vdrift_meantimer_submit_parser.add_argument("--inputTtrigDB",
0273             help="Local alternative calib ttrig db")
0274 
0275         vdrift_meantimer_check_parser = vdrift_meantimer_subparsers.add_parser(
0276             "check",
0277             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0278                     super(DTvdriftWorkflow,cls).get_check_options_parser()],
0279             help = "Check status of submitted jobs")
0280 
0281         vdrift_meantimer_write_parser = vdrift_meantimer_subparsers.add_parser(
0282             "write",
0283             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0284                      super(DTvdriftWorkflow,cls).get_write_options_parser()
0285                     ],
0286             help = "Write result from root output to text file")
0287 
0288         vdrift_meantimer_dump_parser = vdrift_meantimer_subparsers.add_parser(
0289             "dump",
0290             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0291                      super(DTvdriftWorkflow,cls).get_dump_options_parser()],
0292             help = "Dump database to text file")
0293 
0294         vdrift_meantimer_all_parser = vdrift_meantimer_subparsers.add_parser(
0295             "all",
0296             parents=[super(DTvdriftWorkflow,cls).get_common_options_parser(),
0297                      super(DTvdriftWorkflow,cls).get_submission_options_parser(),
0298                      super(DTvdriftWorkflow,cls).get_check_options_parser(),
0299                      super(DTvdriftWorkflow,cls).get_input_db_options_parser(),
0300                      super(DTvdriftWorkflow,cls).get_local_input_db_options_parser(),
0301                      super(DTvdriftWorkflow,cls).get_write_options_parser(),
0302                      super(DTvdriftWorkflow,cls).get_dump_options_parser()
0303                     ],
0304             help = "Perform all steps: submit, check, write, dump in this order")
0305         vdrift_meantimer_all_parser.add_argument("--inputTtrigDB",
0306             help="Local alternative calib ttrig db")