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, nEvents=0):
34 msg =
"\n# in: " +os.getcwd()
35 if self.
dryRun: msg +=
" dryRun for '" 36 else: msg +=
" going to execute " 37 msg += cmd.replace(
';',
'\n')
40 cmdLog = open(self.
wfDir+
'/cmdLog',
'a')
41 cmdLog.write(msg+
'\n')
46 p = Popen(cmd, shell=
True)
47 ret = os.waitpid(p.pid, 0)[1]
49 print(
"ERROR executing ",cmd,
'ret=', ret)
55 startDir = os.getcwd()
57 if not os.path.exists(self.
wfDir):
58 os.makedirs(self.
wfDir)
60 print(
"cleaning up ", self.
wfDir,
' in ', os.getcwd())
61 shutil.rmtree(self.
wfDir)
62 os.makedirs(self.
wfDir)
64 preamble =
'cd '+self.
wfDir+
'; ' 66 realstarttime = datetime.now()
67 startime=
'date %s' %time.asctime()
71 if 'cms/caf/cms' in os.environ[
'CMS_PATH']:
82 return ' > %s 2>&1; ' % (
'step%d_'%(i,)+ID+
'.log ',)
87 for (istepmone,com)
in enumerate(self.
wf.cmds):
100 if not isinstance(com,str):
101 if self.
cafVeto and (com.location ==
'CAF' and not onCAF):
102 print(
"You need to be no CAF to run",self.
wf.numId)
110 cmd2 = com.lumiRanges()
112 cmd2 =cmd+cmd2+closeCmd(istep,
'lumiRanges')
113 lumiRangeFile=
'step%d_lumiRanges.log'%(istep,)
114 retStep = self.
doCmd(cmd2)
115 if (com.dataSetParent):
116 cmd3=cmd+com.das(self.
dasOptions,com.dataSetParent)+closeCmd(istep,
'dasparentquery')
117 retStep = self.
doCmd(cmd3)
119 cmd+=closeCmd(istep,
'dasquery')
120 retStep = self.
doCmd(cmd)
124 dasOutputPath =
join(self.
wfDir,
'step%d_dasquery.log'%(istep,))
127 if not exists(dasOutputPath):
133 dasOutput = [l
for l
in open(dasOutputPath).
read().
split(
"\n")
if l.startswith(
"/")]
138 inFile =
'filelist:' + basename(dasOutputPath)
147 if inFile
and not 'premix_stage1' in cmd:
148 cmd +=
' --filein '+inFile
151 cmd +=
' --lumiToProcess '+lumiRangeFile
154 if 'HARVESTING' in cmd
and not 134==self.
wf.numId
and not '--filein' in cmd:
155 cmd+=
' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
160 if istep!=1
and not '--filein' in cmd
and not 'premix_stage1' in cmd
and not (
"--fast" in cmd
and "premix_stage2" in cmd):
161 cmd+=
' --filein file:step%s.root '%(istep-1,)
162 if not '--fileout' in com:
163 cmd+=
' --fileout file:step%s.root '%(istep,)
165 cmd +=
' --suffix "-j JobReport%s.xml " ' % istep
166 if (self.
nThreads > 1)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
167 cmd +=
' --nThreads %s' % self.
nThreads 168 if (self.
nStreams > 0)
and (
'HARVESTING' not in cmd)
and (
'ALCAHARVEST' not in cmd):
169 cmd +=
' --nStreams %s' % self.
nStreams 172 split = cmd.split(event_token)
173 pos_cmd =
" ".
join(split[1].
split(
" ")[1:])
174 cmd = split[0] + event_token +
'%s ' % self.
nEvents + pos_cmd
175 cmd+=closeCmd(istep,self.
wf.nameId)
178 wf_stats = open(
"%s/wf_steps.txt" % self.
wfDir,
"a")
179 wf_stats.write(
'step%s:%s\n' % (istep, cmd))
181 else: retStep = self.
doCmd(cmd)
207 endtime=
'date %s' %time.asctime()
208 tottime=
'%s-%s'%(endtime,startime)
214 for i,s
in enumerate(self.
stat):
215 logStat+=
'Step%d-%s '%(i,s)
217 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, nStreams=0, maxSteps=9999, nEvents=0)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def split(sequence, size)
static std::string join(char **cmd)
npass
needs to set self.report