6 Beam spot postprocessing library.
8 __author__ =
'Juerg Beringer'
14 from InDetBeamSpotExample.PostProcessing
import PostProcessingStep, PostProcessingError, PostponeProcessing, runPostProcStep
16 from InDetBeamSpotExample
import COOLUtils
18 from future
import standard_library
19 standard_library.install_aliases()
23 'PlotBeamSpot.gif':
'<a href="../files?u=%s/%s/%s">Summary</a>',
24 'PlotBeamSpot.pdf':
'(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
25 'PlotBeamSpotMon.gif':
'<a href="../files?u=%s/%s/%s">Monitoring</a>',
26 'PlotBeamSpotMon.pdf':
'(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
27 'PlotGlobalMon.gif':
'<a href="../files?u=%s/%s/%s">Globalmon</a>',
28 'PlotGlobalMon.pdf':
'(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
29 'PlotBeamSpotCompareReproc.gif':
'<a href="../files?u=%s/%s/%s">Compare</a>',
30 'PlotBeamSpotCompareReproc.pdf':
'(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
31 'PlotBeamSpotCompareReproc.html':
'(<a href="/jobfiles/%s/%s/%s">html</a>)',
32 'PlotBCID-data.txt':
'<a href="../files?u=%s/%s/%s">BCID data</a>',
33 'PlotBCID-vsLb.gif':
'<a href="../files?u=%s/%s/%s">vsLb</a>',
34 'PlotBCID-vsLb.pdf':
None,
36 'PlotBCID-vsTime.gif':
'<a href="../files?u=%s/%s/%s">vsTime</a>',
37 'PlotBCID-vsTime.pdf':
None,
39 'PlotBCID-vsBCID.gif':
'<a href="../files?u=%s/%s/%s">vsBCID</a>',
40 'PlotBCID-vsBCID.pdf':
None,
41 'PlotBCID-vsBunchPos.gif':
'<a href="../files?u=%s/%s/%s">vsBunchPos</a>',
42 'PlotBCID-vsBunchPos.pdf':
None,
44 'MergeNt-nt.root':
None,
45 'BeamSpotNt-nt.root':
None,
46 'AveBeamSpot-beamspot.db':
None,
49 'DQBeamSpot-dqflags.db' :
None,
50 'DQBeamSpot-dqflags.txt' :
None,
51 'DQBeamSpotReproc-dqflags.db' :
None,
52 'PlotOnlineOfflineCompare.gif':
None,
53 'PlotOnlineOfflineCompare.pdf':
None
59 beamspottagonline =
'IndetBeamposOnl-LiveMon-001-00'
63 postProcSteps = self.taskDict[
'TASKPOSTPROCSTEPS'].
split()
64 for step
in postProcSteps:
65 self.log(
'Running postprocessing step: %s' % step)
73 print(
'Jobname: ',self.jobName)
75 postProcSteps = self.getJobConfig(self.jobName)[
'jobpostprocsteps'].
split()
77 self.log(
'Warning: No config file or jobpostprocsteps parameter found for %s/%s' % (self.dsName,self.taskName))
78 self.log(
'Continue anyway with the steps: PlotBeamSpotMon LinkResults')
79 steps =
'PlotBeamSpotMon LinkResults'
80 postProcSteps = steps.split()
82 for step
in postProcSteps:
83 self.log(
'Running postprocessing step: %s' % step)
89 postProcSteps =
'PlotBeamSpotMon MergeNt BeamSpotNt PlotBeamSpot LinkResults PlotOnlineOfflineCompare AveBeamSpot CheckT0Status UploadBeamSpot DQBeamSpot UploadDataQuality BeamSpotGlobalNt '
90 for step
in postProcSteps.split():
91 self.log(
'Running postprocessing step: %s' % step)
96 postProcSteps =
'PlotBeamSpotMon MergeNt BeamSpotNt PlotBeamSpot LinkResults PlotOnlineOfflineCompare AveBeamSpot CheckT0Status DQBeamSpot BeamSpotGlobalNt '
97 for step
in postProcSteps.split():
98 self.log(
'Running postprocessing step: %s' % step)
103 postProcSteps =
'PlotBeamSpotMon MergeNt BeamSpotNt PlotBeamSpot PlotBeamSpotCompareReproc LinkResults AveBeamSpot DQBeamSpotReproc'
104 for step
in postProcSteps.split():
105 self.log(
'Running postprocessing step: %s' % step)
111 postProcSteps =
'MergeNt BeamSpotNtNoAve PlotBCID LinkResults'
112 for step
in postProcSteps.split():
113 self.log(
'Running postprocessing step: %s' % step)
119 outFileNameGIF = self.getFileName(
'.gif')
120 outFileNamePDF = self.getFileName(
'.pdf')
121 histFileName = self.getFileName(
'-beamspotmonitoring.root')
122 if os.path.exists(
'/'.
join([self.taskDir,histFileName])):
123 self.logExec(
'cd %s; rm -f %s %s %s' % (self.taskDir,histFileName,outFileNameGIF,outFileNamePDF))
124 postProcFiles = self.taskFileList(
'*-beamspotmonitoring.root',
'POSTPROCESSING',self.jobName)
125 self.log(text=
'Found %i monitoring files from POSTPROCESSING jobs ...' % len(postProcFiles))
126 completedFiles = self.taskFileList(
'*-beamspotmonitoring.root',
'COMPLETED',self.jobName)
127 self.log(text=
'Found %i monitoring files from COMPLETED jobs ...' % len(completedFiles))
128 histFiles =
sorted(postProcFiles+completedFiles)
131 self.hadd(self.taskDir,histFileName,histFiles)
132 self.logExec(
'cd %s; plotBeamSpotMon.py -b -o %s,%s %s' % (self.taskDir,outFileNameGIF,outFileNamePDF,histFileName))
133 self.addResult(outFileNameGIF)
134 self.addResult(outFileNamePDF)
136 self.log(text=
'No monitoring files yet ...')
141 outFileNameGIF = self.getFileName(
'.gif')
142 outFileNamePDF = self.getFileName(
'.pdf')
143 ntFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
148 beamspottag = COOLUtils.resolveCurrentBeamSpotFolder()
150 raise PostProcessingError(
'ERROR: Unable to resolve beamspot folder tag',self.executedSteps,TaskManager.StatusCodes[
'POSTPROCFAILED'])
152 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
153 self.logExec(
'cd %s; plotBeamSpotCompare.py -b -o %s,%s --config="Reproc" %s %s' % (self.taskDir, outFileNameGIF,outFileNamePDF,beamspottag,ntFileName))
154 self.addResult(outFileNameGIF)
155 self.addResult(outFileNamePDF)
156 self.logExec(
'cd %s; mkdir -p %s' % (self.taskDir, self.getFileName(
'-compplots')))
157 self.logExec(
'cd %s; plotBeamSpotCompare.py -b --outtag="%s/repro_" --output=".pdf,.png" --config="Reproc" --multicanv --html %s %s' % (self.taskDir, self.getFileName(
'-compplots'), beamspottag,ntFileName))
158 self.addResult(self.getFileName(
'.html'))
162 outFileNameGIF = self.getFileName(
'.gif')
163 outFileNamePDF = self.getFileName(
'.pdf')
164 ntFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
165 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
166 cmd =
'cd %s; plotBeamSpotCompare.py -b -o %s,%s --online2 --config="OnlineOffline" %s %s' % (self.taskDir, outFileNameGIF, outFileNamePDF, ntFileName, beamspottagonline)
167 status=self.logExec(cmd,doPrint=
True,abortOnError=
False)
168 resultLinks = self.taskDict[
'RESULTLINKS']
170 self.addResult(outFileNameGIF)
171 self.addResult(outFileNamePDF)
172 link =
'<a class="ok" href="../files/?u=%s/%s/%s.gif">vsOnline</a>' % (self.dsName,self.taskName,self.baseNameStep)
173 if resultLinks.find(link)==-1:
174 resultLinks =
' '.
join([resultLinks,link])
175 link =
'(<a class="ok" href="/jobfiles/%s/%s/%s.pdf">pdf</a>)' % (self.dsName,self.taskName,self.baseNameStep)
176 if resultLinks.find(link)==-1:
177 resultLinks =
' '.
join([resultLinks,link])
179 link =
'<a class="warn" href="../files/?u=%s/%s/%s.log">No vsOnline</a>' % (self.dsName,self.taskName,self.baseNameStep)
180 if resultLinks.find(link)==-1:
181 resultLinks =
' '.
join([resultLinks,link])
182 self.taskman.setValue(self.dsName,self.taskName,
'RESULTLINKS',resultLinks)
187 outFileNameGIF = self.getFileName(
'.gif')
188 outFileNamePDF = self.getFileName(
'.pdf')
190 self.logExec(
'cd %s; hadd -f %s-globalmonitoring.root */*-globalmonitoring.root' % (self.taskDir,self.baseName))
191 self.logExec(
'cd %s; plotBeamSpotMon.py -b -o %s,%s %s-globalmonitoring.root' % (self.taskDir,outFileNameGIF,outFileNamePDF,self.baseName))
192 self.addResult(outFileNameGIF)
193 self.addResult(outFileNamePDF)
198 ntFileName = self.getFileName(
'-nt.root')
199 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
200 self.logExec(
'cd %s; rm -f %s' % (self.taskDir,ntFileName))
201 postProcFiles = self.taskFileList(
'*-nt.root',
'POSTPROCESSING',self.jobName)
202 self.log(text=
'Found %i ntuple files from POSTPROCESSING jobs ...' % len(postProcFiles))
203 completedFiles = self.taskFileList(
'*-nt.root',
'COMPLETED',self.jobName)
204 self.log(text=
'Found %i ntuple files from COMPLETED jobs ...' % len(completedFiles))
205 ntFiles =
sorted(postProcFiles+completedFiles)
208 self.hadd(self.taskDir,ntFileName,ntFiles)
209 self.addResult(ntFileName)
211 raise PostProcessingError(
'WARNING: No beam spot ntuple files to merge',self.executedSteps)
216 ntFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
217 outFileNameGIF = self.getFileName(
'.gif')
218 outFileNamePDF = self.getFileName(
'.pdf')
219 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
220 self.logExec(
'cd %s; beamspotnt.py -b -o %s,%s -f %s summary' % (self.taskDir,outFileNameGIF,outFileNamePDF,ntFileName))
221 self.addResult(outFileNameGIF)
222 self.addResult(outFileNamePDF)
224 raise PostProcessingError(
'ERROR: No ntuple file %s - did BeamSpotNt step run?\n' % ntFileName,self.executedSteps)
229 resultFiles = self.taskDict[
'RESULTFILES']
231 if 'AveBeamSpot' in self.executedSteps:
232 self.log(text=
'WARNING: You should always run AveBeamSpot after LinkResults to avoid overwriting results\n',doPrint=
True)
235 for r
in resultFiles.split():
236 what =
'.'.
join(r.split(
'.')[-2:])
237 if what
in linkTemplates:
238 if linkTemplates[what]:
239 resultLinks =
' '.
join([resultLinks, linkTemplates[what] % (self.dsName,self.taskName,r)])
241 resultLinks =
' '.
join([resultLinks,
'<a href="../files?u=%s/%s/%s">%s</a>' % (self.dsName,self.taskName,r,what)])
242 self.taskman.setValue(self.dsName,self.taskName,
'RESULTLINKS',resultLinks)
247 ntFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
248 beamSpotDbFileName = self.getFileName(
'-beamspot.db')
251 if os.path.exists(
'/'.
join([self.taskDir,beamSpotDbFileName])):
252 self.logExec(
'cd %s; rm -f %s' % (self.taskDir,beamSpotDbFileName))
256 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
257 cmd =
'cd %s; beamspotnt.py --tag=%s -f %s --newave ave' % (self.taskDir,beamSpotDbFileName[:-3],ntFileName)
260 status = self.logExec(cmd,doPrint=
True,abortOnError=
False)
261 if status
and status!=2
and status!=3:
263 raise PostProcessingError(
'ERROR in postprocessing step AveBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
264 resultLinks = self.taskDict[
'RESULTLINKS']
266 self.addResult(beamSpotDbFileName)
267 link =
'<a class="ok" href="../files/?u=%s/%s/%s.log">Beam spot</a>' % (self.dsName,self.taskName,self.baseNameStep)
268 if resultLinks.find(link)==-1:
269 resultLinks =
' '.
join([link,resultLinks])
271 link =
'<a class="warn" href="../files/?u=%s/%s/%s.log">No beam spot</a>' % (self.dsName,self.taskName,self.baseNameStep)
272 if resultLinks.find(link)==-1:
273 resultLinks =
' '.
join([link,resultLinks])
275 link =
'<a class="warn" href="../files/?u=%s/%s/%s.log">No vtx/beam spot</a>' % (self.dsName,self.taskName,self.baseNameStep)
276 if resultLinks.find(link)==-1:
277 resultLinks =
' '.
join([link,resultLinks])
300 self.taskman.setValue(self.dsName,self.taskName,
'RESULTLINKS',resultLinks)
302 raise PostProcessingError(
'ERROR: No ntuple file %s - did BeamSpotNt step run?\n' % ntFileName,self.executedSteps)
306 """Check in T0 task DB if T0 processing is done, if not raise PostponeProcessing exception."""
310 f = self.getJobConfig(self.jobName)[
'inputfiles'][0]
314 self.log(
'WARNING: Unable to determine input file type - will assume default (%s)\n' % filter, doPrint=
True)
315 cmd =
'beamspotman.py -n -f %s queryT0 %s %s' % (filter,self.dsName,self.taskName)
316 status = self.logExec(cmd,doPrint=
True,abortOnError=
False)
321 raise PostponeProcessing(
'Tier-0 processing still in progress - restart postprocessing later',self.executedSteps)
324 raise PostProcessingError(
'ERROR: Unable to determine Tier-0 task status',self.executedSteps)
329 beamSpotDbFileName = self.getFileName(
'-beamspot.db',
'AveBeamSpot')
330 cooltags = self.taskDict[
'COOLTAGS']
331 if not cooltags: cooltags =
''
335 beamspottag = COOLUtils.resolveCurrentBeamSpotFolder()
337 raise PostProcessingError(
'ERROR: Unable to resolve beamspot folder tag',self.executedSteps,TaskManager.StatusCodes[
'POSTPROCFAILED'])
340 if beamspottag
in cooltags.split():
341 self.log(
'WARNING: Beam spot already uploaded to COOL: %s - continue anyway' % beamspottag)
346 if self.dsName.
split(
'.')[-1] !=
'express_express' and self.dsName.
split(
'.')[-1] !=
'calibration_BeamSpot':
347 print (self.dsName.
split(
'.')[-1] )
348 self.log(text=
"WARNING: Not running on the express or BeamSpot stream, so won't upload anything - if this is intentional, please upload manually\n",doPrint=
True)
350 if os.path.exists(
'/'.
join([self.taskDir,beamSpotDbFileName])):
353 self.logExec(
'beamspotman.py -b -n -t %s upload %s %s' % (beamspottag,self.dsName,self.taskName))
356 self.log(text=
'ERROR: No beam spot COOL SQLite file %s\n Nothing to upload - was beam spot determination successful?\n' % beamSpotDbFileName,doPrint=
True)
366 """Automatically determine DQ info (after uploading beamspot)"""
367 def run(self, absent=False):
368 ntFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
369 dataQualityDbFileName = self.getFileName(
'-dqflags.db')
371 if os.path.exists(
'/'.
join([self.taskDir,dataQualityDbFileName])):
372 self.logExec(
'cd %s; rm -f %s' % (self.taskDir,dataQualityDbFileName))
374 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
375 cmd =
'cd %s; dqBeamSpot.py -b %s -o %s %s' % (self.taskDir,
'-a' if absent
else '',dataQualityDbFileName,ntFileName)
376 status = self.logExec(cmd,doPrint=
True,abortOnError=
False)
379 raise PostProcessingError(
'ERROR in postprocessing step DQBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
382 self.addResult(dataQualityDbFileName)
384 dataQualityTxtFileName = dataQualityDbFileName.replace(
'.db',
'.txt')
385 cmd =
'grep -c "ID_BS_NOBEAMSPOT" %s/%s' % (self.taskDir, dataQualityTxtFileName)
386 status,out = subprocess.getstatusoutput(cmd)
392 raise PostProcessingError(
'ERROR in postprocessing step DQBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
395 link=
'<a class="ok" href="../files?u=%s/%s/%s-dqflags.txt">DQFlags</a>' % (self.dsName,self.taskName,self.baseNameStep)
397 link=
'<a class="bad" href="../files?u=%s/%s/%s-dqflags.txt">DQFlags</a>' % (self.dsName,self.taskName,self.baseNameStep)
399 resultLinks = self.taskDict[
'RESULTLINKS']
400 if resultLinks.find(link)==-1:
401 resultLinks =
' '.
join([resultLinks, link])
404 self.taskman.setValue(self.dsName,self.taskName,
'RESULTLINKS',resultLinks)
406 raise PostProcessingError(
'ERROR: No ntuple file %s - did BeamSpotNt step run?\n' % ntFileName,self.executedSteps)
409 """Automatically determine DQ info (after uploading beamspot). For reprocessing also upload absent defects to remove previosuly set ones"""
411 return DQBeamSpot.run(self, absent=
True)
414 """Upload beampsot data quality info"""
416 dataQualityDbFileName = self.getFileName(
'-dqflags.db',
'DQBeamSpot')
419 if os.path.exists(
'/'.
join([self.taskDir,dataQualityDbFileName])):
420 self.logExec(
'beamspotman.py -b -n --dqtag %s dqflag %s %s' % (dqtag,self.dsName,self.taskName))
422 self.log(text=
'ERROR: No beam spot DQ flag SQLite file %s\n Nothing to upload - was DQ determination successful?\n' % dataQualityDbFileName,doPrint=
True)
427 ntFileName = self.getFileName(
'-nt.root',
'MergeNt')
428 bsNtFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
429 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
430 self.logExec(
"cd %s; rm -f %s; beamspotnt.py -f %s --status '' --fillCOOL --addScanVars merge %s" % (self.taskDir,bsNtFileName,bsNtFileName,ntFileName))
431 self.addResult(bsNtFileName)
433 raise PostProcessingError(
'ERROR: No merged ntuple file %s - did MergeNt step run?\n' % ntFileName,self.executedSteps)
439 ntFileName = self.getFileName(
'-nt.root',
'MergeNt')
440 bsNtFileName = self.getFileName(
'-nt.root')
441 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
442 self.logExec(
"cd %s; rm -f %s; beamspotnt.py -f %s --status '' --fillCOOL --useAve merge %s" % (self.taskDir,bsNtFileName,bsNtFileName,ntFileName))
443 self.addResult(bsNtFileName)
445 raise PostProcessingError(
'ERROR: No merged ntuple file %s - did MergeNt step run?\n' % ntFileName,self.executedSteps)
451 cooltags = self.taskDict[
'COOLTAGS']
452 if not cooltags: cooltags =
''
457 self.log(text=
'WARNING: Beam spot not uploaded - result not merged to global ntuple\n',doPrint=
True)
460 ntFileName = self.getFileName(
'-nt.root',
'MergeNt')
461 globalNtDir =
'/afs/cern.ch/user/a/atlidbs/nt/t0'
462 beamspottag = cooltags.split()[len(cooltags.split())-1]
463 globalNtFileName =
'%s/beamspotnt-%s.root' % (globalNtDir,beamspottag)
464 if not os.path.exists(globalNtDir):
465 raise PostProcessingError(
'ERROR: Cannot access directory with global beam spot ntuple: %s' % globalNtDir, self.executedSteps)
466 if os.path.exists(
'/'.
join([self.taskDir,ntFileName])):
467 self.logExec(
"cd %s; beamspotnt.py -f %s --status '' --fillCOOL --useAve merge %s" % (self.taskDir,globalNtFileName,ntFileName))
470 raise PostProcessingError(
'ERROR: No merged ntuple file %s - did MergeNt step run?\n' % ntFileName, self.executedSteps)
475 bsNtFileName = self.getFileName(
'-nt.root',
'BeamSpotNt')
476 dumpFileName = self.getFileName(
'-data.txt')
477 outFileNameLbGIF = self.getFileName(
'-vsLb.gif')
478 outFileNameLbPDF = self.getFileName(
'-vsLb.pdf')
479 outFileNameTimeGIF = self.getFileName(
'-vsTime.gif')
480 outFileNameTimePDF = self.getFileName(
'-vsTime.pdf')
481 outFileNameBCIDGIF = self.getFileName(
'-vsBCID.gif')
482 outFileNameBCIDPDF = self.getFileName(
'-vsBCID.pdf')
483 outFileNameTrainGIF = self.getFileName(
'-vsBunchPos.gif')
484 outFileNameTrainPDF = self.getFileName(
'-vsBunchPos.pdf')
485 if os.path.exists(
'/'.
join([self.taskDir,bsNtFileName])):
486 self.logExec(
"cd %s; rm -f %s; beamspotnt.py -v -f %s dump > %s" % (self.taskDir,dumpFileName,bsNtFileName,dumpFileName))
487 self.addResult(dumpFileName)
488 self.logExec(
"cd %s; beamspotnt.py --batch -o %s,%s -f %s summary" % (self.taskDir,outFileNameLbGIF,outFileNameLbPDF,bsNtFileName))
489 self.addResult(outFileNameLbGIF)
490 self.addResult(outFileNameLbPDF)
491 self.logExec(
"cd %s; beamspotnt.py --batch --time -o %s,%s -f %s summary" % (self.taskDir,outFileNameTimeGIF,outFileNameTimePDF,bsNtFileName))
492 self.addResult(outFileNameTimeGIF)
493 self.addResult(outFileNameTimePDF)
494 self.logExec(
"cd %s; beamspotnt.py --batch -m 0.2 --perbcid -o %s,%s -f %s summary" % (self.taskDir,outFileNameBCIDGIF,outFileNameBCIDPDF,bsNtFileName))
495 self.addResult(outFileNameBCIDGIF)
496 self.addResult(outFileNameBCIDPDF)
497 self.logExec(
"cd %s; beamspotnt.py --batch --vsbunchpos -o %s,%s -f %s summary" % (self.taskDir,outFileNameTrainGIF,outFileNameTrainPDF,bsNtFileName))
498 self.addResult(outFileNameTrainGIF)
499 self.addResult(outFileNameTrainPDF)
501 raise PostProcessingError(
'ERROR: No beam spot ntuple file %s - did BeamSpotNt step run?\n' % bsNtFileName,self.executedSteps)