CMS 3D CMS Logo

html.py
Go to the documentation of this file.
1 import os
2 import collections
3 
4 def _lowerFirst(s):
5  return s[0].lower()+s[1:]
6 
7 _sampleName = {
8  "RelValMinBias": "Min Bias",
9  "RelValTTbar": "TTbar",
10  "RelValQCD_Pt_600_800": "QCD Pt 600 to 800",
11  "RelValQCD_Pt_3000_3500": "QCD Pt 3000 to 3500",
12  "RelValQCD_FlatPt_15_3000": "QCD Flat Pt 15 to 3000",
13  "RelValZMM": "ZMuMu",
14  "RelValWjet_Pt_3000_3500": "Wjet Pt 3000 to 3500",
15  "RelValH125GGgluonfusion": "Higgs to gamma gamma",
16  "RelValSingleElectronPt35": "Single Electron Pt 35",
17  "RelValSingleElectronPt35Extended": "Single Electron Pt 35 (extended eta)",
18  "RelValSingleElectronPt10": "Single Electron Pt 10",
19  "RelValSingleMuPt1": "Single Muon Pt 1",
20  "RelValSingleMuPt10": "Single Muon Pt 10",
21  "RelValSingleMuPt10Extended": "Single Muon Pt 10 (extended eta)",
22  "RelValSingleMuPt100": "Single Muon Pt 100",
23  "RelValTenMuE_0_200": "Ten muon Pt 0-200",
24 }
25 
26 _sampleFileName = {
27  "RelValMinBias": "minbias",
28  "RelValTTbar": "ttbar",
29  "RelValQCD_Pt_600_800": "qcd600",
30  "RelValQCD_Pt_3000_3500": "qcd3000",
31  "RelValQCD_FlatPt_15_3000": "qcdflat",
32  "RelValZMM": "zmm",
33  "RelValWjet_Pt_3000_3500": "wjet3000",
34  "RelValH125GGgluonfusion": "hgg",
35  "RelValSingleElectronPt35": "ele35",
36  "RelValSingleElectronPt35Extended": "ele35ext",
37  "RelValSingleElectronPt10": "ele10",
38  "RelValSingleMuPt1": "mu1",
39  "RelValSingleMuPt10": "mu10",
40  "RelValSingleMuPt10Extended": "mu10ext",
41  "RelValSingleMuPt100": "mu100",
42  "RelValTenMuE_0_200": "tenmu200",
43 }
44 
45 _allName = "All tracks"
46 _allTPEfficName = _allName+" (all TPs)"
47 _fromPVName = "Tracks from PV"
48 _fromPVAllTPName = "Tracks from PV (all TPs)"
49 _tpPtLess09Name = "All tracks (TP pT < 0.9 GeV)"
50 _conversionName = "Tracks for conversions"
51 _gsfName = "Electron GSF tracks"
52 _bhadronName = "All tracks (B-hadron TPs)"
53 def _toHP(s):
54  return "High purity "+_lowerFirst(s)
55 def _toOriAlgo(s):
56  return s.replace("tracks", "tracks by originalAlgo")
57 def _toAlgoMask(s):
58  return s.replace("tracks", "tracks by algoMask")
59 def _allToHP(s):
60  return s.replace("All", "High purity")
61 def _allToBTV(s):
62  return s.replace("All", "BTV-like")
64  return s.replace("tracks", "tracks by originalAlgo")
65 def _ptCut(s):
66  return s.replace("Tracks", "Tracks pT > 0.9 GeV").replace("tracks", "tracks pT > 0.9 GeV")
67 _trackQualityNameOrder = collections.OrderedDict([
68  ("seeding_seeds", "Seeds"),
69  ("seeding_seedsa", "Seeds A"),
70  ("seeding_seedsb", "Seeds B"),
71  ("seeding_seedsc", "Seeds C"),
72  ("seeding_seedstripl", "Seeds triplets"),
73  ("seeding_seedspair", "Seeds pairs"),
74  ("building_", "Built tracks"),
75  ("", _allName),
76  ("highPurity", _allToHP(_allName)),
77  ("Pt09", "Tracks pT > 0.9 GeV"),
78  ("highPurityPt09", "High purity tracks pT > 0.9 GeV"),
79  ("ByOriginalAlgo", _toOriAlgo(_allName)),
80  ("highPurityByOriginalAlgo", _toOriAlgo(_toHP(_allName))),
81  ("ByAlgoMask", _toAlgoMask(_allName)),
82  ("highPurityByAlgoMask", _toAlgoMask(_toHP(_allName))),
83  ("tpPtLess09_", _tpPtLess09Name),
84  ("tpPtLess09_highPurity", _allToHP(_tpPtLess09Name)),
85  ("tpPtLess09_ByOriginalAlgo", _byOriginalAlgo(_tpPtLess09Name)),
86  ("tpPtLess09_highPurityByOriginalAlgo", _byOriginalAlgo(_allToHP(_tpPtLess09Name))),
87  ("btvLike", _allToBTV(_allName)),
88  ("ak4PFJets", "AK4 PF jets"),
89  ("allTPEffic_", _allTPEfficName),
90  ("allTPEffic_highPurity", _allToHP(_allTPEfficName)),
91  ("fromPV_", _fromPVName),
92  ("fromPV_highPurity", _toHP(_fromPVName)),
93  ("fromPV_Pt09", _ptCut(_fromPVName)),
94  ("fromPV_highPurityPt09", _toHP(_ptCut(_fromPVName))),
95  ("fromPVAllTP_", _fromPVAllTPName),
96  ("fromPVAllTP_highPurity", _toHP(_fromPVAllTPName)),
97  ("fromPVAllTP_Pt09", _ptCut(_fromPVAllTPName)),
98  ("fromPVAllTP_highPurityPt09", _toHP(_ptCut(_fromPVAllTPName))),
99  ("fromPVAllTP2_", _fromPVAllTPName.replace("PV", "PV v2")),
100  ("fromPVAllTP2_highPurity", "High purity "+_lowerFirst(_fromPVAllTPName).replace("PV", "PV v2")),
101  ("fromPVAllTP2_Pt09", _fromPVAllTPName.replace("Tracks", "Tracks pT > 0.9 GeV").replace("PV", "PV v2")),
102  ("fromPVAllTP2_highPurityPt09", _toHP(_ptCut(_fromPVAllTPName)).replace("PV", "PV v2")),
103  ("conversion_", _conversionName),
104  ("gsf_", _gsfName),
105  ("bhadron_", _bhadronName),
106  ("bhadron_highPurity", _allToHP(_bhadronName)),
107  ("bhadron_ByOriginalAlgo", _toOriAlgo(_bhadronName)),
108  ("bhadron_highPurityByOriginalAlgo", _toOriAlgo(_toHP(_bhadronName))),
109  ("bhadron_ByAlgoMask", _toAlgoMask(_bhadronName)),
110  ("bhadron_highPurityByAlgoMask", _toAlgoMask(_allToHP(_bhadronName))),
111  ("bhadron_btvLike", _allToBTV(_bhadronName)),
112 ])
113 
114 _trackAlgoName = {
115  "ootb": "Out of the box",
116  "iter0" : "Iterative Step 0",
117  "iter1" : "Iterative Step 1",
118  "iter2" : "Iterative Step 2",
119  "iter3" : "Iterative Step 3",
120  "iter4" : "Iterative Step 4",
121  "iter5" : "Iterative Step 5",
122  "iter6" : "Iterative Step 6",
123  "iter7" : "Iterative Step 7",
124  "iter9" : "Iterative Step 9",
125  "iter10": "Iterative Step 10",
126 }
127 
128 _trackAlgoOrder = [
129  'ootb',
130  'initialStepPreSplitting',
131  'initialStep',
132  'highPtTripletStep',
133  'detachedQuadStep',
134  'detachedTripletStep',
135  'lowPtQuadStep',
136  'lowPtTripletStep',
137  'pixelPairStep',
138  'mixedTripletStep',
139  'pixelLessStep',
140  'tobTecStep',
141  'jetCoreRegionalStep',
142  'muonSeededStepInOut',
143  'muonSeededStepOutIn',
144  'duplicateMerge',
145  'convStep',
146  'conversionStep',
147  'ckfInOutFromConversions',
148  'ckfOutInFromConversions',
149  'electronGsf',
150  'iter0',
151  'iter1',
152  'iter2',
153  'iter3',
154  'iter4',
155  'iter5',
156  'iter6',
157  'iter7',
158  'iter9',
159  'iter10',
160 ]
161 
162 _pageNameMap = {
163  "summary": "Summary",
164  "vertex": "Vertex",
165  "v0": "V0",
166  "miniaod": "MiniAOD",
167  "timing": "Timing",
168  "hlt": "HLT",
169 }
170 
171 _sectionNameMapOrder = collections.OrderedDict([
172  # These are for the summary page
173  ("seeding_seeds", "Seeds"),
174  ("building", "Built tracks"),
175  ("", "All tracks"),
176  ("Pt09", "All tracks (pT>0.9 GeV)"),
177  ("highPurity", "High purity tracks"),
178  ("highPurityPt09", "High purity tracks (pT>0.9 GeV)"),
179  ("tpPtLess09", _tpPtLess09Name),
180  ("tpPtLess09_highPurity", _allToHP(_tpPtLess09Name)),
181  ("btvLike", "BTV-like"),
182  ("ak4PFJets", "AK4 PF jets"),
183  ("allTPEffic", _allTPEfficName),
184  ("allTPEffic_highPurity", _allToHP(_allTPEfficName)),
185  ("fromPV", _fromPVName),
186  ("fromPV_highPurity", "High purity "+_lowerFirst(_fromPVName)),
187  ("fromPVAllTP", _fromPVAllTPName),
188  ("fromPVAllTP_highPurity", "High purity "+_lowerFirst(_fromPVAllTPName)),
189  ("conversion", _conversionName),
190  ("gsf", _gsfName),
191  ("bhadron", _bhadronName),
192  ("bhadron_highPurity", _allToHP(_bhadronName)),
193  # These are for vertices
194  ("genvertex", "Gen vertices"),
195  ("pixelVertices", "Pixel vertices"),
196  ("selectedPixelVertices", "Selected pixel vertices"),
197  ("firstStepPrimaryVerticesPreSplitting", "firstStepPrimaryVerticesPreSplitting"),
198  ("firstStepPrimaryVertices", "firstStepPrimaryVertices"),
199  ("offlinePrimaryVertices", "All vertices (offlinePrimaryVertices)"),
200  ("selectedOfflinePrimaryVertices", "Selected vertices (selectedOfflinePrimaryVertices)"),
201  ("offlinePrimaryVerticesWithBS", "All vertices with BS constraint"),
202  ("selectedOfflinePrimaryVerticesWithBS", "Selected vertices with BS constraint"),
203  # These are for V0
204  ("k0", "K0"),
205  ("lambda", "Lambda"),
206 ])
207 _btvLegend = "BTV-like selected tracks"
208 _allTPEfficLegend = "All tracks, efficiency denominator contains all TrackingParticles"
209 _fromPVLegend = "Tracks from reco PV vs. TrackingParticles from gen PV (fake rate includes pileup tracks)"
210 _fromPVPtLegend = "Tracks (pT > 0.9 GeV) from reco PV vs. TrackingParticles from gen PV (fake rate includes pileup tracks)"
211 _fromPVAllTPLegend = "Tracks from reco PV, fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
212 _fromPVAllTPPtLegend = "Tracks (pT > 0.9 GeV) from reco PV, fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
213 _fromPVAllTP2Legend = "Tracks from reco PV (another method), fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
214 _fromPVAllTPPt2Legend = "Tracks (pT > 0.9 GeV) from reco PV (another method), fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
215 _bhadronLegend = "All tracks, efficiency denominator contains only TrackingParticles from B-hadron decays"
216 
218  return {
219  "btvLike": _btvLegend,
220  "ak4PFJets": "Tracks from AK4 PF jets (jet corrected pT > 10 GeV)",
221  "allTPEffic": _allTPEfficLegend,
222  "allTPEffic_": _allTPEfficLegend,
223  "allTPEffic_highPurity": _allToHP(_allTPEfficLegend),
224  "fromPV": _fromPVLegend,
225  "fromPV_": _fromPVLegend,
226  "fromPV_highPurity": _toHP(_fromPVLegend),
227  "fromPV_Pt09": _fromPVPtLegend,
228  "fromPV_highPurity_Pt09": _toHP(_fromPVPtLegend),
229  "fromPVAllTP": _fromPVAllTPLegend,
230  "fromPVAllTP_": _fromPVAllTPLegend,
231  "fromPVAllTP_highPurity": _toHP(_fromPVAllTPLegend),
232  "fromPVAllTP_Pt09": _fromPVAllTPPtLegend,
233  "fromPVAllTP_highPurityPt09": _toHP(_fromPVAllTPPtLegend),
234  "fromPVAllTP2_": _fromPVAllTP2Legend,
235  "fromPVAllTP2_highPurity": _toHP(_fromPVAllTP2Legend),
236  "fromPVAllTP2_Pt09": _fromPVAllTPPt2Legend,
237  "fromPVAllTP2_highPurityPt09": _toHP(_fromPVAllTPPt2Legend),
238  "bhadron_": _bhadronLegend,
239  "bhadron_highPurity": _allToHP(_bhadronLegend),
240  "bhadron_btvLike": _bhadronLegend.replace("All tracks", _btvLegend),
241  }
242 
243 class Table:
244  # table [column][row]
245  def __init__(self, columnHeaders, rowHeaders, table, purpose, page, section):
246  if len(columnHeaders) != len(table):
247  raise Exception("Got %d columnHeaders for table with %d columns for page %s, section %s" % (len(columnHeaders), len(table), page, section))
248  lenRow = len(table[0])
249  for icol, column in enumerate(table):
250  if len(column) != lenRow:
251  raise Exception("Got non-square table, first column has %d rows, column %d has %d rows" % (lenRow, icol, len(column)))
252  if len(rowHeaders) != lenRow:
253  raise Exception("Got %d rowHeaders for table with %d rows" % (len(rowHeaders), lenRow))
254 
255  self._columnHeaders = columnHeaders
256  self._rowHeaders = rowHeaders
257  self._table = table
258 
259  self._purpose = purpose
260  self._page = page
261  self._section = section
262 
263  def getPurpose(self):
264  return self._purpose
265 
266  def getPage(self):
267  return self._page
268 
269  def getSection(self):
270  return self._section
271 
272  def ncolumns(self):
273  return len(self._table)
274 
275  def nrows(self):
276  return len(self._table[0])
277 
278  def columnHeaders(self):
279  return self._columnHeaders
280 
281  def rowHeaders(self):
282  return self._rowHeaders
283 
284  def tableAsColumnRow(self):
285  return self._table
286 
287  def tableAsRowColumn(self):
288  return map(list, zip(*self._table))
289 
291  class TrackingIteration: pass
292  class TrackingSummary: pass
293  class Vertexing: pass
294  class MiniAOD: pass
295  class Timing: pass
296  class HLT: pass
297 
298 class Page(object):
299  def __init__(self, title, sampleName):
300  self._content = [
301  '<html>',
302  ' <head>',
303  ' <title>%s</title>' % title,
304  ' </head>',
305  ' <body>',
306  ' '+sampleName,
307  ' <br/>',
308  ' <br/>',
309  ]
310 
311  self._plotSets = {}
312  self._tables = {}
313 
314  def addPlotSet(self, section, plotSet):
315  if section in self._plotSets:
316  self._plotSets[section].extend(plotSet)
317  else:
318  self._plotSets[section] = plotSet
319 
320  def addTable(self, section, table):
321  self._tables[section] = table
322 
323  def isEmpty(self):
324  for plotSet in self._plotSets.itervalues():
325  if len(plotSet) > 0:
326  return False
327 
328  if len(self._tables) > 0:
329  return False
330 
331  return True
332 
333  def write(self, fileName):
334  self._legends = []
336  self._columnHeaders = []
338  self._formatPlotSets()
339  self._formatTables()
340  self._formatLegend()
341 
342  self._content.extend([
343  ' </body>',
344  '</html>',
345  ])
346 
347  #print "Writing HTML report page", fileName
348  f = open(fileName, "w")
349  for line in self._content:
350  f.write(line)
351  f.write("\n")
352  f.close()
353 
354  def _appendLegend(self, section):
355  leg = ""
356  legends = _sectionNameLegend()
357  if section in legends:
358  if section in self._sectionLegendIndex:
359  leg = self._sectionLegendIndex[section]
360  else:
361  legnum = len(self._legends)+1
362  leg = "<sup>%d</sup>" % legnum
363  leg2 = "<sup>%d)</sup>" % legnum
364  self._legends.append("%s %s" % (leg2, legends[section]))
365  self._sectionLegendIndex[section] = leg
366  return leg
367 
368  def _formatPlotSets(self):
369  self._content.extend([
370  ' <table>'
371  ' <tr>',
372  ])
373 
374  fileTable = []
375 
376  sections = self._orderSets(self._plotSets.keys())
377  for isec, section in enumerate(sections):
378  leg = self._appendLegend(section)
379 
380  self._content.extend([
381  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
382  ])
383  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
384  for row in fileTable:
385  found = False
386  for i, (bsf, f) in enumerate(files):
387  if bsf == row[0]:
388  row.append(f)
389  found = True
390  del files[i]
391  break
392  if not found:
393  row.append(None)
394  for bsf, f in files:
395  fileTable.append( [bsf] + [None]*isec + [f] )
396 
397  self._content.extend([
398  ' </tr>',
399  ])
400 
401  for row in fileTable:
402  self._content.append(' <tr>')
403  bs = row[0]
404  for elem in row[1:]:
405  if elem is not None:
406  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
407  else:
408  self._content.append(' <td></td>')
409  self._content.append(' </tr>')
410 
411 
412  self._content.extend([
413  ' </table>',
414  ])
415 
416  def _appendColumnHeader(self, header):
417  leg = ""
418  if header in self._columnHeadersIndex:
419  leg = self._columnHeadersIndex[header]
420  else:
421  leg = str(chr(ord('A')+len(self._columnHeaders)))
422  self._columnHeaders.append("%s: %s" % (leg, header))
423  self._columnHeadersIndex[header] = leg
424  return leg
425 
426  def _formatTables(self):
427  def _allNone(row):
428  for item in row:
429  if item is not None:
430  return False
431  return True
432 
433  sections = self._orderSets(self._tables.keys())
434  for isec, section in enumerate(sections):
435  leg = self._appendLegend(section)
436 
437  table = self._tables[section]
438  self._content.extend([
439  ' <br/>',
440  ' %s%s' % (self._mapSectionName(section), leg),
441  ' <table border="1">'
442  ])
443 
444  # table is stored in column-row, need to transpose
445  data = table.tableAsRowColumn()
446 
447  self._content.extend([
448  ' <tr>'
449  ' <td></td>'
450  ])
451  heads = table.columnHeaders()
452  if max(map(lambda h: len(h), heads)) > 20:
453  heads = [self._appendColumnHeader(h) for h in heads]
454  for head in heads:
455  self._content.append(' <td>%s</td>' % head)
456  self._content.append(' </tr>')
457 
458  for irow, row in enumerate(data):
459  # Skip row if all values are non-existent
460  if _allNone(row):
461  continue
462 
463  self._content.extend([
464  ' <tr>'
465  ' <td>%s</td>' % table.rowHeaders()[irow]
466  ])
467  # align the number columns to right
468  for icol, item in enumerate(row):
469  formatted = str(item) if item is not None else ""
470  self._content.append(' <td align="right">%s</td>' % formatted)
471  self._content.append(' </tr>')
472 
473  self._content.append(' </table>')
474 
475  for shortenedColumnHeader in self._columnHeaders:
476  self._content.append(' %s<br/>' % shortenedColumnHeader)
477  self._columnHeaders = []
478  self._columnHeadersIndex = {}
479 
480  def _formatLegend(self):
481  if len(self._legends) > 0:
482  self._content.extend([
483  ' <br/>'
484  ' Details:</br>',
485  ])
486  for leg in self._legends:
487  self._content.append(' %s<br/>' % leg)
488 
489 
490  def _mapSectionName(self, section):
491  return _sectionNameMapOrder.get(section, section)
492 
493  def _orderSets(self, keys):
494  keys_sorted = sorted(keys)
495  ret = []
496  for section in _sectionNameMapOrder.keys():
497  if section in keys_sorted:
498  ret.append(section)
499  keys_sorted.remove(section)
500  ret.extend(keys_sorted)
501  return ret
502 
504  def __init__(self, title, sampleName, sample, fastVsFull, pileupComparison, dqmSubFolderTranslatedToSectionName=None):
505  self._title = title
506  self._sampleName = sampleName
507  self._pages = collections.OrderedDict()
508  self._dqmSubFolderTranslatedToSectionName = dqmSubFolderTranslatedToSectionName
509 
510  self._prefix = ""
511  if sample.fastsim():
512  self._prefix += "fast_"
513  if fastVsFull:
514  self._prefix += "full_"
515 
516  self._prefix += _sampleFileName.get(sample.label(), sample.label())+"_"
517  if hasattr(sample, "hasScenario") and sample.hasScenario():
518  self._prefix += sample.scenario()+"_"
519 
520  if hasattr(sample, "hasPileup"):
521  if sample.hasPileup():
522  self._prefix += "pu"+str(sample.pileupNumber())+"_"+sample.pileupType()+"_"
523  else:
524  self._prefix += "nopu_"
525  if pileupComparison:
526  self._prefix += "vspu_"
527 
528 
529  def _getPage(self, key, pageClass):
530  if key not in self._pages:
531  page = pageClass(self._title, self._sampleName)
532  self._pages[key] = page
533  else:
534  page = self._pages[key]
535  return page
536 
537  def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles):
538  pageKey = plotterFolder.getPage()
539  if pageKey is None:
540  if dqmSubFolder is not None:
541  pageKey = dqmSubFolder.translated
542  else:
543  pageKey = plotterFolder.getName()
544 
545  page = self._getPage(pageKey, Page)
546  sectionName = plotterFolder.getSection()
547  if sectionName is None:
548  if plotterFolder.getPage() is not None and dqmSubFolder is not None:
549  if self._dqmSubFolderTranslatedToSectionName is not None:
550  sectionName = self._dqmSubFolderTranslatedToSectionName(dqmSubFolder.translated)
551  else:
552  sectionName = dqmSubFolder.translated
553  else:
554  sectionName = ""
555 
556  page.addPlotSet(sectionName, plotFiles)
557 
558  def addTable(self, table):
559  if table is None:
560  return
561 
562  page = self._getPage(table.getPage(), Page)
563  page.addTable(table.getSection(), table)
564 
565  def write(self, baseDir):
566  #print "TrackingPageSet.write"
567  ret = []
568 
569  keys = self._orderPages(self._pages.keys())
570  for key in keys:
571  page = self._pages[key]
572  if page.isEmpty():
573  continue
574 
575  fileName = "%s%s.html" % (self._prefix, key)
576  page.write(os.path.join(baseDir, fileName))
577  ret.append( (self._mapPagesName(key), fileName) )
578  return ret
579 
580  def _mapPagesName(self, name):
581  return _pageNameMap.get(name, name)
582 
583  def _orderPages(self, keys):
584  return keys
585 
586 
587 
589  def __init__(self, *args, **kwargs):
590  super(TrackingIterPage, self).__init__(*args, **kwargs)
591 
592  def _mapSectionName(self, quality):
593  return _trackQualityNameOrder.get(quality, quality)
594 
595  def _orderSets(self, qualities):
596  ret = []
597  for qual in _trackQualityNameOrder.keys():
598  if qual in qualities:
599  ret.append(qual)
600  qualities.remove(qual)
601  ret.extend(qualities)
602  return ret
603 
605  def __init__(self, *args, **kwargs):
606  super(TrackingPageSet, self).__init__(*args, **kwargs)
607 
608  def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles):
609  (algo, quality) = dqmSubFolder.translated
610 
611  pageName = algo
612  sectionName = quality
613 
614  # put all non-iterative stuff under OOTB
615  #
616  # it is bit of a hack to access trackingPlots.TrackingPlotFolder this way,
617  # but it was simple and it works
618  if algo != "ootb" and not plotterFolder._plotFolder.isAlgoIterative(algo):
619  pageName = "ootb"
620  sectionName = algo
621 
622  folderName = plotterFolder.getName()
623  if folderName != "":
624  sectionName = folderName+"_"+sectionName
625 
626  page = self._getPage(pageName, TrackingIterPage)
627  page.addPlotSet(sectionName, plotFiles)
628 
629  def _mapPagesName(self, algo): # algo = pageName
630  return _trackAlgoName.get(algo, algo)
631 
632  def _orderPages(self, algos):
633  ret = []
634  for algo in _trackAlgoOrder:
635  if algo in algos:
636  ret.append(algo)
637  algos.remove(algo)
638  ret.extend(algos)
639  return ret
640 
641 
642 
644  def __init__(self, sample, title, fastVsFull, pileupComparison):
645  self._sample = sample
646 
647  self._sampleName = ""
648  if sample.fastsim():
649  self._sampleName += "FastSim "
650  if fastVsFull:
651  self._sampleName += "vs FullSim "
652 
653  pileup = ""
654  if hasattr(sample, "hasPileup"):
655  pileup = "with no pileup"
656  if sample.hasPileup():
657  pileup = "with %d pileup (%s)" % (sample.pileupNumber(), sample.pileupType())
658  if pileupComparison is not None:
659  pileup += " "+pileupComparison
660  if hasattr(sample, "customPileupLabel"):
661  pileup = sample.customPileupLabel()
662 
663  scenario = ""
664  if hasattr(sample, "hasScenario") and sample.hasScenario():
665  scenario = " (\"%s\")" % sample.scenario()
666  self._sampleName += "%s sample%s %s" % (_sampleName.get(sample.name(), sample.name()), scenario, pileup)
667 
668  params = [title, self._sampleName, sample, fastVsFull, pileupComparison is not None]
669  self._summaryPage = PageSet(*params)
671  self._vertexPage = PageSet(*params)
672  self._miniaodPage = PageSet(*params)
673  self._timingPage = PageSet(*params)
674  self._hltPages = PageSet(*params, dqmSubFolderTranslatedToSectionName=lambda algoQuality: algoQuality[0])
675  self._otherPages = PageSet(*params)
676 
684  }
685 
686  def addPlots(self, plotterFolder, dqmSubFolder, plotFiles):
687  page = self._purposePageMap.get(plotterFolder.getPurpose(), self._otherPages)
688  page.addPlotSet(plotterFolder, dqmSubFolder, plotFiles)
689 
690  def addTable(self, table):
691  if table is None:
692  return
693 
694  page = self._purposePageMap.get(table.getPurpose(), self._otherPages)
695  page.addTable(table)
696  params = []
697 
698  def write(self, baseDir):
699  ret = [
700  " "+self._sampleName,
701  " <br/>",
702  " <ul>",
703  ]
704 
705  for pages in [self._summaryPage, self._iterationPages, self._vertexPage, self._miniaodPage, self._timingPage, self._hltPages, self._otherPages]:
706  labelFiles = pages.write(baseDir)
707  for label, fname in labelFiles:
708  ret.append(' <li><a href="%s">%s</a></li>' % (fname, label))
709 
710  ret.extend([
711  ' </ul>',
712  ' <br/>',
713  ])
714 
715  return ret
716 
718  def __init__(self, validationName, newBaseDir):
719  self._title = "Tracking validation "+validationName
720  self._newBaseDir = newBaseDir
721 
722  self._index = [
723  '<html>',
724  ' <head>',
725  ' <title>%s</title>' % self._title,
726  ' </head>',
727  ' <body>',
728  ]
729 
730  self._sections = collections.OrderedDict()
731 
732  def addNote(self, note):
733  self._index.append(' <p>%s</p>'%note)
734 
735  def beginSample(self, sample, fastVsFull=False, pileupComparison=None):
736  # Fast vs. Full becomes just after the corresponding Fast
737  # Same for PU
738  rightAfterRefSample = fastVsFull or (pileupComparison is not None)
739 
740  key = (sample.digest(), rightAfterRefSample)
741  if key in self._sections:
742  self._currentSection = self._sections[key]
743  else:
744  self._currentSection = IndexSection(sample, self._title, fastVsFull, pileupComparison)
745  self._sections[key] = self._currentSection
746 
747  def addPlots(self, *args, **kwargs):
748  self._currentSection.addPlots(*args, **kwargs)
749 
750  def addTable(self, *args, **kwargs):
751  self._currentSection.addTable(*args, **kwargs)
752 
753  def write(self):
754  # Reorder sections such that Fast vs. Full becomes just after the corresponding Fast
755  keys = self._sections.iterkeys()
756  newkeys = []
757  for key in keys:
758  if not key[1]:
759  newkeys.append(key)
760  continue
761  # is fast vs full
762  ind_fast = newkeys.index( (key[0], False) )
763  newkeys.insert(ind_fast+1, key)
764 
765  for key in newkeys:
766  section = self._sections[key]
767  self._index.extend(section.write(self._newBaseDir))
768 
769  self._index.extend([
770  " </body>",
771  "</html>",
772  ])
773 
774  f = open(os.path.join(self._newBaseDir, "index.html"), "w")
775  for line in self._index:
776  f.write(line)
777  f.write("\n")
778  f.close()
779 
781  def __init__(self):
782  pass
783 
784  def beginSample(self, *args, **kwargs):
785  pass
786 
787  def addPlots(self, *args, **kwargs):
788  pass
789 
790  def addTable(self, *args, **kwargs):
791  pass
def _appendColumnHeader(self, header)
Definition: html.py:416
_purpose
Definition: html.py:259
def write(self, fileName)
Definition: html.py:333
_dqmSubFolderTranslatedToSectionName
Definition: html.py:508
def __init__(self, columnHeaders, rowHeaders, table, purpose, page, section)
Definition: html.py:245
def addTable(self, args, kwargs)
Definition: html.py:750
_legends
Definition: html.py:334
def write(self, baseDir)
Definition: html.py:698
def addTable(self, args, kwargs)
Definition: html.py:790
def _lowerFirst(s)
Definition: html.py:4
def addPlots(self, args, kwargs)
Definition: html.py:747
def _toAlgoMask(s)
Definition: html.py:57
_content
Definition: html.py:300
def __init__(self, args, kwargs)
Definition: html.py:589
def _formatLegend(self)
Definition: html.py:480
def isEmpty(self)
Definition: html.py:323
def _mapPagesName(self, name)
Definition: html.py:580
_rowHeaders
Definition: html.py:256
def __init__(self, sample, title, fastVsFull, pileupComparison)
Definition: html.py:644
def replace(string, replacements)
def __init__(self, title, sampleName)
Definition: html.py:299
def addNote(self, note)
Definition: html.py:732
def _mapPagesName(self, algo)
Definition: html.py:629
_columnHeaders
Definition: html.py:255
def _allToHP(s)
Definition: html.py:59
def _orderSets(self, qualities)
Definition: html.py:595
def _orderSets(self, keys)
Definition: html.py:493
def _toOriAlgo(s)
Definition: html.py:55
def _byOriginalAlgo(s)
Definition: html.py:63
def getPage(self)
Definition: html.py:266
def __init__(self, title, sampleName, sample, fastVsFull, pileupComparison, dqmSubFolderTranslatedToSectionName=None)
Definition: html.py:504
def _mapSectionName(self, section)
Definition: html.py:490
def __init__(self, args, kwargs)
Definition: html.py:605
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def _allToBTV(s)
Definition: html.py:61
def addTable(self, table)
Definition: html.py:558
def addPlots(self, args, kwargs)
Definition: html.py:787
def __init__(self)
Definition: html.py:781
def _orderPages(self, algos)
Definition: html.py:632
def _appendLegend(self, section)
Definition: html.py:354
_columnHeaders
Definition: html.py:336
def columnHeaders(self)
Definition: html.py:278
def addPlotSet(self, section, plotSet)
Definition: html.py:314
def getSection(self)
Definition: html.py:269
def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:537
def addTable(self, table)
Definition: html.py:690
_plotSets
Definition: html.py:311
def _getPage(self, key, pageClass)
Definition: html.py:529
def _mapSectionName(self, quality)
Definition: html.py:592
def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:608
def _formatTables(self)
Definition: html.py:426
def ncolumns(self)
Definition: html.py:272
_columnHeadersIndex
Definition: html.py:337
_section
Definition: html.py:261
def _formatPlotSets(self)
Definition: html.py:368
def rowHeaders(self)
Definition: html.py:281
_tables
Definition: html.py:312
def getPurpose(self)
Definition: html.py:263
def tableAsRowColumn(self)
Definition: html.py:287
def beginSample(self, sample, fastVsFull=False, pileupComparison=None)
Definition: html.py:735
def beginSample(self, args, kwargs)
Definition: html.py:784
def __init__(self, validationName, newBaseDir)
Definition: html.py:718
def tableAsColumnRow(self)
Definition: html.py:284
def addPlots(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:686
def write(self)
Definition: html.py:753
def _sectionNameLegend()
Definition: html.py:217
_sectionLegendIndex
Definition: html.py:335
def _ptCut(s)
Definition: html.py:65
def _orderPages(self, keys)
Definition: html.py:583
def nrows(self)
Definition: html.py:275
def _toHP(s)
Definition: html.py:53
def addTable(self, section, table)
Definition: html.py:320
def write(self, baseDir)
Definition: html.py:565