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 351 of file html.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 352 of file html.py.

352  def __init__(self, title, sampleName):
353  self._content = [
354  '<html>',
355  ' <head>',
356  ' <title>%s</title>' % title,
357  ' </head>',
358  ' <body>',
359  ' '+sampleName,
360  ' <br/>',
361  ' <br/>',
362  ]
363 
364  self._plotSets = {}
365  self._tables = {}
366 

Member Function Documentation

◆ _appendColumnHeader()

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

Definition at line 475 of file html.py.

475  def _appendColumnHeader(self, header):
476  leg = ""
477  if header in self._columnHeadersIndex:
478  leg = self._columnHeadersIndex[header]
479  else:
480  leg = str(chr(ord('A')+len(self._columnHeaders)))
481  self._columnHeaders.append("%s: %s" % (leg, header))
482  self._columnHeadersIndex[header] = leg
483  return leg
484 

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 407 of file html.py.

407  def _appendLegend(self, section):
408  leg = ""
409  legends = _sectionNameLegend()
410  if section in legends:
411  if section in self._sectionLegendIndex:
412  leg = self._sectionLegendIndex[section]
413  else:
414  legnum = len(self._legends)+1
415  leg = "<sup>%d</sup>" % legnum
416  leg2 = "<sup>%d)</sup>" % legnum
417  self._legends.append("%s %s" % (leg2, legends[section]))
418  self._sectionLegendIndex[section] = leg
419  return leg
420 

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 539 of file html.py.

539  def _formatLegend(self):
540  if len(self._legends) > 0:
541  self._content.extend([
542  ' <br/>'
543  ' Details:</br>',
544  ])
545  for leg in self._legends:
546  self._content.append(' %s<br/>' % leg)
547 
548 

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

◆ _formatPlotSets()

def html.Page._formatPlotSets (   self)
private

Definition at line 421 of file html.py.

421  def _formatPlotSets(self):
422  self._content.extend([
423  ' <table>'
424  ' <tr>',
425  ])
426 
427  fileTable = []
428 
429  sections = self._orderSets(self._plotSets.keys())
430  for isec, section in enumerate(sections):
431  leg = self._appendLegend(section)
432 
433  self._content.extend([
434  ' <td>%s%s</td>' % (self._mapSectionName(section), leg),
435  ])
436  files = [(os.path.basename(f), f) for f in self._plotSets[section]]
437  for row in fileTable:
438  found = False
439  for i, (bsf, f) in enumerate(files):
440  if bsf == row[0]:
441  row.append(f)
442  found = True
443  del files[i]
444  break
445  if not found:
446  row.append(None)
447  for bsf, f in files:
448  fileTable.append( [bsf] + [None]*isec + [f] )
449 
450  self._content.extend([
451  ' </tr>',
452  ])
453 
454  for row in fileTable:
455  self._content.append(' <tr>')
456  bs = row[0]
457  for elem in row[1:]:
458  if elem is not None:
459  self._content.append(' <td><a href="%s">%s</a></td>' % (elem, bs))
460  else:
461  self._content.append(' <td></td>')
462  self._content.append(' </tr>')
463 
464 
465  self._content.extend([
466  ' </table>',
467  ])
468 
469  if len(fileTable):
470  first_row = fileTable[0]
471  self._content.extend([
472  ' <a href="%s">Browse Folder</a>' % (first_row[1][0:first_row[1].rfind('/')])
473  ])
474 

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 485 of file html.py.

485  def _formatTables(self):
486  def _allNone(row):
487  for item in row:
488  if item is not None:
489  return False
490  return True
491 
492  sections = self._orderSets(self._tables.keys())
493  for isec, section in enumerate(sections):
494  leg = self._appendLegend(section)
495 
496  table = self._tables[section]
497  self._content.extend([
498  ' <br/>',
499  ' %s%s' % (self._mapSectionName(section), leg),
500  ' <table border="1">'
501  ])
502 
503  # table is stored in column-row, need to transpose
504  data = table.tableAsRowColumn()
505 
506  self._content.extend([
507  ' <tr>'
508  ' <td></td>'
509  ])
510  heads = table.columnHeaders()
511  if max(map(lambda h: len(h), heads)) > 20:
512  heads = [self._appendColumnHeader(h) for h in heads]
513  for head in heads:
514  self._content.append(' <td>%s</td>' % head)
515  self._content.append(' </tr>')
516 
517  for irow, row in enumerate(data):
518  # Skip row if all values are non-existent
519  if _allNone(row):
520  continue
521 
522  self._content.extend([
523  ' <tr>'
524  ' <td>%s</td>' % table.rowHeaders()[irow]
525  ])
526  # align the number columns to right
527  for icol, item in enumerate(row):
528  formatted = str(item) if item is not None else ""
529  self._content.append(' <td align="right">%s</td>' % formatted)
530  self._content.append(' </tr>')
531 
532  self._content.append(' </table>')
533 
534  for shortenedColumnHeader in self._columnHeaders:
535  self._content.append(' %s<br/>' % shortenedColumnHeader)
536  self._columnHeaders = []
537  self._columnHeadersIndex = {}
538 

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 549 of file html.py.

549  def _mapSectionName(self, section):
550  return _sectionNameMapOrder.get(section, section)
551 

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

◆ _orderSets()

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

Reimplemented in html.TrackingIterPage.

Definition at line 552 of file html.py.

552  def _orderSets(self, keys):
553  keys_sorted = sorted(keys)
554  ret = []
555  for section in _sectionNameMapOrder.keys():
556  if section in keys_sorted:
557  ret.append(section)
558  keys_sorted.remove(section)
559  ret.extend(keys_sorted)
560  return ret
561 

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

◆ addPlotSet()

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

Definition at line 367 of file html.py.

367  def addPlotSet(self, section, plotSet):
368  if section in self._plotSets:
369  self._plotSets[section].extend(plotSet)
370  else:
371  self._plotSets[section] = plotSet
372 

References html.Page._plotSets.

◆ addTable()

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

Definition at line 373 of file html.py.

373  def addTable(self, section, table):
374  self._tables[section] = table
375 

References html.Page._tables.

◆ isEmpty()

def html.Page.isEmpty (   self)

Definition at line 376 of file html.py.

376  def isEmpty(self):
377  for plotSet in six.itervalues(self._plotSets):
378  if len(plotSet) > 0:
379  return False
380 
381  if len(self._tables) > 0:
382  return False
383 
384  return True
385 

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

Referenced by plotting.Plot.clone().

◆ write()

def html.Page.write (   self,
  fileName 
)

Definition at line 386 of file html.py.

386  def write(self, fileName):
387  self._legends = []
388  self._sectionLegendIndex = {}
389  self._columnHeaders = []
390  self._columnHeadersIndex = {}
391  self._formatPlotSets()
392  self._formatTables()
393  self._formatLegend()
394 
395  self._content.extend([
396  ' </body>',
397  '</html>',
398  ])
399 
400  #print "Writing HTML report page", fileName
401  f = open(fileName, "w")
402  for line in self._content:
403  f.write(line)
404  f.write("\n")
405  f.close()
406 

Member Data Documentation

◆ _columnHeaders

html.Page._columnHeaders
private

Definition at line 389 of file html.py.

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

◆ _columnHeadersIndex

html.Page._columnHeadersIndex
private

Definition at line 390 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 387 of file html.py.

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

◆ _plotSets

html.Page._plotSets
private

Definition at line 364 of file html.py.

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

◆ _sectionLegendIndex

html.Page._sectionLegendIndex
private

Definition at line 388 of file html.py.

Referenced by html.Page._appendLegend().

◆ _tables

html.Page._tables
private

Definition at line 365 of file html.py.

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

html._sectionNameLegend
def _sectionNameLegend()
Definition: html.py:262
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
str
#define str(s)
Definition: TestProcessor.cc:52
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