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

Constructor & Destructor Documentation

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

Definition at line 304 of file html.py.

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 
_content
Definition: html.py:305
def __init__(self, title, sampleName)
Definition: html.py:304
_plotSets
Definition: html.py:316
_tables
Definition: html.py:317

Member Function Documentation

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

Definition at line 421 of file html.py.

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

Referenced by html.Page._formatTables().

421  def _appendColumnHeader(self, header):
422  leg = ""
423  if header in self._columnHeadersIndex:
424  leg = self._columnHeadersIndex[header]
425  else:
426  leg = str(chr(ord('A')+len(self._columnHeaders)))
427  self._columnHeaders.append("%s: %s" % (leg, header))
428  self._columnHeadersIndex[header] = leg
429  return leg
430 
def _appendColumnHeader(self, header)
Definition: html.py:421
_columnHeaders
Definition: html.py:341
_columnHeadersIndex
Definition: html.py:342
#define str(s)
def html.Page._appendLegend (   self,
  section 
)
private

Definition at line 359 of file html.py.

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

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

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 
_legends
Definition: html.py:339
def _appendLegend(self, section)
Definition: html.py:359
def _sectionNameLegend()
Definition: html.py:221
_sectionLegendIndex
Definition: html.py:340
def html.Page._formatLegend (   self)
private

Definition at line 485 of file html.py.

References html.Page._legends.

485  def _formatLegend(self):
486  if len(self._legends) > 0:
487  self._content.extend([
488  ' <br/>'
489  ' Details:</br>',
490  ])
491  for leg in self._legends:
492  self._content.append(' %s<br/>' % leg)
493 
494 
_legends
Definition: html.py:339
def _formatLegend(self)
Definition: html.py:485
def html.Page._formatPlotSets (   self)
private

Definition at line 373 of file html.py.

References html.Page._appendLegend(), html.Page._mapSectionName(), html.Page._orderSets(), and html.Page._plotSets.

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 
def _orderSets(self, keys)
Definition: html.py:498
def _mapSectionName(self, section)
Definition: html.py:495
def _appendLegend(self, section)
Definition: html.py:359
_plotSets
Definition: html.py:316
def _formatPlotSets(self)
Definition: html.py:373
def html.Page._formatTables (   self)
private

Definition at line 431 of file html.py.

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

431  def _formatTables(self):
432  def _allNone(row):
433  for item in row:
434  if item is not None:
435  return False
436  return True
437 
438  sections = self._orderSets(self._tables.keys())
439  for isec, section in enumerate(sections):
440  leg = self._appendLegend(section)
441 
442  table = self._tables[section]
443  self._content.extend([
444  ' <br/>',
445  ' %s%s' % (self._mapSectionName(section), leg),
446  ' <table border="1">'
447  ])
448 
449  # table is stored in column-row, need to transpose
450  data = table.tableAsRowColumn()
451 
452  self._content.extend([
453  ' <tr>'
454  ' <td></td>'
455  ])
456  heads = table.columnHeaders()
457  if max(map(lambda h: len(h), heads)) > 20:
458  heads = [self._appendColumnHeader(h) for h in heads]
459  for head in heads:
460  self._content.append(' <td>%s</td>' % head)
461  self._content.append(' </tr>')
462 
463  for irow, row in enumerate(data):
464  # Skip row if all values are non-existent
465  if _allNone(row):
466  continue
467 
468  self._content.extend([
469  ' <tr>'
470  ' <td>%s</td>' % table.rowHeaders()[irow]
471  ])
472  # align the number columns to right
473  for icol, item in enumerate(row):
474  formatted = str(item) if item is not None else ""
475  self._content.append(' <td align="right">%s</td>' % formatted)
476  self._content.append(' </tr>')
477 
478  self._content.append(' </table>')
479 
480  for shortenedColumnHeader in self._columnHeaders:
481  self._content.append(' %s<br/>' % shortenedColumnHeader)
482  self._columnHeaders = []
483  self._columnHeadersIndex = {}
484 
def _appendColumnHeader(self, header)
Definition: html.py:421
def _orderSets(self, keys)
Definition: html.py:498
def _mapSectionName(self, section)
Definition: html.py:495
def _appendLegend(self, section)
Definition: html.py:359
_columnHeaders
Definition: html.py:341
def _formatTables(self)
Definition: html.py:431
_columnHeadersIndex
Definition: html.py:342
_tables
Definition: html.py:317
#define str(s)
def html.Page._mapSectionName (   self,
  section 
)
private

Definition at line 495 of file html.py.

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

495  def _mapSectionName(self, section):
496  return _sectionNameMapOrder.get(section, section)
497 
def _mapSectionName(self, section)
Definition: html.py:495
def html.Page._orderSets (   self,
  keys 
)
private

Definition at line 498 of file html.py.

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

498  def _orderSets(self, keys):
499  keys_sorted = sorted(keys)
500  ret = []
501  for section in _sectionNameMapOrder.keys():
502  if section in keys_sorted:
503  ret.append(section)
504  keys_sorted.remove(section)
505  ret.extend(keys_sorted)
506  return ret
507 
def _orderSets(self, keys)
Definition: html.py:498
def html.Page.addPlotSet (   self,
  section,
  plotSet 
)

Definition at line 319 of file html.py.

References html.Page._plotSets.

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 
def addPlotSet(self, section, plotSet)
Definition: html.py:319
_plotSets
Definition: html.py:316
def html.Page.addTable (   self,
  section,
  table 
)

Definition at line 325 of file html.py.

References html.Page._tables.

325  def addTable(self, section, table):
326  self._tables[section] = table
327 
_tables
Definition: html.py:317
def addTable(self, section, table)
Definition: html.py:325
def html.Page.isEmpty (   self)

Definition at line 328 of file html.py.

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

Referenced by plotting.Plot.clone().

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 
def isEmpty(self)
Definition: html.py:328
_plotSets
Definition: html.py:316
_tables
Definition: html.py:317
def html.Page.write (   self,
  fileName 
)

Definition at line 338 of file html.py.

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 
def write(self, fileName)
Definition: html.py:338
_legends
Definition: html.py:339
_content
Definition: html.py:305
def _formatLegend(self)
Definition: html.py:485
_columnHeaders
Definition: html.py:341
def _formatTables(self)
Definition: html.py:431
_columnHeadersIndex
Definition: html.py:342
def _formatPlotSets(self)
Definition: html.py:373
_sectionLegendIndex
Definition: html.py:340

Member Data Documentation

html.Page._columnHeaders
private

Definition at line 341 of file html.py.

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

html.Page._columnHeadersIndex
private

Definition at line 342 of file html.py.

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

html.Page._content
private

Definition at line 305 of file html.py.

html.Page._legends
private

Definition at line 339 of file html.py.

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

html.Page._plotSets
private

Definition at line 316 of file html.py.

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

html.Page._sectionLegendIndex
private

Definition at line 340 of file html.py.

Referenced by html.Page._appendLegend().

html.Page._tables
private

Definition at line 317 of file html.py.

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