1 from threading
import Thread
2 from Configuration.PyReleaseValidation
import WorkFlow
5 from subprocess
import Popen
6 from os.path
import exists, basename, join
7 from datetime
import datetime
10 def __init__(self, wf, noRun=False,dryRun=False,cafVeto=True,dasOptions="",jobReport=False, nThreads=1, maxSteps=9999):
26 self.
wfDir=
str(self.wf.numId)+
'_'+self.wf.nameId
31 msg =
"\n# in: " +os.getcwd()
32 if self.
dryRun: msg +=
" dryRun for '" 33 else: msg +=
" going to execute " 34 msg += cmd.replace(
';',
'\n')
37 cmdLog = open(self.
wfDir+
'/cmdLog',
'a')
38 cmdLog.write(msg+
'\n')
43 p = Popen(cmd, shell=
True)
44 ret = os.waitpid(p.pid, 0)[1]
46 print "ERROR executing ",cmd,
'ret=', ret
52 startDir = os.getcwd()
54 if not os.path.exists(self.
wfDir):
55 os.makedirs(self.
wfDir)
57 print "cleaning up ", self.
wfDir,
' in ', os.getcwd()
58 shutil.rmtree(self.
wfDir)
59 os.makedirs(self.
wfDir)
61 preamble =
'cd '+self.
wfDir+
'; ' 63 realstarttime = datetime.now()
64 startime=
'date %s' %time.asctime()
68 if 'cms/caf/cms' in os.environ[
'CMS_PATH']:
79 return ' > %s 2>&1; ' % (
'step%d_'%(i,)+ID+
'.log ',)
84 for (istepmone,com)
in enumerate(self.wf.cmds):
94 self.retStep.append(0)
95 self.stat.append(
'NOTRUN')
97 if not isinstance(com,str):
98 if self.
cafVeto and (com.location ==
'CAF' and not onCAF):
99 print "You need to be no CAF to run",self.wf.numId
102 self.retStep.append(0)
103 self.stat.append(
'NOTRUN')
107 cmd2 = com.lumiRanges()
109 cmd2 =cmd+cmd2+closeCmd(istep,
'lumiRanges')
110 lumiRangeFile=
'step%d_lumiRanges.log'%(istep,)
111 retStep = self.
doCmd(cmd2)
112 if (com.dataSetParent):
113 cmd3=cmd+com.das(self.
dasOptions,com.dataSetParent)+closeCmd(istep,
'dasparentquery')
114 retStep = self.
doCmd(cmd3)
116 cmd+=closeCmd(istep,
'dasquery')
117 retStep = self.
doCmd(cmd)
121 dasOutputPath =
join(self.
wfDir,
'step%d_dasquery.log'%(istep,))
122 if not exists(dasOutputPath):
128 dasOutput = [l
for l
in open(dasOutputPath).read().
split(
"\n")
if l.startswith(
"/")]
133 inFile =
'filelist:' +
basename(dasOutputPath)
142 if inFile
and not 'premix_stage1' in cmd:
143 cmd +=
' --filein '+inFile
146 cmd +=
' --lumiToProcess '+lumiRangeFile
149 if 'HARVESTING' in cmd
and not 134==self.wf.numId
and not '--filein' in cmd:
150 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
154 if istep!=1
and not '--filein' in cmd
and not 'premix_stage1' in cmd:
155 cmd+=
' --filein file:step%s.root '%(istep-1,)
156 if not '--fileout' in com:
157 cmd+=
' --fileout file:step%s.root '%(istep,)
159 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
160 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
161 cmd +=
' --nThreads %s' % self.
nThreads 162 cmd+=closeCmd(istep,self.wf.nameId)
165 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
166 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
168 else: retStep = self.
doCmd(cmd)
170 self.retStep.append(retStep)
175 self.stat.append(
'TIMEOUT')
182 self.stat.append(
"DAS_ERROR")
184 self.stat.append(
'FAILED')
191 self.stat.append(
'PASSED')
194 endtime=
'date %s' %time.asctime()
195 tottime=
'%s-%s'%(endtime,startime)
201 for i,s
in enumerate(self.
stat):
202 logStat+=
'Step%d-%s '%(i,s)
203 self.
report=
'%s_%s %s - time %s; exit: '%(self.wf.numId,self.wf.nameId,logStat,tottime)+
' '.
join(
map(str,self.
retStep))+
'\n'
def __init__(self, wf, noRun=False, dryRun=False, cafVeto=True, dasOptions="", jobReport=False, nThreads=1, maxSteps=9999)
static std::string join(char **cmd)
npass
needs to set self.report