CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
tablePrinter Namespace Reference

Functions

def indent
 

Variables

string data
 
int headerwidth = 46
 
tuple labels = ('First Name','Last Name','Age','Position')
 
list lumidata
 
list lumifooter = [('%-*s'%(24,'189'),'%-*s'%(10,'17.89'),'%-*s'%(10,'16.1'),'%-*s'%(20,'3.47'))]
 
list lumiheader = [('%-*s'%(30,'Lumi Sections'),'%-*s'%(46,'Luminosity'))]
 
list rows = [row.strip().split(',') for row in data.splitlines()]
 
int width = 10
 

Function Documentation

def tablePrinter.indent (   rows,
  hasHeader = False,
  headerChar = '-',
  delim = ' | ',
  justify = 'center',
  separateRows = False,
  prefix = '',
  postfix = '',
  wrapfunc = lambda x:x 
)
Indents a table by column.
- rows: A sequence of sequences of items, one sequence per row.
- hadHeader: True if the first row consists of the column's names.
- headerChar: Character to be used for the row separator line
(if hasHeader==True or separateRows==True).
- delim: The column delimiter.
- justify: Determines how are data justified in their column.
Valid values are 'left','right','center'.
- separateRows: True if rows are to be separated by a line of 'headerChar's.
- prefix: A string prepended to each printed row.
- postfix: A string appended to each printed row.
- wrapfunc: A function f(text) for wrapping text; each element in the table is first wrapped by this function.

Definition at line 8 of file tablePrinter.py.

References python.multivaluedict.map(), max(), and split.

8 
9  separateRows=False,prefix='',postfix='',wrapfunc=lambda x:x):
10  """
11  Indents a table by column.
12  - rows: A sequence of sequences of items, one sequence per row.
13  - hadHeader: True if the first row consists of the column's names.
14  - headerChar: Character to be used for the row separator line
15  (if hasHeader==True or separateRows==True).
16  - delim: The column delimiter.
17  - justify: Determines how are data justified in their column.
18  Valid values are 'left','right','center'.
19  - separateRows: True if rows are to be separated by a line of 'headerChar's.
20  - prefix: A string prepended to each printed row.
21  - postfix: A string appended to each printed row.
22  - wrapfunc: A function f(text) for wrapping text; each element in the table is first wrapped by this function.
23  """
24  #nested function
25  #closure for breaking logical rows to physical, using wrapfunc
26  def rowWrapper(row):
27  newRows=[wrapfunc(item).split('\n') for item in row]
28  #print 'newRows: ',newRows
29  #print 'map result: ',map(None,*newRows)
30  #print 'rowwrapped: ',[[substr or '' for substr in item] for item in map(None,*newRows)]
31  return [[substr or '' for substr in item] for item in map(None,*newRows)]
32  # break each logical row into one or more physical ones
33  logicalRows = [rowWrapper(row) for row in rows]
34  # columns of physical rows
35  columns = map(None,*reduce(operator.add,logicalRows))
36  # get the maximum of each column by the string length of its items
37  maxWidths = [max([len(str(item)) for item in column]) for column in columns]
38  rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) + len(delim)*(len(maxWidths)-1))
39  # select the appropriate justify method
40  justify = {'center':str.center,'right':str.rjust,'left':str.ljust}[justify.lower()]
41  output=cStringIO.StringIO()
42  if separateRows: print >> output,rowSeparator
43  for physicalRows in logicalRows:
44  for row in physicalRows:
45  print >> output, prefix+delim.join([justify(str(item),width) for (item,width) in zip(row,maxWidths)])+postfix
46  if separateRows or hasHeader: print >> output, rowSeparator; hasHeader=False
47  return output.getvalue()
const T & max(const T &a, const T &b)
double split
Definition: MVATrainer.cc:139

Variable Documentation

string tablePrinter.data
Initial value:
1 = """John,Smith,24,Software Engineer
2  Mary,Brohowski,23,Sales Manager
3  Aristidis,Papageorgopoulos,28,Senior Reseacher"""

Definition at line 51 of file tablePrinter.py.

int tablePrinter.headerwidth = 46

Definition at line 71 of file tablePrinter.py.

tuple tablePrinter.labels = ('First Name','Last Name','Age','Position')

Definition at line 50 of file tablePrinter.py.

Referenced by BTagPerformanceAnalyzerOnData.analyze(), BTagPerformanceAnalyzerMC.analyze(), HLTPrescaleRecorder.beginRun(), HLTMuonOfflineAnalyzer.beginRun(), HLTMuonValidator.beginRun(), DigiInvestigatorHistogramMaker.book(), DigiPileupCorrHistogramMaker.book(), DigiVtxPosCorrHistogramMaker.book(), DigiVertexCorrHistogramMaker.book(), DigiLumiCorrHistogramMaker.book(), DigiBXCorrHistogramMaker< T >.book(), cscdqm::Collection.book(), CollectionCombiner< Collection >.CollectionCombiner(), pat::TauJetCorrFactors.correctionLabels(), pat::JetCorrFactors.correctionLabels(), pat::TauJetCorrFactors.correctionLabelString(), pat::JetCorrFactors.correctionLabelString(), HLTConfigData.dump(), HLTPrescaleRecorder.endRun(), TauDQMHistPlotter.endRun(), GenericTriggerEventFlag.expressionsFromDB(), HLTConfigData.extract(), EcalMIPRecHitFilter.filter(), HCalSD.HCalSD(), edm::EDConsumerBase.labelsForToken(), rpcdqm::utils.labelYAxisRing(), hitfit.make_constraint_intermed(), edm::PrincipalGetAdapter.makeFailToGetException(), PlotCombiner.makePlot(), MultiplicityTimeCorrelations.MultiplicityTimeCorrelations(), PlotPixelMultVtxPos(), FastTimerService.preStreamBeginRun(), ReducedESRecHitCollectionProducer.produce(), CollectionCombiner< Collection >.produce(), ReducedRecHitCollectionProducer.produce(), TrackClusterRemover.produce(), SeedClusterRemover.produce(), DTLocalTriggerTask.setQLabels(), DTLocalTriggerBaseTask.setQLabels(), MVAJetTagPlotter.tagInfoRequirements(), TauDQMHistPlotter.TauDQMHistPlotter(), edm::PrincipalGetAdapter.throwAmbiguousException(), and edm::EDConsumerBase.updateLookup().

list tablePrinter.lumidata
Initial value:
1 = [\
2  ('%-*s'%(8,'run'),'%-*s'%(8,'first'),'%-*s'%(8,'last'),'%-*s'%(10,'delivered'),'%-*s'%(10,'recorded'),'%-*s'%(20,'recorded\nmypathdfdafddafd')),\
3  ['%d'%(132440),'%d'%(23),'%d'%(99),'%.2f'%(2.345),'%.2f'%(1.23),'%.2f'%(0.5678)],\
4  ['%d'%(132442),'%d'%(1),'%d'%(20),'%.2f'%(2.345),'%.2f'%(1.23),'%.2f'%(0.5678)],\
5  ['','%d'%(27),'%d'%(43),'%.2f'%(2.345),'%.2f'%(1.23),'%.2f'%(0.5678)]\
6  ]

Definition at line 64 of file tablePrinter.py.

list tablePrinter.lumifooter = [('%-*s'%(24,'189'),'%-*s'%(10,'17.89'),'%-*s'%(10,'16.1'),'%-*s'%(20,'3.47'))]

Definition at line 73 of file tablePrinter.py.

list tablePrinter.lumiheader = [('%-*s'%(30,'Lumi Sections'),'%-*s'%(46,'Luminosity'))]

Definition at line 70 of file tablePrinter.py.

Referenced by lumi::Lumi2DB.retrieveData().

list tablePrinter.rows = [row.strip().split(',') for row in data.splitlines()]

Definition at line 54 of file tablePrinter.py.

Referenced by SiPixelRecHitsValid.fillBarrel(), SiPixelRecHitsValid.fillForward(), SiPixelActionExecutor.fillSummary(), pos::PixelCalibConfiguration.PixelCalibConfiguration(), MuonResidualsFitter.read(), SiPixelCalibConfiguration.SiPixelCalibConfiguration(), and MuonResidualsFitter.write().

int tablePrinter.width = 10

Definition at line 59 of file tablePrinter.py.