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