Functions | |
def | help |
def | importDF |
def | indent |
def | search |
def | wrap_always |
def | wrap_onspace |
def | wrap_onspace_strict |
Variables | |
list | imported_modules = [] |
def dataformats::help | ( | ) |
Definition at line 122 of file dataformats.py.
00122 : 00123 print "usage: dataformats pattern_to_search" 00124 print "example: dataformats muon" 00125 print "Note! multiple patterns separated by space are not supported" 00126
def dataformats::importDF | ( | path | ) |
Definition at line 84 of file dataformats.py.
00084 : 00085 00086 modules_to_import = "RecoTracker RecoLocalTracker RecoLocalCalo RecoEcal RecoEgamma RecoLocalMuon RecoMuon RecoJets RecoMET RecoBTag RecoTauTag RecoVertex RecoPixelVertexing HLTrigger RecoParticleFlow".split() 00087 modules_to_import = "RecoLocalTracker RecoLocalMuon RecoLocalCalo RecoEcal TrackingTools RecoTracker RecoJets RecoMET RecoMuon RecoBTau RecoBTag RecoTauTag RecoVertex RecoPixelVertexing RecoEgamma RecoParticleFlow L1Trigger".split() 00088 00089 00090 for module in modules_to_import: 00091 m = module + "_dataformats" 00092 try: 00093 sys.path.append(path+"/src/Documentation/DataFormats/python/") 00094 # sys.path.append(".") 00095 globals()[m] = __import__(m) 00096 imported_modules.append(m) 00097 print "Searching in "+ module 00098 except ImportError: 00099 print "skipping", module 00100 00101 # END of import 00102 00103
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 4 of file dataformats.py.
Referenced by CalibrationXML::addChild(), FWPSetTableManager::cellRenderer(), node_filter(), operator<<(), and edm::ParameterDescription< std::vector< ParameterSet > >::writeOneElementToCfi().
00005 :x): 00006 """Indents a table by column. 00007 - rows: A sequence of sequences of items, one sequence per row. 00008 - hasHeader: True if the first row consists of the columns' names. 00009 - headerChar: Character to be used for the row separator line 00010 (if hasHeader==True or separateRows==True). 00011 - delim: The column delimiter. 00012 - justify: Determines how are data justified in their column. 00013 Valid values are 'left','right' and 'center'. 00014 - separateRows: True if rows are to be separated by a line 00015 of 'headerChar's. 00016 - prefix: A string prepended to each printed row. 00017 - postfix: A string appended to each printed row. 00018 - wrapfunc: A function f(text) for wrapping text; each element in 00019 the table is first wrapped by this function.""" 00020 # closure for breaking logical rows to physical, using wrapfunc 00021 def rowWrapper(row): 00022 newRows = [wrapfunc(item).split('\n') for item in row] 00023 return [[substr or '' for substr in item] for item in map(None,*newRows)] 00024 # break each logical row into one or more physical ones 00025 logicalRows = [rowWrapper(row) for row in rows] 00026 # columns of physical rows 00027 columns = map(None,*reduce(operator.add,logicalRows)) 00028 # get the maximum of each column by the string length of its items 00029 maxWidths = [max([len(str(item)) for item in column]) for column in columns] 00030 rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) + \ 00031 len(delim)*(len(maxWidths)-1)) 00032 # select the appropriate justify method 00033 justify = {'center':str.center, 'right':str.rjust, 'left':str.ljust}[justify.lower()] 00034 output=cStringIO.StringIO() 00035 if separateRows: print >> output, rowSeparator 00036 for physicalRows in logicalRows: 00037 for row in physicalRows: 00038 print >> output, \ 00039 prefix \ 00040 + delim.join([justify(str(item),width) for (item,width) in zip(row,maxWidths)]) \ 00041 + postfix 00042 if separateRows or hasHeader: print >> output, rowSeparator; hasHeader=False 00043 return output.getvalue() 00044 00045 # written by Mike Brown 00046 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
def dataformats::search | ( | query | ) |
Definition at line 104 of file dataformats.py.
Referenced by AlignmentMonitorTemplate::event().
00104 : 00105 labels = ('Where(Package)', 'Instance', 'Container', 'Description') 00106 width = 20 00107 data = "" 00108 00109 for module in imported_modules: 00110 dict = vars(globals()[module])["json"] 00111 for type in ["full", "reco", "aod"]: 00112 for data_items in dict[type]['data']: 00113 if query.lower() in data_items.__str__().lower() and not (("No documentation".lower()) in data_items.__str__().lower()): 00114 data+= module.replace("_json", "")+" ("+ type.replace("full", "FEVT") + ")||" + "||".join(data_items.values())+"\n" 00115 00116 if (data != ""): 00117 rows = [row.strip().split('||') for row in data.splitlines()] 00118 print indent([labels]+rows, hasHeader=True, separateRows=True, prefix='| ', postfix=' |', wrapfunc=lambda x: wrap_always(x,width)) 00119 else: 00120 print "No documentation found" 00121
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.
00070 : 00071 """A simple word-wrap function that wraps text on exactly width characters. 00072 It doesn't split the text in words.""" 00073 return '\n'.join([ text[width*i:width*(i+1)] \ 00074 for i in xrange(int(math.ceil(1.*len(text)/width))) ]) 00075 00076 00077 00078 # END OF TABLE FORMATING 00079 00080 # START of import
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.
00047 : 00048 """ 00049 A word-wrap function that preserves existing line breaks 00050 and most spaces in the text. Expects that existing line 00051 breaks are posix newlines (\n). 00052 """ 00053 return reduce(lambda line, word, width=width: '%s%s%s' % 00054 (line, 00055 ' \n'[(len(line[line.rfind('\n')+1:]) 00056 + len(word.split('\n',1)[0] 00057 ) >= width)], 00058 word), 00059 text.split(' ') 00060 ) 00061
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.
00063 : 00064 """Similar to wrap_onspace, but enforces the width constraint: 00065 words longer than width are split.""" 00066 wordRegex = re.compile(r'\S{'+str(width)+r',}') 00067 return wrap_onspace(wordRegex.sub(lambda m: wrap_always(m.group(),width),text),width) 00068
list dataformats::imported_modules = [] |
Definition at line 82 of file dataformats.py.