2 import cStringIO,operator
4 def indent(rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
5 separateRows=
False, prefix=
'', postfix=
'', wrapfunc=
lambda x:x):
6 """Indents a table by column.
7 - rows: A sequence of sequences of items, one sequence per row.
8 - hasHeader: True if the first row consists of the columns' names.
9 - headerChar: Character to be used for the row separator line
10 (if hasHeader==True or separateRows==True).
11 - delim: The column delimiter.
12 - justify: Determines how are data justified in their column.
13 Valid values are 'left','right' and 'center'.
14 - separateRows: True if rows are to be separated by a line
16 - prefix: A string prepended to each printed row.
17 - postfix: A string appended to each printed row.
18 - wrapfunc: A function f(text) for wrapping text; each element in
19 the table is first wrapped by this function."""
22 newRows = [wrapfunc(item).
split(
'\n')
for item
in row]
23 return [[substr
or '' for substr
in item]
for item
in map(
None,*newRows)]
25 logicalRows = [rowWrapper(row)
for row
in rows]
27 columns =
map(
None,*reduce(operator.add,logicalRows))
29 maxWidths = [
max([len(str(item))
for item
in column])
for column
in columns]
30 rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) + \
31 len(delim)*(len(maxWidths)-1))
33 justify = {
'center':str.center,
'right':str.rjust,
'left':str.ljust}[justify.lower()]
34 output=cStringIO.StringIO()
35 if separateRows:
print >> output, rowSeparator
36 for physicalRows
in logicalRows:
37 for row
in physicalRows:
40 + delim.join([justify(str(item),width)
for (item,width)
in zip(row,maxWidths)]) \
42 if separateRows
or hasHeader:
print >> output, rowSeparator; hasHeader=
False
43 return output.getvalue()
49 A word-wrap function that preserves existing line breaks
50 and most spaces in the text. Expects that existing line
51 breaks are posix newlines (\n).
53 return reduce(
lambda line, word, width=width:
'%s%s%s' %
55 ' \n'[(len(line[line.rfind(
'\n')+1:])
56 + len(word.split(
'\n',1)[0]
64 """Similar to wrap_onspace, but enforces the width constraint:
65 words longer than width are split."""
66 wordRegex = re.compile(
r'\S{'+str(width)+
r',}')
71 """A simple word-wrap function that wraps text on exactly width characters.
72 It doesn't split the text in words."""
73 return '\n'.
join([ text[width*i:width*(i+1)] \
74 for i
in xrange(int(math.ceil(1.*len(text)/width))) ])
86 modules_to_import =
"RecoTracker RecoLocalTracker RecoLocalCalo RecoEcal RecoEgamma RecoLocalMuon RecoMuon RecoJets RecoMET RecoBTag RecoTauTag RecoVertex RecoPixelVertexing HLTrigger RecoParticleFlow".
split()
87 modules_to_import =
"RecoLocalTracker RecoLocalMuon RecoLocalCalo RecoEcal TrackingTools RecoTracker RecoJets RecoMET RecoMuon RecoBTau RecoBTag RecoTauTag RecoVertex RecoPixelVertexing RecoEgamma RecoParticleFlow L1Trigger".
split()
90 for m
in modules_to_import:
91 m = m +
"_dataformats"
93 sys.path.append(path+
"/src/Documentation/DataFormats/python/")
94 globals()[m] = __import__(m)
95 imported_modules.append(m)
103 labels = (
'Where(Package)',
'Instance',
'Container',
'Description')
107 for module
in imported_modules:
108 for dict_name
in [
"full",
"reco",
"aod"]:
110 dict = vars(globals()[module])[dict_name]
112 for key
in sorted(dict.keys()):
115 if query.lower()
in element.__str__().lower():
116 if not ((
"No documentation".lower())
in element.__str__().lower()):
117 data+= module.replace(
"_dataformats",
"")+
" ("+ dict_name.replace(
"full",
"FEVT") +
")||" +
"||".
join(element)+
"\n"
120 rows = [row.strip().
split(
'||')
for row
in data.splitlines()]
121 print indent([labels]+rows, hasHeader=
True, separateRows=
True, prefix=
'| ', postfix=
' |', wrapfunc=
lambda x:
wrap_always(x,width))
123 print "No documentation found"
126 print "usage: dataformats pattern_to_search"
127 print "example: dataformats muon"
128 print "Note! multiple patterns separated by space are not supported"
130 if __name__ ==
"__main__":
132 if (
"help" in sys.argv):
139 if (len(sys.argv) > 2):
141 print "\nSearching for: "+sys.argv[2]+
"\n"
const T & max(const T &a, const T &b)
static std::string join(char **cmd)