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, maxSteps=9999):
32 msg =
"\n# in: " +os.getcwd()
33 if self.
dryRun: msg +=
" dryRun for '"
34 else: msg +=
" going to execute "
35 msg += cmd.replace(
';',
'\n')
38 cmdLog = open(self.
wfDir+
'/cmdLog',
'a')
39 cmdLog.write(msg+
'\n')
44 p = Popen(cmd, shell=
True)
45 ret = os.waitpid(p.pid, 0)[1]
47 print(
"ERROR executing ",cmd,
'ret=', ret)
53 startDir = os.getcwd()
55 if not os.path.exists(self.
wfDir):
56 os.makedirs(self.
wfDir)
58 print(
"cleaning up ", self.
wfDir,
' in ', os.getcwd())
59 shutil.rmtree(self.
wfDir)
60 os.makedirs(self.
wfDir)
62 preamble =
'cd '+self.
wfDir+
'; '
64 realstarttime = datetime.now()
65 startime=
'date %s' %time.asctime()
69 if 'cms/caf/cms' in os.environ[
'CMS_PATH']:
80 return ' > %s 2>&1; ' % (
'step%d_'%(i,)+ID+
'.log ',)
85 for (istepmone,com)
in enumerate(self.
wf.cmds):
98 if not isinstance(com,str):
99 if self.
cafVeto and (com.location ==
'CAF' and not onCAF):
100 print(
"You need to be no CAF to run",self.
wf.numId)
108 cmd2 = com.lumiRanges()
110 cmd2 =cmd+cmd2+closeCmd(istep,
'lumiRanges')
111 lumiRangeFile=
'step%d_lumiRanges.log'%(istep,)
112 retStep = self.
doCmd(cmd2)
113 if (com.dataSetParent):
114 cmd3=cmd+com.das(self.
dasOptions,com.dataSetParent)+closeCmd(istep,
'dasparentquery')
115 retStep = self.
doCmd(cmd3)
117 cmd+=closeCmd(istep,
'dasquery')
118 retStep = self.
doCmd(cmd)
122 dasOutputPath =
join(self.
wfDir,
'step%d_dasquery.log'%(istep,))
125 if not exists(dasOutputPath):
131 dasOutput = [l
for l
in open(dasOutputPath).
read().
split(
"\n")
if l.startswith(
"/")]
136 inFile =
'filelist:' + basename(dasOutputPath)
145 if inFile
and not 'premix_stage1' in cmd:
146 cmd +=
' --filein '+inFile
149 cmd +=
' --lumiToProcess '+lumiRangeFile
152 if 'HARVESTING' in cmd
and not 134==self.
wf.numId
and not '--filein' in cmd:
153 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
158 if istep!=1
and not '--filein' in cmd
and not 'premix_stage1' in cmd
and not (
"--fast" in cmd
and "premix_stage2" in cmd):
159 cmd+=
' --filein file:step%s.root '%(istep-1,)
160 if not '--fileout' in com:
161 cmd+=
' --fileout file:step%s.root '%(istep,)
163 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
164 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
165 cmd +=
' --nThreads %s' % self.
nThreads
166 cmd+=closeCmd(istep,self.
wf.nameId)
169 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
170 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
172 else: retStep = self.
doCmd(cmd)
198 endtime=
'date %s' %time.asctime()
199 tottime=
'%s-%s'%(endtime,startime)
205 for i,s
in enumerate(self.
stat):
206 logStat+=
'Step%d-%s '%(i,s)
207 self.
report=
'%s_%s %s - time %s; exit: '%(self.
wf.numId,self.
wf.nameId,logStat,tottime)+
' '.
join(
map(str,self.
retStep))+
'\n'