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  "pf": "PF",
172 }
173 
174 _sectionNameMapOrder = collections.OrderedDict([
175  # These are for the summary page
176  ("seeding_seeds", "Seeds"),
177  ("building", "Built tracks"),
178  ("", "All tracks"),
179  ("Pt09", "All tracks (pT>0.9 GeV)"),
180  ("highPurity", "High purity tracks"),
181  ("highPurityPt09", "High purity tracks (pT>0.9 GeV)"),
182  ("tpPtLess09", _tpPtLess09Name),
183  ("tpPtLess09_highPurity", _allToHP(_tpPtLess09Name)),
184  ("btvLike", "BTV-like"),
185  ("ak4PFJets", "AK4 PF jets"),
186  ("allTPEffic", _allTPEfficName),
187  ("allTPEffic_highPurity", _allToHP(_allTPEfficName)),
188  ("fromPV", _fromPVName),
189  ("fromPV_highPurity", "High purity "+_lowerFirst(_fromPVName)),
190  ("fromPVAllTP", _fromPVAllTPName),
191  ("fromPVAllTP_highPurity", "High purity "+_lowerFirst(_fromPVAllTPName)),
192  ("conversion", _conversionName),
193  ("gsf", _gsfName),
194  ("bhadron", _bhadronName),
195  ("bhadron_highPurity", _allToHP(_bhadronName)),
196  # Pixel tracks
197  ("pixel", "Pixel tracks"),
198  # These are for vertices
199  ("genvertex", "Gen vertices"),
200  ("pixelVertices", "Pixel vertices"),
201  ("selectedPixelVertices", "Selected pixel vertices"),
202  ("firstStepPrimaryVerticesPreSplitting", "firstStepPrimaryVerticesPreSplitting"),
203  ("firstStepPrimaryVertices", "firstStepPrimaryVertices"),
204  ("offlinePrimaryVertices", "All vertices (offlinePrimaryVertices)"),
205  ("selectedOfflinePrimaryVertices", "Selected vertices (selectedOfflinePrimaryVertices)"),
206  ("offlinePrimaryVerticesWithBS", "All vertices with BS constraint"),
207  ("selectedOfflinePrimaryVerticesWithBS", "Selected vertices with BS constraint"),
208  # These are for V0
209  ("k0", "K0"),
210  ("lambda", "Lambda"),
211 ])
212 _btvLegend = "BTV-like selected tracks"
213 _allTPEfficLegend = "All tracks, efficiency denominator contains all TrackingParticles"
214 _fromPVLegend = "Tracks from reco PV vs. TrackingParticles from gen PV (fake rate includes pileup tracks)"
215 _fromPVPtLegend = "Tracks (pT > 0.9 GeV) from reco PV vs. TrackingParticles from gen PV (fake rate includes pileup tracks)"
216 _fromPVAllTPLegend = "Tracks from reco PV, fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
217 _fromPVAllTPPtLegend = "Tracks (pT > 0.9 GeV) from reco PV, fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
218 _fromPVAllTP2Legend = "Tracks from reco PV (another method), fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
219 _fromPVAllTPPt2Legend = "Tracks (pT > 0.9 GeV) from reco PV (another method), fake rate numerator contains all TrackingParticles (separates fake tracks from pileup tracks)"
220 _bhadronLegend = "All tracks, efficiency denominator contains only TrackingParticles from B-hadron decays"
221 
223  return {
224  "btvLike": _btvLegend,
225  "ak4PFJets": "Tracks from AK4 PF jets (jet corrected pT > 10 GeV)",
226  "allTPEffic": _allTPEfficLegend,
227  "allTPEffic_": _allTPEfficLegend,
228  "allTPEffic_highPurity": _allToHP(_allTPEfficLegend),
229  "fromPV": _fromPVLegend,
230  "fromPV_": _fromPVLegend,
231  "fromPV_highPurity": _toHP(_fromPVLegend),
232  "fromPV_Pt09": _fromPVPtLegend,
233  "fromPV_highPurity_Pt09": _toHP(_fromPVPtLegend),
234  "fromPVAllTP": _fromPVAllTPLegend,
235  "fromPVAllTP_": _fromPVAllTPLegend,
236  "fromPVAllTP_highPurity": _toHP(_fromPVAllTPLegend),
237  "fromPVAllTP_Pt09": _fromPVAllTPPtLegend,
238  "fromPVAllTP_highPurityPt09": _toHP(_fromPVAllTPPtLegend),
239  "fromPVAllTP2_": _fromPVAllTP2Legend,
240  "fromPVAllTP2_highPurity": _toHP(_fromPVAllTP2Legend),
241  "fromPVAllTP2_Pt09": _fromPVAllTPPt2Legend,
242  "fromPVAllTP2_highPurityPt09": _toHP(_fromPVAllTPPt2Legend),
243  "bhadron_": _bhadronLegend,
244  "bhadron_highPurity": _allToHP(_bhadronLegend),
245  "bhadron_btvLike": _bhadronLegend.replace("All tracks", _btvLegend),
246  }
247 
248 class Table:
249  # table [column][row]
250  def __init__(self, columnHeaders, rowHeaders, table, purpose, page, section):
251  if len(columnHeaders) != len(table):
252  raise Exception("Got %d columnHeaders for table with %d columns for page %s, section %s" % (len(columnHeaders), len(table), page, section))
253  lenRow = len(table[0])
254  for icol, column in enumerate(table):
255  if len(column) != lenRow:
256  raise Exception("Got non-square table, first column has %d rows, column %d has %d rows" % (lenRow, icol, len(column)))
257  if len(rowHeaders) != lenRow:
258  raise Exception("Got %d rowHeaders for table with %d rows" % (len(rowHeaders), lenRow))
259 
260  self._columnHeaders = columnHeaders
261  self._rowHeaders = rowHeaders
262  self._table = table
263 
264  self._purpose = purpose
265  self._page = page
266  self._section = section
267 
268  def getPurpose(self):
269  return self._purpose
270 
271  def getPage(self):
272  return self._page
273 
274  def getSection(self):
275  return self._section
276 
277  def ncolumns(self):
278  return len(self._table)
279 
280  def nrows(self):
281  return len(self._table[0])
282 
283  def columnHeaders(self):
284  return self._columnHeaders
285 
286  def rowHeaders(self):
287  return self._rowHeaders
288 
289  def tableAsColumnRow(self):
290  return self._table
291 
292  def tableAsRowColumn(self):
293  return map(list, zip(*self._table))
294 
296  class TrackingIteration: pass
297  class TrackingSummary: pass
298  class Vertexing: pass
299  class MiniAOD: pass
300  class Timing: pass
301  class HLT: pass
302  class Pixel: pass
303  class PF: pass
304 
305 class Page(object):
306  def __init__(self, title, sampleName):
307  self._content = [
308  '<html>',
309  ' <head>',
310  ' <title>%s</title>' % title,
311  ' </head>',
312  ' <body>',
313  ' '+sampleName,
314  ' <br/>',
315  ' <br/>',
316  ]
317 
318  self._plotSets = {}
319  self._tables = {}
320 
321  def addPlotSet(self, section, plotSet):
322  if section in self._plotSets:
323  self._plotSets[section].extend(plotSet)
324  else:
325  self._plotSets[section] = plotSet
326 
327  def addTable(self, section, table):
328  self._tables[section] = table
329 
330  def isEmpty(self):
331  for plotSet in six.itervalues(self._plotSets):
332  if len(plotSet) > 0:
333  return False
334 
335  if len(self._tables) > 0:
336  return False
337 
338  return True
339 
340  def write(self, fileName):
341  self._legends = []
343  self._columnHeaders = []
345  self._formatPlotSets()
346  self._formatTables()
347  self._formatLegend()
348 
349  self._content.extend([
350  ' </body>',
351  '</html>',
352  ])
353 
354  #print "Writing HTML report page", fileName
355  f = open(fileName, "w")
356  for line in self._content:
357  f.write(line)
358  f.write("\n")
359  f.close()
360 
361  def _appendLegend(self, section):
362  leg = ""
363  legends = _sectionNameLegend()
364  if section in legends:
365  if section in self._sectionLegendIndex:
366  leg = self._sectionLegendIndex[section]
367  else:
368  legnum = len(self._legends)+1
369  leg = "<sup>%d</sup>" % legnum
370  leg2 = "<sup>%d)</sup>" % legnum
371  self._legends.append("%s %s" % (leg2, legends[section]))
372  self._sectionLegendIndex[section] = leg
373  return leg
374 
375  def _formatPlotSets(self):
376  self._content.extend([
377  ' <table>'
378  ' <tr>',
379  ])
380 
381  fileTable = []
382 
383  sections = self._orderSets(self._plotSets.keys())
384  for isec, section in enumerate(sections):
385  leg = self._appendLegend(section)
386 
387  self._content.extend([
388  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
389  ])
390  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
391  for row in fileTable:
392  found = False
393  for i, (bsf, f) in enumerate(files):
394  if bsf == row[0]:
395  row.append(f)
396  found = True
397  del files[i]
398  break
399  if not found:
400  row.append(None)
401  for bsf, f in files:
402  fileTable.append( [bsf] + [None]*isec + [f] )
403 
404  self._content.extend([
405  ' </tr>',
406  ])
407 
408  for row in fileTable:
409  self._content.append(' <tr>')
410  bs = row[0]
411  for elem in row[1:]:
412  if elem is not None:
413  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
414  else:
415  self._content.append(' <td></td>')
416  self._content.append(' </tr>')
417 
418 
419  self._content.extend([
420  ' </table>',
421  ])
422 
423  if len(fileTable):
424  first_row = fileTable[0]
425  self._content.extend([
426  ' <a href="%s">Browse Folder</a>' % (first_row[1][0:first_row[1].rfind('/')])
427  ])
428 
429  def _appendColumnHeader(self, header):
430  leg = ""
431  if header in self._columnHeadersIndex:
432  leg = self._columnHeadersIndex[header]
433  else:
434  leg = str(chr(ord('A')+len(self._columnHeaders)))
435  self._columnHeaders.append("%s: %s" % (leg, header))
436  self._columnHeadersIndex[header] = leg
437  return leg
438 
439  def _formatTables(self):
440  def _allNone(row):
441  for item in row:
442  if item is not None:
443  return False
444  return True
445 
446  sections = self._orderSets(self._tables.keys())
447  for isec, section in enumerate(sections):
448  leg = self._appendLegend(section)
449 
450  table = self._tables[section]
451  self._content.extend([
452  ' <br/>',
453  ' %s%s' % (self._mapSectionName(section), leg),
454  ' <table border="1">'
455  ])
456 
457  # table is stored in column-row, need to transpose
458  data = table.tableAsRowColumn()
459 
460  self._content.extend([
461  ' <tr>'
462  ' <td></td>'
463  ])
464  heads = table.columnHeaders()
465  if max(map(lambda h: len(h), heads)) > 20:
466  heads = [self._appendColumnHeader(h) for h in heads]
467  for head in heads:
468  self._content.append(' <td>%s</td>' % head)
469  self._content.append(' </tr>')
470 
471  for irow, row in enumerate(data):
472  # Skip row if all values are non-existent
473  if _allNone(row):
474  continue
475 
476  self._content.extend([
477  ' <tr>'
478  ' <td>%s</td>' % table.rowHeaders()[irow]
479  ])
480  # align the number columns to right
481  for icol, item in enumerate(row):
482  formatted = str(item) if item is not None else ""
483  self._content.append(' <td align="right">%s</td>' % formatted)
484  self._content.append(' </tr>')
485 
486  self._content.append(' </table>')
487 
488  for shortenedColumnHeader in self._columnHeaders:
489  self._content.append(' %s<br/>' % shortenedColumnHeader)
490  self._columnHeaders = []
491  self._columnHeadersIndex = {}
492 
493  def _formatLegend(self):
494  if len(self._legends) > 0:
495  self._content.extend([
496  ' <br/>'
497  ' Details:</br>',
498  ])
499  for leg in self._legends:
500  self._content.append(' %s<br/>' % leg)
501 
502 
503  def _mapSectionName(self, section):
504  return _sectionNameMapOrder.get(section, section)
505 
506  def _orderSets(self, keys):
507  keys_sorted = sorted(keys)
508  ret = []
509  for section in _sectionNameMapOrder.keys():
510  if section in keys_sorted:
511  ret.append(section)
512  keys_sorted.remove(section)
513  ret.extend(keys_sorted)
514  return ret
515 
517  def __init__(self, title, sampleName, sample, fastVsFull, pileupComparison, dqmSubFolderTranslatedToSectionName=None):
518  self._title = title
519  self._sampleName = sampleName
520  self._pages = collections.OrderedDict()
521  self._dqmSubFolderTranslatedToSectionName = dqmSubFolderTranslatedToSectionName
522 
523  self._prefix = ""
524  if sample.fastsim():
525  self._prefix += "fast_"
526  if fastVsFull:
527  self._prefix += "full_"
528 
529  self._prefix += _sampleFileName.get(sample.label(), sample.label())+"_"
530  if hasattr(sample, "hasScenario") and sample.hasScenario():
531  self._prefix += sample.scenario()+"_"
532 
533  if hasattr(sample, "hasPileup"):
534  if sample.hasPileup():
535  self._prefix += "pu"+str(sample.pileupNumber())+"_"+sample.pileupType()+"_"
536  else:
537  self._prefix += "nopu_"
538  if pileupComparison:
539  self._prefix += "vspu_"
540 
541 
542  def _getPage(self, key, pageClass):
543  if key not in self._pages:
544  page = pageClass(self._title, self._sampleName)
545  self._pages[key] = page
546  else:
547  page = self._pages[key]
548  return page
549 
550  def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles):
551  pageKey = plotterFolder.getPage()
552  if pageKey is None:
553  if dqmSubFolder is not None:
554  pageKey = dqmSubFolder.translated
555  else:
556  pageKey = plotterFolder.getName()
557 
558  page = self._getPage(pageKey, Page)
559  sectionName = plotterFolder.getSection()
560  if sectionName is None:
561  if plotterFolder.getPage() is not None and dqmSubFolder is not None:
562  if self._dqmSubFolderTranslatedToSectionName is not None:
563  sectionName = self._dqmSubFolderTranslatedToSectionName(dqmSubFolder.translated)
564  else:
565  sectionName = dqmSubFolder.translated
566  else:
567  sectionName = ""
568 
569  page.addPlotSet(sectionName, plotFiles)
570 
571  def addTable(self, table):
572  if table is None:
573  return
574 
575  page = self._getPage(table.getPage(), Page)
576  page.addTable(table.getSection(), table)
577 
578  def write(self, baseDir):
579  #print "TrackingPageSet.write"
580  ret = []
581 
582  keys = self._orderPages(self._pages.keys())
583  for key in keys:
584  page = self._pages[key]
585  if page.isEmpty():
586  continue
587 
588  fileName = "%s%s.html" % (self._prefix, key)
589  page.write(os.path.join(baseDir, fileName))
590  ret.append( (self._mapPagesName(key), fileName) )
591  return ret
592 
593  def _mapPagesName(self, name):
594  return _pageNameMap.get(name, name)
595 
596  def _orderPages(self, keys):
597  return keys
598 
599 
600 
602  def __init__(self, *args, **kwargs):
603  super(TrackingIterPage, self).__init__(*args, **kwargs)
604 
605  def _mapSectionName(self, quality):
606  return _trackQualityNameOrder.get(quality, quality)
607 
608  def _orderSets(self, qualities):
609  ret = []
610  for qual in _trackQualityNameOrder.keys():
611  if qual in qualities:
612  ret.append(qual)
613  qualities.remove(qual)
614  ret.extend(qualities)
615  return ret
616 
618  def __init__(self, *args, **kwargs):
619  super(TrackingPageSet, self).__init__(*args, **kwargs)
620 
621  def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles):
622  (algo, quality) = dqmSubFolder.translated
623 
624  pageName = algo
625  sectionName = quality
626 
627  # put all non-iterative stuff under OOTB
628  #
629  # it is bit of a hack to access trackingPlots.TrackingPlotFolder this way,
630  # but it was simple and it works
631  if algo != "ootb" and not plotterFolder._plotFolder.isAlgoIterative(algo):
632  pageName = "ootb"
633  sectionName = algo
634 
635  folderName = plotterFolder.getName()
636  if folderName != "":
637  sectionName = folderName+"_"+sectionName
638 
639  page = self._getPage(pageName, TrackingIterPage)
640  page.addPlotSet(sectionName, plotFiles)
641 
642  def _mapPagesName(self, algo): # algo = pageName
643  return _trackAlgoName.get(algo, algo)
644 
645  def _orderPages(self, algos):
646  ret = []
647  for algo in _trackAlgoOrder:
648  if algo in algos:
649  ret.append(algo)
650  algos.remove(algo)
651  ret.extend(algos)
652  return ret
653 
654 
655 
657  def __init__(self, sample, title, fastVsFull, pileupComparison):
658  self._sample = sample
659 
660  self._sampleName = ""
661  if sample.fastsim():
662  self._sampleName += "FastSim "
663  if fastVsFull:
664  self._sampleName += "vs FullSim "
665 
666  pileup = ""
667  if hasattr(sample, "hasPileup"):
668  pileup = "with no pileup"
669  if sample.hasPileup():
670  pileup = "with %d pileup (%s)" % (sample.pileupNumber(), sample.pileupType())
671  if pileupComparison is not None:
672  pileup += " "+pileupComparison
673  if hasattr(sample, "customPileupLabel"):
674  pileup = sample.customPileupLabel()
675 
676  scenario = ""
677  if hasattr(sample, "hasScenario") and sample.hasScenario():
678  scenario = " (\"%s\")" % sample.scenario()
679  self._sampleName += "%s sample%s %s" % (_sampleName.get(sample.name(), sample.name()), scenario, pileup)
680 
681  params = [title, self._sampleName, sample, fastVsFull, pileupComparison is not None]
682  self._summaryPage = PageSet(*params)
684  self._vertexPage = PageSet(*params)
685  self._miniaodPage = PageSet(*params)
686  self._timingPage = PageSet(*params)
687  self._pfPages = PageSet(*params)
688  self._hltPages = PageSet(*params, dqmSubFolderTranslatedToSectionName=lambda algoQuality: algoQuality[0])
689  self._pixelPages = PageSet(*params, dqmSubFolderTranslatedToSectionName=lambda algoQuality: algoQuality[0])
690  self._otherPages = PageSet(*params)
691 
698  PlotPurpose.PF: self._pfPages,
701  }
702 
703  def addPlots(self, plotterFolder, dqmSubFolder, plotFiles):
704  page = self._purposePageMap.get(plotterFolder.getPurpose(), self._otherPages)
705  page.addPlotSet(plotterFolder, dqmSubFolder, plotFiles)
706 
707  def addTable(self, table):
708  if table is None:
709  return
710 
711  page = self._purposePageMap.get(table.getPurpose(), self._otherPages)
712  page.addTable(table)
713  params = []
714 
715  def write(self, baseDir):
716  ret = [
717  " "+self._sampleName,
718  " <br/>",
719  " <ul>",
720  ]
721 
722  for pages in [self._summaryPage, self._iterationPages, self._pixelPages, self._vertexPage, self._miniaodPage, self._timingPage, self._hltPages, self._pfPages, self._otherPages]:
723  labelFiles = pages.write(baseDir)
724  for label, fname in labelFiles:
725  ret.append(' <li><a href="%s">%s</a></li>' % (fname, label))
726 
727  ret.extend([
728  ' </ul>',
729  ' <br/>',
730  ])
731 
732  return ret
733 
735  def __init__(self, validationName, newBaseDir):
736  self._title = "Tracking validation "+validationName
737  self._newBaseDir = newBaseDir
738 
739  self._index = [
740  '<html>',
741  ' <head>',
742  ' <title>%s</title>' % self._title,
743  ' </head>',
744  ' <body>',
745  ]
746 
747  self._sections = collections.OrderedDict()
748 
749  def addNote(self, note):
750  self._index.append(' <p>%s</p>'%note)
751 
752  def beginSample(self, sample, fastVsFull=False, pileupComparison=None):
753  # Fast vs. Full becomes just after the corresponding Fast
754  # Same for PU
755  rightAfterRefSample = fastVsFull or (pileupComparison is not None)
756 
757  key = (sample.digest(), rightAfterRefSample)
758  if key in self._sections:
759  self._currentSection = self._sections[key]
760  else:
761  self._currentSection = IndexSection(sample, self._title, fastVsFull, pileupComparison)
762  self._sections[key] = self._currentSection
763 
764  def addPlots(self, *args, **kwargs):
765  self._currentSection.addPlots(*args, **kwargs)
766 
767  def addTable(self, *args, **kwargs):
768  self._currentSection.addTable(*args, **kwargs)
769 
770  def write(self):
771  # Reorder sections such that Fast vs. Full becomes just after the corresponding Fast
772  keys = self._sections.iterkeys()
773  newkeys = []
774  for key in keys:
775  if not key[1]:
776  newkeys.append(key)
777  continue
778  # is fast vs full
779  ind_fast = newkeys.index( (key[0], False) )
780  newkeys.insert(ind_fast+1, key)
781 
782  for key in newkeys:
783  section = self._sections[key]
784  self._index.extend(section.write(self._newBaseDir))
785 
786  self._index.extend([
787  " </body>",
788  "</html>",
789  ])
790 
791  f = open(os.path.join(self._newBaseDir, "index.html"), "w")
792  for line in self._index:
793  f.write(line)
794  f.write("\n")
795  f.close()
796 
798  def __init__(self):
799  pass
800 
801  def beginSample(self, *args, **kwargs):
802  pass
803 
804  def addPlots(self, *args, **kwargs):
805  pass
806 
807  def addTable(self, *args, **kwargs):
808  pass
def _appendColumnHeader(self, header)
Definition: html.py:429
_purpose
Definition: html.py:264
def write(self, fileName)
Definition: html.py:340
_dqmSubFolderTranslatedToSectionName
Definition: html.py:521
def __init__(self, columnHeaders, rowHeaders, table, purpose, page, section)
Definition: html.py:250
def addTable(self, args, kwargs)
Definition: html.py:767
_legends
Definition: html.py:341
def write(self, baseDir)
Definition: html.py:715
def addTable(self, args, kwargs)
Definition: html.py:807
def _lowerFirst(s)
Definition: html.py:5
def addPlots(self, args, kwargs)
Definition: html.py:764
def _toAlgoMask(s)
Definition: html.py:58
_content
Definition: html.py:307
def __init__(self, args, kwargs)
Definition: html.py:602
def _formatLegend(self)
Definition: html.py:493
def isEmpty(self)
Definition: html.py:330
def _mapPagesName(self, name)
Definition: html.py:593
_rowHeaders
Definition: html.py:261
def __init__(self, sample, title, fastVsFull, pileupComparison)
Definition: html.py:657
def replace(string, replacements)
def __init__(self, title, sampleName)
Definition: html.py:306
def addNote(self, note)
Definition: html.py:749
def _mapPagesName(self, algo)
Definition: html.py:642
_columnHeaders
Definition: html.py:260
def _allToHP(s)
Definition: html.py:60
def _orderSets(self, qualities)
Definition: html.py:608
def _orderSets(self, keys)
Definition: html.py:506
def _toOriAlgo(s)
Definition: html.py:56
def getPage(self)
Definition: html.py:271
def __init__(self, title, sampleName, sample, fastVsFull, pileupComparison, dqmSubFolderTranslatedToSectionName=None)
Definition: html.py:517
def _mapSectionName(self, section)
Definition: html.py:503
def __init__(self, args, kwargs)
Definition: html.py:618
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:571
def addPlots(self, args, kwargs)
Definition: html.py:804
def __init__(self)
Definition: html.py:798
def _orderPages(self, algos)
Definition: html.py:645
def _appendLegend(self, section)
Definition: html.py:361
_columnHeaders
Definition: html.py:343
def columnHeaders(self)
Definition: html.py:283
def addPlotSet(self, section, plotSet)
Definition: html.py:321
def getSection(self)
Definition: html.py:274
def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:550
def addTable(self, table)
Definition: html.py:707
_plotSets
Definition: html.py:318
def _getPage(self, key, pageClass)
Definition: html.py:542
def _mapSectionName(self, quality)
Definition: html.py:605
def addPlotSet(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:621
def _formatTables(self)
Definition: html.py:439
def ncolumns(self)
Definition: html.py:277
_columnHeadersIndex
Definition: html.py:344
_section
Definition: html.py:266
def _formatPlotSets(self)
Definition: html.py:375
def rowHeaders(self)
Definition: html.py:286
_tables
Definition: html.py:319
def getPurpose(self)
Definition: html.py:268
def tableAsRowColumn(self)
Definition: html.py:292
def beginSample(self, sample, fastVsFull=False, pileupComparison=None)
Definition: html.py:752
def beginSample(self, args, kwargs)
Definition: html.py:801
#define str(s)
def __init__(self, validationName, newBaseDir)
Definition: html.py:735
def tableAsColumnRow(self)
Definition: html.py:289
def addPlots(self, plotterFolder, dqmSubFolder, plotFiles)
Definition: html.py:703
def write(self)
Definition: html.py:770
def _sectionNameLegend()
Definition: html.py:222
_sectionLegendIndex
Definition: html.py:342
def _ptCut(s)
Definition: html.py:64
def _orderPages(self, keys)
Definition: html.py:596
def nrows(self)
Definition: html.py:280
def _toHP(s)
Definition: html.py:54
def addTable(self, section, table)
Definition: html.py:327
def write(self, baseDir)
Definition: html.py:578