ATLAS Offline Software
BeamSpotPostProcessing.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 """
6 Beam spot postprocessing library.
7 """
8 __author__ = 'Juerg Beringer'
9 __version__ = '$Id $'
10 
11 
12 import os
13 
14 from InDetBeamSpotExample.PostProcessing import PostProcessingStep, PostProcessingError, PostponeProcessing, runPostProcStep
15 from InDetBeamSpotExample.TaskManager import TaskManager
16 from InDetBeamSpotExample import COOLUtils
17 
18 from future import standard_library
19 standard_library.install_aliases()
20 import subprocess
21 
22 linkTemplates = {
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, # suppress linking until we get better quality PDF
35  #'PlotBCID-vsLb.pdf': '(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
36  'PlotBCID-vsTime.gif': '<a href="../files?u=%s/%s/%s">vsTime</a>',
37  'PlotBCID-vsTime.pdf': None, # suppress linking until we get better quality PDF
38  #'PlotBCID-vsTime.pdf': '(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
39  'PlotBCID-vsBCID.gif': '<a href="../files?u=%s/%s/%s">vsBCID</a>',
40  'PlotBCID-vsBCID.pdf': None, # suppress linking until we get better quality PDF
41  'PlotBCID-vsBunchPos.gif': '<a href="../files?u=%s/%s/%s">vsBunchPos</a>',
42  'PlotBCID-vsBunchPos.pdf': None,
43  #'PlotBCID-vsBCID.pdf': '(<a href="/jobfiles/%s/%s/%s">pdf</a>)',
44  'MergeNt-nt.root': None, # suppress linking
45  'BeamSpotNt-nt.root': None, # suppress linking
46  'AveBeamSpot-beamspot.db': None, # suppress linking
47  #'AveBeamSpot-dqflags.db' : None, # suppress linking
48  #'AveBeamSpot-dqflags.txt' : None, # suppress linking
49  'DQBeamSpot-dqflags.db' : None, # suppress linking
50  'DQBeamSpot-dqflags.txt' : None, # suppress linking
51  'DQBeamSpotReproc-dqflags.db' : None, # suppress linking
52  'PlotOnlineOfflineCompare.gif': None,
53  'PlotOnlineOfflineCompare.pdf': None
54 }
55 
56 # Beamspot tag is now taken from "current" BLK tag alias
57 #beamspottag = 'IndetBeampos-ES1-UPD2'
58 dqtag = 'HEAD'
59 beamspottagonline = 'IndetBeamposOnl-LiveMon-001-00'
60 
61 class TaskPostProcessing(PostProcessingStep):
62  def run(self):
63  postProcSteps = self.taskDict['TASKPOSTPROCSTEPS'].split()
64  for step in postProcSteps:
65  self.log('Running postprocessing step: %s' % step)
66  self.executedSteps = runPostProcStep(self.taskman,self.taskDict,self.oldStatus,self.executedSteps,step,self.postprocLib,self.jobName)
67 
68 
69 class JobPostProcessing(PostProcessingStep):
70  def run(self):
71 
73  print('Jobname: ',self.jobName)
74  try:
75  postProcSteps = self.getJobConfig(self.jobName)['jobpostprocsteps'].split()
76  except Exception:
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()
81  #raise PostProcessingError('ERROR: No config file or jobpostprocsteps parameter found for %s/%s' % (self.dsName,self.taskName),self.executedSteps)
82  for step in postProcSteps:
83  self.log('Running postprocessing step: %s' % step)
84  self.executedSteps = runPostProcStep(self.taskman,self.taskDict,self.oldStatus,self.executedSteps,step,self.postprocLib,self.jobName)
85 
86 
87 class T0VertexDefaultProcessing(PostProcessingStep):
88  def run(self):
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)
92  self.executedSteps = runPostProcStep(self.taskman,self.taskDict,self.oldStatus,self.executedSteps,step,self.postprocLib,self.jobName)
93 
94 class T0VertexTestProcessing(PostProcessingStep):
95  def run(self):
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)
99  self.executedSteps = runPostProcStep(self.taskman,self.taskDict,self.oldStatus,self.executedSteps,step,self.postprocLib,self.jobName)
100 
101 class ReprocVertexDefaultProcessing(PostProcessingStep):
102  def run(self):
103  postProcSteps = 'PlotBeamSpotMon MergeNt BeamSpotNt PlotBeamSpot PlotBeamSpotCompareReproc LinkResults AveBeamSpot DQBeamSpotReproc'
104  for step in postProcSteps.split():
105  self.log('Running postprocessing step: %s' % step)
106  self.executedSteps = runPostProcStep(self.taskman,self.taskDict,self.oldStatus,self.executedSteps,step,self.postprocLib,self.jobName)
107 
108 
109 class BCIDDefaultProcessing(PostProcessingStep):
110  def run(self):
111  postProcSteps = 'MergeNt BeamSpotNtNoAve PlotBCID LinkResults'
112  for step in postProcSteps.split():
113  self.log('Running postprocessing step: %s' % step)
114  self.executedSteps = runPostProcStep(self.taskman,self.taskDict,self.oldStatus,self.executedSteps,step,self.postprocLib,self.jobName)
115 
116 
117 class PlotBeamSpotMon(PostProcessingStep):
118  def run(self):
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)
129  if len(histFiles)>0:
130  #self.logExec('cd %s; hadd -f %s %s' % (self.taskDir,histFileName,' '.join(histFiles)))
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)
135  else:
136  self.log(text='No monitoring files yet ...')
137 
138 
139 class PlotBeamSpotCompareReproc(PostProcessingStep):
140  def run(self):
141  outFileNameGIF = self.getFileName('.gif')
142  outFileNamePDF = self.getFileName('.pdf')
143  ntFileName = self.getFileName('-nt.root','BeamSpotNt')
144 
145  # Resolve beamspot tag. Since reprocessing results will be uploaded to the "next" tag, the "current"
146  # tag will be the one containing the best results to date and hence we compare to that
147  try:
148  beamspottag = COOLUtils.resolveCurrentBeamSpotFolder()
149  except Exception:
150  raise PostProcessingError('ERROR: Unable to resolve beamspot folder tag',self.executedSteps,TaskManager.StatusCodes['POSTPROCFAILED'])
151 
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'))
159 
160 class PlotOnlineOfflineCompare(PostProcessingStep):
161  def run(self):
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']
169  if status==0:
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])
178  else:
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)
183 
184 # Still to be tested
185 class PlotGlobalMon(PostProcessingStep):
186  def run(self):
187  outFileNameGIF = self.getFileName('.gif')
188  outFileNamePDF = self.getFileName('.pdf')
189  # Get monitoring file name from jobConfig?
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)
194 
195 
196 class MergeNt(PostProcessingStep):
197  def run(self):
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)
206  if len(ntFiles)>0:
207  #self.logExec('cd %s; hadd -f %s %s' % (self.taskDir,ntFileName,' '.join(ntFiles)))
208  self.hadd(self.taskDir,ntFileName,ntFiles)
209  self.addResult(ntFileName)
210  else:
211  raise PostProcessingError('WARNING: No beam spot ntuple files to merge',self.executedSteps)
212 
213 
214 class PlotBeamSpot(PostProcessingStep):
215  def run(self):
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)
223  else:
224  raise PostProcessingError('ERROR: No ntuple file %s - did BeamSpotNt step run?\n' % ntFileName,self.executedSteps)
225 
226 
227 class LinkResults(PostProcessingStep):
228  def run(self):
229  resultFiles = self.taskDict['RESULTFILES']
230  resultLinks = ''
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)
233  if not resultFiles:
234  return
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)])
240  else:
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)
243 
244 
245 class AveBeamSpot(PostProcessingStep):
246  def run(self):
247  ntFileName = self.getFileName('-nt.root','BeamSpotNt')
248  beamSpotDbFileName = self.getFileName('-beamspot.db')
249  #dataQualityDbFileName = self.getFileName('-dqflags.db')
250 
251  if os.path.exists('/'.join([self.taskDir,beamSpotDbFileName])):
252  self.logExec('cd %s; rm -f %s' % (self.taskDir,beamSpotDbFileName))
253  #if os.path.exists('/'.join([self.taskDir,dataQualityDbFileName])):
254  # self.logExec('cd %s; rm -f %s' % (self.taskDir,dataQualityDbFileName))
255 
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)
258  #cmd = 'cd %s; aveBeamSpot.py -b -o %s %s' % (self.taskDir,beamSpotDbFileName,ntFileName)
259  #cmd = 'cd %s; aveBeamSpot.py -b -o %s -d %s %s' % (self.taskDir,beamSpotDbFileName,dataQualityDbFileName,ntFileName)
260  status = self.logExec(cmd,doPrint=True,abortOnError=False)
261  if status and status!=2 and status!=3:
262  # Some other error than simply no beam spot data
263  raise PostProcessingError('ERROR in postprocessing step AveBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
264  resultLinks = self.taskDict['RESULTLINKS']
265  if status==0:
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])
270  if status==2:
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])
274  if status==3:
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])
278 
279 # # Add DQ flags to results and do linking
280 # self.addResult(dataQualityDbFileName)
281 #
282 # dataQualityTxtFileName = dataQualityDbFileName.replace('.db','.txt')
283 # stat,out = subprocess.getstatusoutput('grep -c "ID_BS_NOBEAMSPOT" %s/%s' % (self.taskDir, dataQualityTxtFileName) )
284 #
285 # # Catch errors (do it this way as the exit codes from grep are nasty)
286 # try:
287 # nRed=int(out)
288 # except ValueError:
289 # raise PostProcessingError('ERROR in postprocessing step AveBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
290 #
291 # if nRed==0:
292 # link='<a class="ok" href="../files?u=%s/%s/%s-dqflags.txt">DQFlags</a>' % (self.dsName,self.taskName,self.baseNameStep)
293 # else:
294 # link='<a class="bad" href="../files?u=%s/%s/%s-dqflags.txt">DQFlags</a>' % (self.dsName,self.taskName,self.baseNameStep)
295 #
296 # if resultLinks.find(link)==-1:
297 # resultLinks = ' '.join([resultLinks, link])
298 
299  # Set links by hand
300  self.taskman.setValue(self.dsName,self.taskName,'RESULTLINKS',resultLinks)
301  else:
302  raise PostProcessingError('ERROR: No ntuple file %s - did BeamSpotNt step run?\n' % ntFileName,self.executedSteps)
303 
304 
305 class CheckT0Status(PostProcessingStep):
306  """Check in T0 task DB if T0 processing is done, if not raise PostponeProcessing exception."""
307  def run(self):
308  filter = 'AOD' # T0 uses AODs by default (at least for pp running)
309  try:
310  f = self.getJobConfig(self.jobName)['inputfiles'][0]
311  if 'ESD' in f:
312  filter = 'ESD'
313  except Exception:
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)
317  if status:
318  # The task is either not finished or there was a problem
319  if status==2:
320  # Task still running
321  raise PostponeProcessing('Tier-0 processing still in progress - restart postprocessing later',self.executedSteps)
322  else:
323  # Unable to determine status
324  raise PostProcessingError('ERROR: Unable to determine Tier-0 task status',self.executedSteps)
325 
326 
327 class UploadBeamSpot(PostProcessingStep):
328  def run(self):
329  beamSpotDbFileName = self.getFileName('-beamspot.db','AveBeamSpot')
330  cooltags = self.taskDict['COOLTAGS']
331  if not cooltags: cooltags = ''
332 
333  # Resolve beamspot tag
334  try:
335  beamspottag = COOLUtils.resolveCurrentBeamSpotFolder()
336  except Exception:
337  raise PostProcessingError('ERROR: Unable to resolve beamspot folder tag',self.executedSteps,TaskManager.StatusCodes['POSTPROCFAILED'])
338 
339  # Check that we haven't uploaded yet
340  if beamspottag in cooltags.split():
341  self.log('WARNING: Beam spot already uploaded to COOL: %s - continue anyway' % beamspottag)
342  # This command is kept for possible future use: raise PostProcessingError('ERROR: Beam spot already uploaded to COOL - if this is intentional, please upload manually.',
343  # self.executedSteps,TaskManager.StatusCodes['POSTPROCFAILED'])
344 
345  # Check that this is the express stream
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)
349  return
350  if os.path.exists('/'.join([self.taskDir,beamSpotDbFileName])):
351  # Dumping of the beam spot SQLite file is done by beamspotman
352  #self.logExec('cd %s; dumpBeamSpot.py %s' % (self.taskDir,beamSpotDbFileName))
353  self.logExec('beamspotman.py -b -n -t %s upload %s %s' % (beamspottag,self.dsName,self.taskName))
354  else:
355  #raise PostProcessingError('ERROR: No beam spot COOL SQLite file %s - did AveBeamSpot succeed?\n' % beamSpotDbFileName,self.executedSteps)
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)
357 
358 # # Once uploaded the beamspot can upload the DQ flags
359 # dataQualityDbFileName = self.getFileName('-dqflags.db','AveBeamSpot')
360 # if os.path.exists('/'.join([self.taskDir,dataQualityDbFileName])):
361 # self.logExec('beamspotman.py -b -n --dqtag %s dqflag %s %s' % (dqtag,self.dsName,self.taskName))
362 # else:
363 # self.log(text='ERROR: No beam spot DQ flag SQLite file %s\n Nothing to upload - was beam spot or DQ determination successful?\n' % dqDbFileName,doPrint=True)
364 
365 class DQBeamSpot(PostProcessingStep):
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')
370 
371  if os.path.exists('/'.join([self.taskDir,dataQualityDbFileName])):
372  self.logExec('cd %s; rm -f %s' % (self.taskDir,dataQualityDbFileName))
373 
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)
377 
378  if status:
379  raise PostProcessingError('ERROR in postprocessing step DQBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
380 
381  # Add DQ flags to results and do linking
382  self.addResult(dataQualityDbFileName)
383 
384  dataQualityTxtFileName = dataQualityDbFileName.replace('.db','.txt')
385  cmd = 'grep -c "ID_BS_NOBEAMSPOT" %s/%s' % (self.taskDir, dataQualityTxtFileName)
386  status,out = subprocess.getstatusoutput(cmd)
387 
388  # Catch errors (do it this way as the exit codes from grep are nasty)
389  try:
390  nRed=int(out)
391  except ValueError:
392  raise PostProcessingError('ERROR in postprocessing step DQBeamSpot while executing:\n\n%s\n' % (cmd),self.executedSteps)
393 
394  if nRed==0:
395  link='<a class="ok" href="../files?u=%s/%s/%s-dqflags.txt">DQFlags</a>' % (self.dsName,self.taskName,self.baseNameStep)
396  else:
397  link='<a class="bad" href="../files?u=%s/%s/%s-dqflags.txt">DQFlags</a>' % (self.dsName,self.taskName,self.baseNameStep)
398 
399  resultLinks = self.taskDict['RESULTLINKS']
400  if resultLinks.find(link)==-1:
401  resultLinks = ' '.join([resultLinks, link])
402 
403  # Set links by hand
404  self.taskman.setValue(self.dsName,self.taskName,'RESULTLINKS',resultLinks)
405  else:
406  raise PostProcessingError('ERROR: No ntuple file %s - did BeamSpotNt step run?\n' % ntFileName,self.executedSteps)
407 
409  """Automatically determine DQ info (after uploading beamspot). For reprocessing also upload absent defects to remove previosuly set ones"""
410  def run(self):
411  return DQBeamSpot.run(self, absent=True)
412 
413 class UploadDataQuality(PostProcessingStep):
414  """Upload beampsot data quality info"""
415  def run(self):
416  dataQualityDbFileName = self.getFileName('-dqflags.db', 'DQBeamSpot')
417 
418  # Upload the DQ flags
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))
421  else:
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)
423 
424 
425 class BeamSpotNtNoAve(PostProcessingStep):
426  def run(self):
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)
432  else:
433  raise PostProcessingError('ERROR: No merged ntuple file %s - did MergeNt step run?\n' % ntFileName,self.executedSteps)
434 
435 
436 
437 class BeamSpotNt(PostProcessingStep):
438  def run(self):
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)
444  else:
445  raise PostProcessingError('ERROR: No merged ntuple file %s - did MergeNt step run?\n' % ntFileName,self.executedSteps)
446 
447 
448 class BeamSpotGlobalNt(PostProcessingStep):
449  def run(self):
450  # Don't merge into global ntuple if no beamspot uploaded to COOL
451  cooltags = self.taskDict['COOLTAGS']
452  if not cooltags: cooltags = ''
453 
454  # Check if the task has uploded to COOL
455  # if not beamspottag in cooltags.split():
456  if not cooltags:
457  self.log(text='WARNING: Beam spot not uploaded - result not merged to global ntuple\n',doPrint=True)
458  return
459 
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))
468  # self.logExec("cd %s; beamspotnt.py -f %s --status '' --fillCOOL --useAve merge %s" % (self.taskDir,globalNtFileName2,ntFileName))
469  else:
470  raise PostProcessingError('ERROR: No merged ntuple file %s - did MergeNt step run?\n' % ntFileName, self.executedSteps)
471 
472 
473 class PlotBCID(PostProcessingStep):
474  def run(self):
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)
500  else:
501  raise PostProcessingError('ERROR: No beam spot ntuple file %s - did BeamSpotNt step run?\n' % bsNtFileName,self.executedSteps)
python.BeamSpotPostProcessing.BCIDDefaultProcessing
Definition: BeamSpotPostProcessing.py:109
python.BeamSpotPostProcessing.LinkResults
Definition: BeamSpotPostProcessing.py:227
python.BeamSpotPostProcessing.DQBeamSpotReproc.run
def run(self)
Definition: BeamSpotPostProcessing.py:410
python.BeamSpotPostProcessing.DQBeamSpot.run
def run(self, absent=False)
Definition: BeamSpotPostProcessing.py:367
python.BeamSpotPostProcessing.BeamSpotNtNoAve
Definition: BeamSpotPostProcessing.py:425
python.BeamSpotPostProcessing.BeamSpotNt
Definition: BeamSpotPostProcessing.py:437
python.BeamSpotPostProcessing.PlotBCID.run
def run(self)
Definition: BeamSpotPostProcessing.py:474
python.BeamSpotPostProcessing.T0VertexDefaultProcessing.executedSteps
executedSteps
Definition: BeamSpotPostProcessing.py:92
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.BeamSpotPostProcessing.CheckT0Status.run
def run(self)
Definition: BeamSpotPostProcessing.py:307
python.BeamSpotPostProcessing.DQBeamSpotReproc
Definition: BeamSpotPostProcessing.py:408
python.BeamSpotPostProcessing.LinkResults.run
def run(self)
Definition: BeamSpotPostProcessing.py:228
python.BeamSpotPostProcessing.BeamSpotNtNoAve.run
def run(self)
Definition: BeamSpotPostProcessing.py:426
python.BeamSpotPostProcessing.JobPostProcessing.executedSteps
executedSteps
JobPostProcessing runs only on completed tasks in status POSTPROCESSING if self.oldStatus==TaskManage...
Definition: BeamSpotPostProcessing.py:84
python.BeamSpotPostProcessing.TaskPostProcessing
Definition: BeamSpotPostProcessing.py:61
python.BeamSpotPostProcessing.DQBeamSpot
Definition: BeamSpotPostProcessing.py:365
python.BeamSpotPostProcessing.PlotBeamSpotCompareReproc
Definition: BeamSpotPostProcessing.py:139
python.BeamSpotPostProcessing.TaskPostProcessing.executedSteps
executedSteps
Definition: BeamSpotPostProcessing.py:66
python.BeamSpotPostProcessing.ReprocVertexDefaultProcessing
Definition: BeamSpotPostProcessing.py:101
python.BeamSpotPostProcessing.PlotBeamSpotMon.run
def run(self)
Definition: BeamSpotPostProcessing.py:118
TaskManager
python.BeamSpotPostProcessing.ReprocVertexDefaultProcessing.run
def run(self)
Definition: BeamSpotPostProcessing.py:102
python.BeamSpotPostProcessing.PlotBeamSpot
Definition: BeamSpotPostProcessing.py:214
python.BeamSpotPostProcessing.ReprocVertexDefaultProcessing.executedSteps
executedSteps
Definition: BeamSpotPostProcessing.py:106
python.BeamSpotPostProcessing.T0VertexTestProcessing
Definition: BeamSpotPostProcessing.py:94
python.BeamSpotPostProcessing.CheckT0Status
Definition: BeamSpotPostProcessing.py:305
python.BeamSpotPostProcessing.T0VertexDefaultProcessing.run
def run(self)
Definition: BeamSpotPostProcessing.py:88
python.BeamSpotPostProcessing.MergeNt
Definition: BeamSpotPostProcessing.py:196
python.BeamSpotPostProcessing.BCIDDefaultProcessing.run
def run(self)
Definition: BeamSpotPostProcessing.py:110
python.BeamSpotPostProcessing.PlotBeamSpot.run
def run(self)
Definition: BeamSpotPostProcessing.py:215
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.BeamSpotPostProcessing.T0VertexTestProcessing.executedSteps
executedSteps
Definition: BeamSpotPostProcessing.py:99
python.BeamSpotPostProcessing.PlotGlobalMon
Definition: BeamSpotPostProcessing.py:185
python.BeamSpotPostProcessing.PlotBeamSpotCompareReproc.run
def run(self)
Definition: BeamSpotPostProcessing.py:140
python.BeamSpotPostProcessing.PlotOnlineOfflineCompare
Definition: BeamSpotPostProcessing.py:160
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.BeamSpotPostProcessing.JobPostProcessing.run
def run(self)
Definition: BeamSpotPostProcessing.py:70
python.BeamSpotPostProcessing.UploadDataQuality
Definition: BeamSpotPostProcessing.py:413
python.BeamSpotPostProcessing.BeamSpotGlobalNt.run
def run(self)
Definition: BeamSpotPostProcessing.py:449
python.BeamSpotPostProcessing.T0VertexTestProcessing.run
def run(self)
Definition: BeamSpotPostProcessing.py:95
python.BeamSpotPostProcessing.BeamSpotGlobalNt
Definition: BeamSpotPostProcessing.py:448
python.BeamSpotPostProcessing.PlotGlobalMon.run
def run(self)
Definition: BeamSpotPostProcessing.py:186
python.BeamSpotPostProcessing.TaskPostProcessing.run
def run(self)
Definition: BeamSpotPostProcessing.py:62
python.BeamSpotPostProcessing.MergeNt.run
def run(self)
Definition: BeamSpotPostProcessing.py:197
python.BeamSpotPostProcessing.UploadBeamSpot
Definition: BeamSpotPostProcessing.py:327
python.BeamSpotPostProcessing.UploadDataQuality.run
def run(self)
Definition: BeamSpotPostProcessing.py:415
python.PostProcessing.runPostProcStep
def runPostProcStep(taskman, taskDict, oldStatus, previousSteps, step, postprocLib, jobName)
Definition: PostProcessing.py:40
python.BeamSpotPostProcessing.BeamSpotNt.run
def run(self)
Definition: BeamSpotPostProcessing.py:438
python.BeamSpotPostProcessing.PlotBCID
Definition: BeamSpotPostProcessing.py:473
python.BeamSpotPostProcessing.T0VertexDefaultProcessing
Definition: BeamSpotPostProcessing.py:87
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.BeamSpotPostProcessing.JobPostProcessing
Definition: BeamSpotPostProcessing.py:69
python.BeamSpotPostProcessing.UploadBeamSpot.run
def run(self)
Definition: BeamSpotPostProcessing.py:328
python.BeamSpotPostProcessing.PlotBeamSpotMon
Definition: BeamSpotPostProcessing.py:117
python.BeamSpotPostProcessing.BCIDDefaultProcessing.executedSteps
executedSteps
Definition: BeamSpotPostProcessing.py:114
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.BeamSpotPostProcessing.AveBeamSpot.run
def run(self)
Definition: BeamSpotPostProcessing.py:246
python.BeamSpotPostProcessing.PlotOnlineOfflineCompare.run
def run(self)
Definition: BeamSpotPostProcessing.py:161
python.BeamSpotPostProcessing.AveBeamSpot
Definition: BeamSpotPostProcessing.py:245