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):
27 self.
wfDir=
str(self.wf.numId)+
'_'+self.wf.nameId
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):
95 self.retStep.append(0)
96 self.stat.append(
'NOTRUN')
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)
103 self.retStep.append(0)
104 self.stat.append(
'NOTRUN')
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,))
123 if not exists(dasOutputPath):
129 dasOutput = [l
for l
in open(dasOutputPath).read().
split(
"\n")
if l.startswith(
"/")]
134 inFile =
'filelist:' +
basename(dasOutputPath)
143 if inFile
and not 'premix_stage1' in cmd:
144 cmd +=
' --filein '+inFile
147 cmd +=
' --lumiToProcess '+lumiRangeFile
150 if 'HARVESTING' in cmd
and not 134==self.wf.numId
and not '--filein' in cmd:
151 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
156 if istep!=1
and not '--filein' in cmd
and not 'premix_stage1' in cmd
and not (
"--fast" in cmd
and "premix_stage2" in cmd):
157 cmd+=
' --filein file:step%s.root '%(istep-1,)
158 if not '--fileout' in com:
159 cmd+=
' --fileout file:step%s.root '%(istep,)
161 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
162 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
163 cmd +=
' --nThreads %s' % self.
nThreads 164 cmd+=closeCmd(istep,self.wf.nameId)
167 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
168 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
170 else: retStep = self.
doCmd(cmd)
172 self.retStep.append(retStep)
177 self.stat.append(
'TIMEOUT')
184 self.stat.append(
"DAS_ERROR")
186 self.stat.append(
'FAILED')
193 self.stat.append(
'PASSED')
196 endtime=
'date %s' %time.asctime()
197 tottime=
'%s-%s'%(endtime,startime)
203 for i,s
in enumerate(self.
stat):
204 logStat+=
'Step%d-%s '%(i,s)
205 self.
report=
'%s_%s %s - time %s; exit: '%(self.wf.numId,self.wf.nameId,logStat,tottime)+
' '.
join(
map(str,self.
retStep))+
'\n'
S & print(S &os, JobReport::InputFile const &f)
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