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)
141 cmd +=
' --filein '+inFile
144 cmd +=
' --lumiToProcess '+lumiRangeFile
147 if 'HARVESTING' in cmd
and not 134==self.wf.numId
and not '--filein' in cmd:
148 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
150 if istep!=1
and not '--filein' in cmd:
151 cmd+=
' --filein file:step%s.root '%(istep-1,)
152 if not '--fileout' in com:
153 cmd+=
' --fileout file:step%s.root '%(istep,)
155 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
156 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd) :
157 cmd +=
' --nThreads %s' % self.
nThreads 158 cmd+=closeCmd(istep,self.wf.nameId)
161 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
162 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
164 else: retStep = self.
doCmd(cmd)
166 self.retStep.append(retStep)
171 self.stat.append(
'TIMEOUT')
178 self.stat.append(
"DAS_ERROR")
180 self.stat.append(
'FAILED')
187 self.stat.append(
'PASSED')
190 endtime=
'date %s' %time.asctime()
191 tottime=
'%s-%s'%(endtime,startime)
197 for i,s
in enumerate(self.
stat):
198 logStat+=
'Step%d-%s '%(i,s)
199 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