CMS 3D CMS Logo

CrabTask.py
Go to the documentation of this file.
1 from crabWrap import crabCreate,crabSubmit,crabWatch,getOutput
2 from tools import replaceTemplate
3 import os
4 #from threading import Thread
5 
6 #class CrabTask(Thread):
7 class CrabTask:
8  def __init__(self, dir, crab_cfg, pset=None, pset_name='mypset.py'):
9  #Thread.__init__(self)
10  self.dir = dir
11 
12  self.crabCfg_name = 'crab.cfg'
13  self.crab_cfg = crab_cfg
14 
15  self.pset_name = pset_name
16  self.pset = pset
17  self.initializeTask(dir=self.dir)
18 
19  def initializeTask(self, dir):
20  if not os.path.exists(dir): os.makedirs(dir)
21 
22  # Write pset
23  if self.pset:
24  self.crab_cfg.set('CMSSW','pset',self.pset_name)
25  open(dir + '/' + self.pset_name,'w').write(self.pset)
26 
27  # Write CRAB cfg
28  self.crab_cfg.write(open(dir + '/' + self.crabCfg_name,'w'))
29 
30  def create(self,dir):
31  self.project = crabCreate(dir,self.crabCfg_name)
32  return self.project
33 
34  def submit(self):
35  if not self.project: raise RuntimeError
36  crabSubmit(self.project)
37 
38  def getoutput(self):
39  if not self.project: raise RuntimeError
40  getOutput(self.project)
41 
42  #def watch(self):
43  # if not self.project: raise RuntimeError
44  # crabWatch(getOutput,self.project)
45 
46  def run(self):
47  #self.initializeTask(dir=self.dir)
48  proj = self.create(self.dir)
49  self.submit()
50  return proj
def create(self, dir)
Definition: CrabTask.py:30
def crabCreate(dir='.', crabCfg_name='crab.cfg')
Definition: crabWrap.py:137
def submit(self)
Definition: CrabTask.py:34
def crabSubmit(project)
Definition: crabWrap.py:150
def getoutput(self)
Definition: CrabTask.py:38
def initializeTask(self, dir)
Definition: CrabTask.py:19
def run(self)
Definition: CrabTask.py:46
def __init__(self, dir, crab_cfg, pset=None, pset_name='mypset.py')
Definition: CrabTask.py:8
def write(self, setup)
def getOutput(project)
Definition: crabWrap.py:230