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)
113 cmd+=closeCmd(istep,
'dasquery')
114 retStep = self.
doCmd(cmd)
118 dasOutputPath =
join(self.
wfDir,
'step%d_dasquery.log'%(istep,))
119 if not exists(dasOutputPath):
125 dasOutput = [l
for l
in open(dasOutputPath).read().
split(
"\n")
if l.startswith(
"/")]
130 inFile =
'filelist:' +
basename(dasOutputPath)
138 cmd +=
' --filein '+inFile
141 cmd +=
' --lumiToProcess '+lumiRangeFile
144 if 'HARVESTING' in cmd
and not 134==self.wf.numId
and not '--filein' in cmd:
145 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
147 if istep!=1
and not '--filein' in cmd:
148 cmd+=
' --filein file:step%s.root '%(istep-1,)
149 if not '--fileout' in com:
150 cmd+=
' --fileout file:step%s.root '%(istep,)
152 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
153 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd) :
154 cmd +=
' --nThreads %s' % self.
nThreads 155 cmd+=closeCmd(istep,self.wf.nameId)
158 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
159 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
161 else: retStep = self.
doCmd(cmd)
163 self.retStep.append(retStep)
168 self.stat.append(
'TIMEOUT')
175 self.stat.append(
"DAS_ERROR")
177 self.stat.append(
'FAILED')
184 self.stat.append(
'PASSED')
187 endtime=
'date %s' %time.asctime()
188 tottime=
'%s-%s'%(endtime,startime)
194 for i,s
in enumerate(self.
stat):
195 logStat+=
'Step%d-%s '%(i,s)
196 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