2 import cStringIO,operator
3 from functools
import reduce
5 def indent(rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
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 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.""" 24 return [[substr
or '' for substr
in item]
for item
in map(
None,*newRows)]
26 logicalRows = [rowWrapper(row)
for row
in rows]
28 columns =
map(
None,*reduce(operator.add,logicalRows))
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))
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:
41 + delim.join([justify(
str(item),width)
for (item,width)
in zip(row,maxWidths)]) \
43 if separateRows
or hasHeader:
print >> output, rowSeparator; hasHeader=
False 44 return output.getvalue()
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). 54 return reduce(
lambda line, word, width=width:
'%s%s%s' %
56 ' \n'[(len(line[line.rfind(
'\n')+1:])
57 + len(word.split(
'\n',1)[0]
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',}')
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))) ])
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()
91 for module
in modules_to_import:
92 m = module +
"_dataformats" 94 sys.path.append(path+
"/src/Documentation/DataFormats/python/")
96 globals()[m] = __import__(m)
97 imported_modules.append(m)
98 print "Searching in "+ module
100 print "skipping", module
106 labels = (
'Where(Package)',
'Instance',
'Container',
'Description')
110 for module
in imported_modules:
111 dict = vars(globals()[module])[
"json"]
112 for type
in [
"full",
"reco",
"aod"]:
113 for data_items
in dict[type][
'data']:
114 if query.lower()
in data_items.__str__().lower()
and not ((
"No documentation".lower())
in data_items.__str__().lower()):
115 data+= module.replace(
"_json",
"")+
" ("+ type.replace(
"full",
"FEVT") +
")||" +
"||".
join(data_items.values())+
"\n" 118 rows = [row.strip().
split(
'||')
for row
in data.splitlines()]
119 print indent([labels]+rows, hasHeader=
True, separateRows=
True, prefix=
'| ', postfix=
' |', wrapfunc=
lambda x:
wrap_always(x,width))
121 print "No documentation found" 124 print "usage: dataformats pattern_to_search" 125 print "example: dataformats muon" 126 print "Note! multiple patterns separated by space are not supported" 128 if __name__ ==
"__main__":
130 if (
"help" in sys.argv):
134 if (len(sys.argv) > 2):
136 print "\nSearching for: "+sys.argv[2]+
"\n"
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
static std::string join(char **cmd)