CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
html.Page Class Reference
Inheritance diagram for html.Page:
html.TrackingIterPage

Public Member Functions

def __init__ (self, title, sampleName)
 
def addPlotSet (self, section, plotSet)
 
def addTable (self, section, table)
 
def isEmpty (self)
 
def write (self, fileName)
 

Private Member Functions

def _appendColumnHeader (self, header)
 
def _appendLegend (self, section)
 
def _formatLegend (self)
 
def _formatPlotSets (self)
 
def _formatTables (self)
 
def _mapSectionName (self, section)
 
def _orderSets (self, keys)
 

Private Attributes

 _columnHeaders
 
 _columnHeadersIndex
 
 _content
 
 _legends
 
 _plotSets
 
 _sectionLegendIndex
 
 _tables
 

Detailed Description

Definition at line 310 of file html.py.

Constructor & Destructor Documentation

◆ __init__()

def html.Page.__init__ (   self,
  title,
  sampleName 
)

Definition at line 311 of file html.py.

311  def __init__(self, title, sampleName):
312  self._content = [
313  '<html>',
314  ' <head>',
315  ' <title>%s</title>' % title,
316  ' </head>',
317  ' <body>',
318  ' '+sampleName,
319  ' <br/>',
320  ' <br/>',
321  ]
322 
323  self._plotSets = {}
324  self._tables = {}
325 

Member Function Documentation

◆ _appendColumnHeader()

def html.Page._appendColumnHeader (   self,
  header 
)
private

Definition at line 434 of file html.py.

434  def _appendColumnHeader(self, header):
435  leg = ""
436  if header in self._columnHeadersIndex:
437  leg = self._columnHeadersIndex[header]
438  else:
439  leg = str(chr(ord('A')+len(self._columnHeaders)))
440  self._columnHeaders.append("%s: %s" % (leg, header))
441  self._columnHeadersIndex[header] = leg
442  return leg
443 

References html.Table._columnHeaders, html.Page._columnHeaders, html.Page._columnHeadersIndex, mps_setup.append, and str.

Referenced by html.Page._formatTables().

◆ _appendLegend()

def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 366 of file html.py.

366  def _appendLegend(self, section):
367  leg = ""
368  legends = _sectionNameLegend()
369  if section in legends:
370  if section in self._sectionLegendIndex:
371  leg = self._sectionLegendIndex[section]
372  else:
373  legnum = len(self._legends)+1
374  leg = "<sup>%d</sup>" % legnum
375  leg2 = "<sup>%d)</sup>" % legnum
376  self._legends.append("%s %s" % (leg2, legends[section]))
377  self._sectionLegendIndex[section] = leg
378  return leg
379 

References html.Page._legends, html.Page._sectionLegendIndex, html._sectionNameLegend(), and mps_setup.append.

Referenced by html.Page._formatPlotSets(), and html.Page._formatTables().

◆ _formatLegend()

def html.Page._formatLegend (   self)
private

Definition at line 498 of file html.py.

498  def _formatLegend(self):
499  if len(self._legends) > 0:
500  self._content.extend([
501  ' <br/>'
502  ' Details:</br>',
503  ])
504  for leg in self._legends:
505  self._content.append(' %s<br/>' % leg)
506 
507 

References html.Page._content, html.Page._legends, and mps_setup.append.

◆ _formatPlotSets()

def html.Page._formatPlotSets (   self)
private

Definition at line 380 of file html.py.

380  def _formatPlotSets(self):
381  self._content.extend([
382  ' <table>'
383  ' <tr>',
384  ])
385 
386  fileTable = []
387 
388  sections = self._orderSets(self._plotSets.keys())
389  for isec, section in enumerate(sections):
390  leg = self._appendLegend(section)
391 
392  self._content.extend([
393  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
394  ])
395  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
396  for row in fileTable:
397  found = False
398  for i, (bsf, f) in enumerate(files):
399  if bsf == row[0]:
400  row.append(f)
401  found = True
402  del files[i]
403  break
404  if not found:
405  row.append(None)
406  for bsf, f in files:
407  fileTable.append( [bsf] + [None]*isec + [f] )
408 
409  self._content.extend([
410  ' </tr>',
411  ])
412 
413  for row in fileTable:
414  self._content.append(' <tr>')
415  bs = row[0]
416  for elem in row[1:]:
417  if elem is not None:
418  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
419  else:
420  self._content.append(' <td></td>')
421  self._content.append(' </tr>')
422 
423 
424  self._content.extend([
425  ' </table>',
426  ])
427 
428  if len(fileTable):
429  first_row = fileTable[0]
430  self._content.extend([
431  ' <a href="%s">Browse Folder</a>' % (first_row[1][0:first_row[1].rfind('/')])
432  ])
433 

References html.Page._appendLegend(), html.Page._content, html.Page._mapSectionName(), html.Page._orderSets(), html.Page._plotSets, mps_setup.append, and relativeConstraints.keys.

◆ _formatTables()

def html.Page._formatTables (   self)
private

Definition at line 444 of file html.py.

444  def _formatTables(self):
445  def _allNone(row):
446  for item in row:
447  if item is not None:
448  return False
449  return True
450 
451  sections = self._orderSets(self._tables.keys())
452  for isec, section in enumerate(sections):
453  leg = self._appendLegend(section)
454 
455  table = self._tables[section]
456  self._content.extend([
457  ' <br/>',
458  ' %s%s' % (self._mapSectionName(section), leg),
459  ' <table border="1">'
460  ])
461 
462  # table is stored in column-row, need to transpose
463  data = table.tableAsRowColumn()
464 
465  self._content.extend([
466  ' <tr>'
467  ' <td></td>'
468  ])
469  heads = table.columnHeaders()
470  if max(map(lambda h: len(h), heads)) > 20:
471  heads = [self._appendColumnHeader(h) for h in heads]
472  for head in heads:
473  self._content.append(' <td>%s</td>' % head)
474  self._content.append(' </tr>')
475 
476  for irow, row in enumerate(data):
477  # Skip row if all values are non-existent
478  if _allNone(row):
479  continue
480 
481  self._content.extend([
482  ' <tr>'
483  ' <td>%s</td>' % table.rowHeaders()[irow]
484  ])
485  # align the number columns to right
486  for icol, item in enumerate(row):
487  formatted = str(item) if item is not None else ""
488  self._content.append(' <td align="right">%s</td>' % formatted)
489  self._content.append(' </tr>')
490 
491  self._content.append(' </table>')
492 
493  for shortenedColumnHeader in self._columnHeaders:
494  self._content.append(' %s<br/>' % shortenedColumnHeader)
495  self._columnHeaders = []
496  self._columnHeadersIndex = {}
497 

References html.Page._appendColumnHeader(), html.Page._appendLegend(), html.Table._columnHeaders, html.Page._columnHeaders, html.Page._columnHeadersIndex, html.Page._content, html.Page._mapSectionName(), html.Page._orderSets(), html.Page._tables, mps_setup.append, relativeConstraints.keys, genParticles_cff.map, SiStripPI.max, and str.

◆ _mapSectionName()

def html.Page._mapSectionName (   self,
  section 
)
private

Reimplemented in html.TrackingIterPage.

Definition at line 508 of file html.py.

508  def _mapSectionName(self, section):
509  return _sectionNameMapOrder.get(section, section)
510 

Referenced by html.Page._formatPlotSets(), and html.Page._formatTables().

◆ _orderSets()

def html.Page._orderSets (   self,
  keys 
)
private

Reimplemented in html.TrackingIterPage.

Definition at line 511 of file html.py.

511  def _orderSets(self, keys):
512  keys_sorted = sorted(keys)
513  ret = []
514  for section in _sectionNameMapOrder.keys():
515  if section in keys_sorted:
516  ret.append(section)
517  keys_sorted.remove(section)
518  ret.extend(keys_sorted)
519  return ret
520 

Referenced by html.Page._formatPlotSets(), and html.Page._formatTables().

◆ addPlotSet()

def html.Page.addPlotSet (   self,
  section,
  plotSet 
)

Definition at line 326 of file html.py.

326  def addPlotSet(self, section, plotSet):
327  if section in self._plotSets:
328  self._plotSets[section].extend(plotSet)
329  else:
330  self._plotSets[section] = plotSet
331 

References html.Page._plotSets.

◆ addTable()

def html.Page.addTable (   self,
  section,
  table 
)

Definition at line 332 of file html.py.

332  def addTable(self, section, table):
333  self._tables[section] = table
334 

References html.Page._tables.

◆ isEmpty()

def html.Page.isEmpty (   self)

Definition at line 335 of file html.py.

335  def isEmpty(self):
336  for plotSet in six.itervalues(self._plotSets):
337  if len(plotSet) > 0:
338  return False
339 
340  if len(self._tables) > 0:
341  return False
342 
343  return True
344 

References html.Page._plotSets, and html.Page._tables.

Referenced by plotting.Plot.clone().

◆ write()

def html.Page.write (   self,
  fileName 
)

Definition at line 345 of file html.py.

345  def write(self, fileName):
346  self._legends = []
347  self._sectionLegendIndex = {}
348  self._columnHeaders = []
349  self._columnHeadersIndex = {}
350  self._formatPlotSets()
351  self._formatTables()
352  self._formatLegend()
353 
354  self._content.extend([
355  ' </body>',
356  '</html>',
357  ])
358 
359  #print "Writing HTML report page", fileName
360  f = open(fileName, "w")
361  for line in self._content:
362  f.write(line)
363  f.write("\n")
364  f.close()
365 

Member Data Documentation

◆ _columnHeaders

html.Page._columnHeaders
private

Definition at line 348 of file html.py.

Referenced by html.Page._appendColumnHeader(), and html.Page._formatTables().

◆ _columnHeadersIndex

html.Page._columnHeadersIndex
private

Definition at line 349 of file html.py.

Referenced by html.Page._appendColumnHeader(), and html.Page._formatTables().

◆ _content

html.Page._content
private

◆ _legends

html.Page._legends
private

Definition at line 346 of file html.py.

Referenced by html.Page._appendLegend(), and html.Page._formatLegend().

◆ _plotSets

html.Page._plotSets
private

Definition at line 323 of file html.py.

Referenced by html.Page._formatPlotSets(), html.Page.addPlotSet(), and html.Page.isEmpty().

◆ _sectionLegendIndex

html.Page._sectionLegendIndex
private

Definition at line 347 of file html.py.

Referenced by html.Page._appendLegend().

◆ _tables

html.Page._tables
private

Definition at line 324 of file html.py.

Referenced by html.Page._formatTables(), html.Page.addTable(), and html.Page.isEmpty().

html._sectionNameLegend
def _sectionNameLegend()
Definition: html.py:227
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
str
#define str(s)
Definition: TestProcessor.cc:51
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
mps_setup.append
append
Definition: mps_setup.py:85
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48
genParticles_cff.map
map
Definition: genParticles_cff.py:11