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 module
in modules_to_import:
91 m = module +
"_dataformats"
93 sys.path.append(path+
"/src/Documentation/DataFormats/python/")
95 globals()[m] = __import__(m)
96 imported_modules.append(m)
97 print "Searching in "+ module
99 print "skipping", module
105 labels = (
'Where(Package)',
'Instance',
'Container',
'Description')
109 for module
in imported_modules:
110 dict = vars(globals()[module])[
"json"]
111 for type
in [
"full",
"reco",
"aod"]:
112 for data_items
in dict[type][
'data']:
113 if query.lower()
in data_items.__str__().lower()
and not ((
"No documentation".lower())
in data_items.__str__().lower()):
114 data+= module.replace(
"_json",
"")+
" ("+ type.replace(
"full",
"FEVT") +
")||" +
"||".
join(data_items.values())+
"\n"
117 rows = [row.strip().
split(
'||')
for row
in data.splitlines()]
118 print indent([labels]+rows, hasHeader=
True, separateRows=
True, prefix=
'| ', postfix=
' |', wrapfunc=
lambda x:
wrap_always(x,width))
120 print "No documentation found"
123 print "usage: dataformats pattern_to_search"
124 print "example: dataformats muon"
125 print "Note! multiple patterns separated by space are not supported"
127 if __name__ ==
"__main__":
129 if (
"help" in sys.argv):
133 if (len(sys.argv) > 2):
135 print "\nSearching for: "+sys.argv[2]+
"\n"
const T & max(const T &a, const T &b)
static std::string join(char **cmd)