CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 from crabWrap import crabCreate,crabSubmit,crabWatch,getOutput
00002 from tools import replaceTemplate
00003 import os
00004 #from threading import Thread
00005 
00006 #class CrabTask(Thread):
00007 class CrabTask:
00008     def __init__(self, dir, crab_cfg, pset=None, pset_name='mypset.py'):
00009         #Thread.__init__(self)
00010         self.dir = dir
00011   
00012         self.crabCfg_name = 'crab.cfg'
00013         self.crab_cfg = crab_cfg
00014   
00015         self.pset_name = pset_name
00016         self.pset = pset
00017         self.initializeTask(dir=self.dir)
00018 
00019     def initializeTask(self, dir):
00020         if not os.path.exists(dir): os.makedirs(dir)
00021 
00022         # Write pset 
00023         if self.pset:
00024             self.crab_cfg.set('CMSSW','pset',self.pset_name)
00025             open(dir + '/' + self.pset_name,'w').write(self.pset) 
00026 
00027         # Write CRAB cfg
00028         self.crab_cfg.write(open(dir + '/' + self.crabCfg_name,'w'))
00029          
00030     def create(self,dir):
00031         self.project = crabCreate(dir,self.crabCfg_name)
00032         return self.project
00033 
00034     def submit(self):
00035         if not self.project: raise RuntimeError
00036         crabSubmit(self.project)
00037 
00038     def getoutput(self):
00039         if not self.project: raise RuntimeError
00040         getOutput(self.project)
00041 
00042     #def watch(self):
00043     #    if not self.project: raise RuntimeError
00044     #    crabWatch(getOutput,self.project) 
00045         
00046     def run(self):
00047         #self.initializeTask(dir=self.dir)
00048         proj = self.create(self.dir) 
00049         self.submit()
00050         return proj