CMS 3D CMS Logo

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