6 from pprint
import pprint
11 """Returns piece from object """
12 parsed = GenObject.parseVariableTofill (description)
13 return GenObject.evaluateFunction (obj, parsed)
16 """Given a object and a prefix, fills an return dictionary with the
19 obj = getPieceFromObject (obj, prefix)
21 for key, description
in varDict.iteritems():
22 retval[key] = getPieceFromObject (obj, description)
26 def format (objDict, label, spacing=9, firstOnly = False):
27 '''return a formatted string for given object'''
28 value = objDict[label]
32 diff = objDict[
'delta_' + label]
35 if isinstance (value, float):
36 formatString =
'%%%d.%df' % (spacing, spacing - 5)
37 retval = formatString % value
38 if abs(diff) > epsilon:
40 retval +=
' [' + formatString % (diff) +
']'
42 retval +=
' (' + formatString % (value + diff) +
')'
44 retval +=
' ' * (spacing + 3)
47 formatString =
'%%%ds' % spacing
48 retval = formatString % value
50 if isinstance (value, str):
51 retval +=
' (' + formatString % diff +
')'
53 retval +=
' [' + formatString % diff +
']'
55 retval +=
' (' + formatString % (value + diff) +
')'
57 retval +=
' ' * (spacing + 3)
61 if __name__ ==
"__main__":
62 parser = optparse.OptionParser (
"Usage: %prog bla.root lib.so var1 [var2]")
63 parser.add_option (
"--delta", dest=
"delta",
64 action=
"store_true", default=
False,
65 help=
"Show deltas when difference is large enough.")
66 parser.add_option (
"--skipUndefined", dest=
"skipUndefined",
67 action=
"store_true", default=
False,
68 help=
"Skip undefined variables without warning.")
69 options, args = parser.parse_args()
72 raise RuntimeError,
"Must provide root file, shlib location, "\
73 "and at least one variable"
74 rootFilename = args.pop(0)
78 if not re.search (
r'_C.so$', shlib)
and not re.search (
r'_C$', shlib):
80 cFile = re.sub (
r'_C$',
r'.C', re.sub(
r'\.so$',
'', shlib))
81 if not os.path.exists (cFile):
82 raise RuntimeError,
"Can not find accompying C file '%s'." % cFile
83 if not os.path.exists (rootFilename):
84 raise RuntimeError,
"Can not find root file '%s'." % rootFilename
86 diffContRE = re.compile (
r'^class goDiffCont_(\w+)')
90 variableREDict[var] = ( re.compile (
r'\bdelta_%s\b' % var),
91 re.compile (
r'\bother_%s\b' % var) )
92 source = open (cFile,
'r')
99 match = diffContRE.search (line)
102 raise RuntimeError,
"Currently only supported for a single"\
104 name = match.group(1)
106 for key, regexTuple
in variableREDict.iteritems():
107 if regexTuple[0].
search(line):
108 typeFoundSet.add( key )
110 if regexTuple[1].
search(line):
111 typeFoundSet.add( key )
112 stringSet.add ( key )
114 raise RuntimeError,
"Didn't find any Diff Container"
116 for var
in variables:
117 if var
not in typeFoundSet:
118 if not options.skipUndefined:
119 raise RuntimeError,
"Variable '%s' not found." % var
124 if ROOT.gSystem.Load (shlib):
125 raise RuntimeError,
"Can not load shilb '%s'." % shlib
126 rootfile = ROOT.TFile.Open (rootFilename)
128 raise RuntimeError,
"Failed to open root file '%s'" % rootFilename
129 tree = rootfile.Get (
'diffTree')
131 raise RuntimeError,
"Failed to get 'diffTree'"
132 size = tree.GetEntries()
133 runeventDict = {
'Run':
'run',
'Event':
'event'}
134 indexSingleDict = {
'index':
'index'}
135 indexDoubleDict = {
'index':
'index',
'delta_index':
'delta_index'}
138 for var
in variables:
139 infoSingleDict[var] = infoDoubleDict[var] = var;
141 infoDoubleDict[
'delta_' + var] =
'other_' + var
143 infoDoubleDict[
'delta_' + var] =
'delta_' + var
144 for index
in range (size):
145 tree.GetEntry (index)
146 runevent = getDictFromObject (tree, runeventDict,
'runevent')
149 firstOnlyColl = getPieceFromObject (tree, name +
'.firstOnly')
150 size = firstOnlyColl.size()
152 print "First Only:\n index ",
153 for var
in variables:
154 print "%-12s" % (
' ' + var),
156 print '-' * (12 + 11 * len(variables))
157 for index
in range (size):
158 firstOnly = firstOnlyColl[index]
159 index = getDictFromObject (firstOnly, indexSingleDict)
160 print ' ', format (index,
'index', 3, firstOnly =
True),
161 info = getDictFromObject (firstOnly, infoSingleDict)
162 for var
in variables:
163 print ' ', format (info, var, firstOnly =
True),
167 secondOnlyColl = getPieceFromObject (tree, name +
'.secondOnly')
168 size = secondOnlyColl.size()
170 print "Second Only:\n index ",
171 for var
in variables:
172 print "%-12s" % (
' ' + var),
174 print '-' * (12 + 11 * len(variables))
175 for index
in range (size):
176 secondOnly = secondOnlyColl[index]
177 index = getDictFromObject (secondOnly, indexSingleDict)
178 print ' ', format (index,
'index', 3, firstOnly =
True),
179 info = getDictFromObject (secondOnly, infoSingleDict)
180 for var
in variables:
181 print ' ', format (info, var, firstOnly =
True),
185 diffColl = getPieceFromObject (tree, name+
'.diff')
186 size = diffColl.size()
188 print "Both:\n index",
189 for var
in variables:
190 print "%-24s" % (
' ' + var),
192 print '-' * (16 + 23 * len(variables))
193 for index
in range (size):
194 diff = diffColl[index]
195 index = getDictFromObject (diff, indexDoubleDict)
196 print ' ', format (index,
'index', 3),
197 info = getDictFromObject (diff, infoDoubleDict)
198 for var
in variables:
199 print ' ', format (info, var),
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Abs< T >::type abs(const T &t)