CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CalibMuon/DTCalibration/python/Workflow/DTResidualCalibration.py

Go to the documentation of this file.
00001 from tools import loadCmsProcess,loadCrabCfg,loadCrabDefault,addCrabInputFile,writeCfg,prependPaths
00002 from addPoolDBESSource import addPoolDBESSource
00003 from CrabTask import *
00004 import os
00005 
00006 class DTResidualCalibration:
00007     def __init__(self, run, dir, input_db, config):
00008         self.pset_name = 'dtResidualCalibration_cfg.py'
00009         self.outputfile = 'residuals.root'
00010         self.config = config
00011         self.dir = dir
00012         self.inputdb = input_db
00013 
00014         self.pset_template = 'CalibMuon.DTCalibration.dtResidualCalibration_cfg'
00015         if hasattr(self.config,'runOnCosmics') and self.config.runOnCosmics:
00016             self.pset_template = 'CalibMuon.DTCalibration.dtResidualCalibration_cosmics_cfg'
00017 
00018         self.process = None  
00019         self.crab_cfg = None
00020         self.initProcess()
00021         self.initCrab()
00022         self.task = CrabTask(self.dir,self.crab_cfg)
00023 
00024     def initProcess(self):
00025         self.process = loadCmsProcess(self.pset_template)
00026         self.process.GlobalTag.globaltag = self.config.globaltag
00027         self.process.dtResidualCalibration.rootFileName = self.outputfile 
00028 
00029         if hasattr(self.config,'inputVDriftDB') and self.config.inputVDriftDB:
00030             addPoolDBESSource(process = self.process,
00031                               moduleName = 'vDriftDB',record = 'DTMtimeRcd',tag = 'vDrift',
00032                               connect = 'sqlite_file:%s' % os.path.basename(self.config.inputVDriftDB))
00033 
00034         if hasattr(self.config,'inputDBTag') and self.config.inputDBTag:
00035             tag = self.config.inputDBTag
00036             record = self.config.inputDBRcd
00037             connect = self.config.connectStrDBTag
00038             moduleName = 'customDB%s' % record 
00039             addPoolDBESSource(process = self.process,
00040                               moduleName = moduleName,record = record,tag = tag,
00041                               connect = connect)
00042 
00043         if(self.inputdb):
00044             label = ''
00045             if hasattr(self.config,'runOnCosmics') and self.config.runOnCosmics: label = 'cosmics'
00046             addPoolDBESSource(process = self.process,
00047                               moduleName = 'calibDB',record = 'DTTtrigRcd',tag = 'ttrig',label = label,
00048                               connect = 'sqlite_file:%s' % os.path.basename(self.inputdb))
00049 
00050         if hasattr(self.config,'runOnRAW') and self.config.runOnRAW:
00051             if hasattr(self.config,'runOnMC') and self.config.runOnMC:
00052                 getattr(self.process,self.config.digilabel).inputLabel = 'rawDataCollector' 
00053             prependPaths(self.process,self.config.digilabel)
00054  
00055         if hasattr(self.config,'preselection') and self.config.preselection:
00056             pathsequence = self.config.preselection.split(':')[0]
00057             seqname = self.config.preselection.split(':')[1]
00058             self.process.load(pathsequence)
00059             prependPaths(self.process,seqname)
00060 
00061     def initCrab(self):
00062         crab_cfg_parser = loadCrabCfg()
00063         loadCrabDefault(crab_cfg_parser,self.config)
00064         crab_cfg_parser.set('CMSSW','pset',self.pset_name)
00065         crab_cfg_parser.set('CMSSW','output_file',self.outputfile)
00066         crab_cfg_parser.remove_option('USER','additional_input_files')
00067         if self.inputdb:
00068             addCrabInputFile(crab_cfg_parser,self.inputdb)
00069 
00070         if hasattr(self.config,'inputVDriftDB') and self.config.inputVDriftDB:
00071             addCrabInputFile(crab_cfg_parser,self.config.inputVDriftDB)
00072 
00073         self.crab_cfg = crab_cfg_parser
00074 
00075     def writeCfg(self):
00076         writeCfg(self.process,self.dir,self.pset_name)
00077         #writeCfgPkl(self.process,self.dir,self.pset_name)
00078 
00079     def run(self):
00080         self.project = self.task.run()
00081         return self.project