CMS 3D CMS Logo

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

Functions

def help
 
def importDF
 
def indent
 
def search
 
def wrap_always
 
def wrap_onspace
 
def wrap_onspace_strict
 

Variables

list imported_modules = []
 

Function Documentation

def dataformats.help ( )

Definition at line 125 of file dataformats.py.

References importDF(), and search().

126 def help():
127  print "usage: dataformats pattern_to_search"
128  print "example: dataformats muon"
129  print "Note! multiple patterns separated by space are not supported"
def dataformats.importDF (   path)

Definition at line 84 of file dataformats.py.

References split.

Referenced by help().

84 
85 def importDF(path):
86 
87  modules_to_import = "RecoTracker RecoLocalTracker RecoLocalCalo RecoEcal RecoEgamma RecoLocalMuon RecoMuon RecoJets RecoMET RecoBTag RecoTauTag RecoVertex RecoPixelVertexing HLTrigger RecoParticleFlow".split()
88  modules_to_import = "RecoLocalTracker RecoLocalMuon RecoLocalCalo RecoEcal TrackingTools RecoTracker RecoJets RecoMET RecoMuon RecoBTau RecoBTag RecoTauTag RecoVertex RecoPixelVertexing RecoEgamma RecoParticleFlow L1Trigger".split()
89 
90 
91  for m in modules_to_import:
92  m = m + "_dataformats"
93  try:
94  sys.path.append(path+"/src/Documentation/DataFormats/python/")
95  globals()[m] = __import__(m)
96  imported_modules.append(m)
97  print m
98  except ImportError:
99  print "skipping", m
100 
101 # END of import
double split
Definition: MVATrainer.cc:139
def dataformats.indent (   rows,
  hasHeader = False,
  headerChar = '-',
  delim = ' | ',
  justify = 'left',
  separateRows = False,
  prefix = '',
  postfix = '',
  wrapfunc = lambda x:x 
)
Indents a table by column.
   - rows: A sequence of sequences of items, one sequence per row.
   - hasHeader: True if the first row consists of the columns' 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' and '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 5 of file dataformats.py.

References Association.map, max(), and split.

Referenced by CalibrationXML.addChild(), FWPSetTableManager.cellRenderer(), node_filter(), operator<<(), search(), and edm::ParameterDescription< std::vector< ParameterSet > >.writeOneElementToCfi().

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

Definition at line 102 of file dataformats.py.

References indent(), join(), split, and wrap_always().

Referenced by dqm_interfaces.DirID.__eq__(), ValidationMatrix.add_to_blacklist(), ValidationMatrix.do_comparisons_threaded(), AlignmentMonitorTemplate.event(), FileNamesHelper.getJobID_fromFileName(), ValidationMatrix.guess_blacklists(), ValidationMatrix.guess_params(), help(), and duplicateReflexLibrarySearch.searchClassDefXml().

103 def search(query):
104  labels = ('Where(Package)', 'Instance', 'Container', 'Description')
105  width = 20
106 
107  data = ""
108  for module in imported_modules:
109  for dict_name in ["full", "reco", "aod"]: # going through all dictionaries
110  #print module
111  dict = vars(globals()[module])[dict_name]
112 
113  for key in sorted(dict.keys()): # going though all elements in dictionary
114  # TODO: IMPROVE
115  element = dict[key]
116  if query.lower() in element.__str__().lower(): # searching for query
117  if not (("No documentation".lower()) in element.__str__().lower()):
118  data+= module.replace("_dataformats", "")+" ("+ dict_name.replace("full", "FEVT") + ")||" + "||".join(element)+"\n"
119 
120  if (data != ""):
121  rows = [row.strip().split('||') for row in data.splitlines()]
122  print indent([labels]+rows, hasHeader=True, separateRows=True, prefix='| ', postfix=' |', wrapfunc=lambda x: wrap_always(x,width))
123  else:
124  print "No documentation found"
def wrap_always
Definition: dataformats.py:70
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139
def dataformats.wrap_always (   text,
  width 
)
A simple word-wrap function that wraps text on exactly width characters.
   It doesn't split the text in words.

Definition at line 70 of file dataformats.py.

References join().

Referenced by search(), and wrap_onspace_strict().

70 
71 def wrap_always(text, width):
72  """A simple word-wrap function that wraps text on exactly width characters.
73  It doesn't split the text in words."""
74  return '\n'.join([ text[width*i:width*(i+1)] \
75  for i in xrange(int(math.ceil(1.*len(text)/width))) ])
76 
77 
78 
79 # END OF TABLE FORMATING
80 
# START of import
def wrap_always
Definition: dataformats.py:70
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def dataformats.wrap_onspace (   text,
  width 
)
A word-wrap function that preserves existing line breaks
and most spaces in the text. Expects that existing line
breaks are posix newlines (\n).

Definition at line 47 of file dataformats.py.

Referenced by lumiReport.toScreenConfHlt(), lumiReport.toScreenLSBeam(), and wrap_onspace_strict().

47 
48 def wrap_onspace(text, width):
49  """
50  A word-wrap function that preserves existing line breaks
51  and most spaces in the text. Expects that existing line
52  breaks are posix newlines (\n).
53  """
54  return reduce(lambda line, word, width=width: '%s%s%s' %
55  (line,
56  ' \n'[(len(line[line.rfind('\n')+1:])
57  + len(word.split('\n',1)[0]
58  ) >= width)],
59  word),
60  text.split(' ')
61  )
def wrap_onspace
Definition: dataformats.py:47
def dataformats.wrap_onspace_strict (   text,
  width 
)
Similar to wrap_onspace, but enforces the width constraint:
   words longer than width are split.

Definition at line 63 of file dataformats.py.

References wrap_always(), and wrap_onspace().

Referenced by lumiReport.toScreenLSEffective(), and lumiReport.toScreenTotEffective().

63 
64 def wrap_onspace_strict(text, width):
65  """Similar to wrap_onspace, but enforces the width constraint:
66  words longer than width are split."""
67  wordRegex = re.compile(r'\S{'+str(width)+r',}')
68  return wrap_onspace(wordRegex.sub(lambda m: wrap_always(m.group(),width),text),width)
def wrap_onspace
Definition: dataformats.py:47
def wrap_always
Definition: dataformats.py:70
def wrap_onspace_strict
Definition: dataformats.py:63

Variable Documentation

list dataformats.imported_modules = []

Definition at line 82 of file dataformats.py.