1 from __future__
import print_function
2 from threading
import Thread
3 from Configuration.PyReleaseValidation
import WorkFlow
6 from subprocess
import Popen
7 from os.path
import exists, basename, join
8 from datetime
import datetime
11 def __init__(self, wf, noRun=False,dryRun=False,cafVeto=True,dasOptions="",jobReport=False, nThreads=1, nStreams=0, maxSteps=9999):
33 msg =
"\n# in: " +os.getcwd()
34 if self.
dryRun: msg +=
" dryRun for '"
35 else: msg +=
" going to execute "
36 msg += cmd.replace(
';',
'\n')
39 cmdLog = open(self.
wfDir+
'/cmdLog',
'a')
40 cmdLog.write(msg+
'\n')
45 p = Popen(cmd, shell=
True)
46 ret = os.waitpid(p.pid, 0)[1]
48 print(
"ERROR executing ",cmd,
'ret=', ret)
54 startDir = os.getcwd()
56 if not os.path.exists(self.
wfDir):
57 os.makedirs(self.
wfDir)
59 print(
"cleaning up ", self.
wfDir,
' in ', os.getcwd())
60 shutil.rmtree(self.
wfDir)
61 os.makedirs(self.
wfDir)
63 preamble =
'cd '+self.
wfDir+
'; '
65 realstarttime = datetime.now()
66 startime=
'date %s' %time.asctime()
70 if 'cms/caf/cms' in os.environ[
'CMS_PATH']:
81 return ' > %s 2>&1; ' % (
'step%d_'%(i,)+ID+
'.log ',)
86 for (istepmone,com)
in enumerate(self.
wf.cmds):
99 if not isinstance(com,str):
100 if self.
cafVeto and (com.location ==
'CAF' and not onCAF):
101 print(
"You need to be no CAF to run",self.
wf.numId)
109 cmd2 = com.lumiRanges()
111 cmd2 =cmd+cmd2+closeCmd(istep,
'lumiRanges')
112 lumiRangeFile=
'step%d_lumiRanges.log'%(istep,)
113 retStep = self.
doCmd(cmd2)
114 if (com.dataSetParent):
115 cmd3=cmd+com.das(self.
dasOptions,com.dataSetParent)+closeCmd(istep,
'dasparentquery')
116 retStep = self.
doCmd(cmd3)
118 cmd+=closeCmd(istep,
'dasquery')
119 retStep = self.
doCmd(cmd)
123 dasOutputPath =
join(self.
wfDir,
'step%d_dasquery.log'%(istep,))
126 if not exists(dasOutputPath):
132 dasOutput = [l
for l
in open(dasOutputPath).
read().
split(
"\n")
if l.startswith(
"/")]
137 inFile =
'filelist:' + basename(dasOutputPath)
146 if inFile
and not 'premix_stage1' in cmd:
147 cmd +=
' --filein '+inFile
150 cmd +=
' --lumiToProcess '+lumiRangeFile
153 if 'HARVESTING' in cmd
and not 134==self.
wf.numId
and not '--filein' in cmd:
154 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
159 if istep!=1
and not '--filein' in cmd
and not 'premix_stage1' in cmd
and not (
"--fast" in cmd
and "premix_stage2" in cmd):
160 cmd+=
' --filein file:step%s.root '%(istep-1,)
161 if not '--fileout' in com:
162 cmd+=
' --fileout file:step%s.root '%(istep,)
164 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
165 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
166 cmd +=
' --nThreads %s' % self.
nThreads
167 if (self.
nStreams > 0)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
168 cmd +=
' --nStreams %s' % self.
nStreams
169 cmd+=closeCmd(istep,self.
wf.nameId)
172 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
173 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
175 else: retStep = self.
doCmd(cmd)
201 endtime=
'date %s' %time.asctime()
202 tottime=
'%s-%s'%(endtime,startime)
208 for i,s
in enumerate(self.
stat):
209 logStat+=
'Step%d-%s '%(i,s)
210 self.
report=
'%s_%s %s - time %s; exit: '%(self.
wf.numId,self.
wf.nameId,logStat,tottime)+
' '.
join(
map(str,self.
retStep))+
'\n'