CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 123 of file dataformats.py.

References importDF(), print(), and search().

124 def help():
125  print("usage: dataformats pattern_to_search")
126  print("example: dataformats muon")
127  print("Note! multiple patterns separated by space are not supported")
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def dataformats.importDF (   path)

Definition at line 85 of file dataformats.py.

References print(), and submitPVValidationJobs.split().

Referenced by help().

85 
86 def importDF(path):
87 
88  modules_to_import = "RecoTracker RecoLocalTracker RecoLocalCalo RecoEcal RecoEgamma RecoLocalMuon RecoMuon RecoJets RecoMET RecoBTag RecoTauTag RecoVertex RecoPixelVertexing HLTrigger RecoParticleFlow".split()
89  modules_to_import = "RecoLocalTracker RecoLocalMuon RecoLocalCalo RecoEcal TrackingTools RecoTracker RecoJets RecoMET RecoMuon RecoBTau RecoBTag RecoTauTag RecoVertex RecoPixelVertexing RecoEgamma RecoParticleFlow L1Trigger".split()
90 
91 
92  for module in modules_to_import:
93  m = module + "_dataformats"
94  try:
95  sys.path.append(path+"/src/Documentation/DataFormats/python/")
96 # sys.path.append(".")
97  globals()[m] = __import__(m)
98  imported_modules.append(m)
99  print("Searching in "+ module)
100  except ImportError:
101  print("skipping", module)
102 
103 # END of import
104 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
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 7 of file dataformats.py.

References SiStripPI.max, print(), submitPVValidationJobs.split(), str, and ComparisonHelper.zip().

Referenced by CalibrationXML.addChild(), FWPSetTableManager.cellRenderer(), node_filter(), operator<<(), search(), JsonOutputProducer::JsonConfigurationBlock.serialise(), JsonOutputProducer::JsonConfiguration.serialise(), JsonOutputProducer::JsonVars.serialise(), JsonOutputProducer::JsonTriggerEventState.serialise(), JsonOutputProducer::JsonEvent.serialise(), JsonOutputProducer.write(), and edm::ParameterDescription< std::vector< ParameterSet > >.writeOneElementToCfi().

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

Definition at line 105 of file dataformats.py.

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

Referenced by help().

106 def search(query):
107  labels = ('Where(Package)', 'Instance', 'Container', 'Description')
108  width = 20
109  data = ""
110 
111  for module in imported_modules:
112  dict = vars(globals()[module])["json"]
113  for type in ["full", "reco", "aod"]:
114  for data_items in dict[type]['data']:
115  if query.lower() in data_items.__str__().lower() and not (("No documentation".lower()) in data_items.__str__().lower()):
116  data+= module.replace("_json", "")+" ("+ type.replace("full", "FEVT") + ")||" + "||".join(data_items.values())+"\n"
117 
118  if (data != ""):
119  rows = [row.strip().split('||') for row in data.splitlines()]
120  print(indent([labels]+rows, hasHeader=True, separateRows=True, prefix='| ', postfix=' |', wrapfunc=lambda x: wrap_always(x,width)))
121  else:
122  print("No documentation found")
def wrap_always
Definition: dataformats.py:71
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
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 71 of file dataformats.py.

References join().

Referenced by search(), and wrap_onspace_strict().

71 
72 def wrap_always(text, width):
73  """A simple word-wrap function that wraps text on exactly width characters.
74  It doesn't split the text in words."""
75  return '\n'.join([ text[width*i:width*(i+1)] \
76  for i in xrange(int(math.ceil(1.*len(text)/width))) ])
77 
78 
79 
80 # END OF TABLE FORMATING
81 
# START of import
def wrap_always
Definition: dataformats.py:71
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
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 48 of file dataformats.py.

Referenced by wrap_onspace_strict().

48 
49 def wrap_onspace(text, width):
50  """
51  A word-wrap function that preserves existing line breaks
52  and most spaces in the text. Expects that existing line
53  breaks are posix newlines (\n).
54  """
55  return reduce(lambda line, word, width=width: '%s%s%s' %
56  (line,
57  ' \n'[(len(line[line.rfind('\n')+1:])
58  + len(word.split('\n',1)[0]
59  ) >= width)],
60  word),
61  text.split(' ')
62  )
def wrap_onspace
Definition: dataformats.py:48
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 64 of file dataformats.py.

References str, wrap_always(), and wrap_onspace().

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

Variable Documentation

list dataformats.imported_modules = []

Definition at line 83 of file dataformats.py.