6 from pprint
import pprint
12 """Returns piece from object """ 13 parsed = GenObject.parseVariableTofill (description)
14 return GenObject.evaluateFunction (obj, parsed)
17 """Given a object and a prefix, fills an return dictionary with the 20 obj = getPieceFromObject (obj, prefix)
22 for key, description
in six.iteritems(varDict):
23 retval[key] = getPieceFromObject (obj, description)
27 def format (objDict, label, spacing=9, firstOnly = False):
28 '''return a formatted string for given object''' 29 value = objDict[label]
33 diff = objDict[
'delta_' + label]
36 if isinstance (value, float):
37 formatString =
'%%%d.%df' % (spacing, spacing - 5)
38 retval = formatString % value
39 if abs(diff) > epsilon:
41 retval +=
' [' + formatString % (diff) +
']' 43 retval +=
' (' + formatString % (value + diff) +
')' 45 retval +=
' ' * (spacing + 3)
48 formatString =
'%%%ds' % spacing
49 retval = formatString % value
51 if isinstance (value, str):
52 retval +=
' (' + formatString % diff +
')' 54 retval +=
' [' + formatString % diff +
']' 56 retval +=
' (' + formatString % (value + diff) +
')' 58 retval +=
' ' * (spacing + 3)
62 if __name__ ==
"__main__":
63 parser = optparse.OptionParser (
"Usage: %prog bla.root lib.so var1 [var2]")
64 parser.add_option (
"--delta", dest=
"delta",
65 action=
"store_true", default=
False,
66 help=
"Show deltas when difference is large enough.")
67 parser.add_option (
"--skipUndefined", dest=
"skipUndefined",
68 action=
"store_true", default=
False,
69 help=
"Skip undefined variables without warning.")
70 options, args = parser.parse_args()
73 raise RuntimeError(
"Must provide root file, shlib location, "\
74 "and at least one variable")
75 rootFilename = args.pop(0)
79 if not re.search (
r'_C.so$', shlib)
and not re.search (
r'_C$', shlib):
81 cFile = re.sub (
r'_C$',
r'.C', re.sub(
r'\.so$',
'', shlib))
82 if not os.path.exists (cFile):
83 raise RuntimeError(
"Can not find accompying C file '%s'." % cFile)
84 if not os.path.exists (rootFilename):
85 raise RuntimeError(
"Can not find root file '%s'." % rootFilename)
87 diffContRE = re.compile (
r'^class goDiffCont_(\w+)')
91 variableREDict[var] = ( re.compile (
r'\bdelta_%s\b' % var),
92 re.compile (
r'\bother_%s\b' % var) )
93 source = open (cFile,
'r') 100 match = diffContRE.search (line)
103 raise RuntimeError(
"Currently only supported for a single"\
105 name = match.group(1)
107 for key, regexTuple
in six.iteritems(variableREDict):
108 if regexTuple[0].
search(line):
109 typeFoundSet.add( key )
111 if regexTuple[1].
search(line):
112 typeFoundSet.add( key )
113 stringSet.add ( key )
115 raise RuntimeError(
"Didn't find any Diff Container")
117 for var
in variables:
118 if var
not in typeFoundSet:
119 if not options.skipUndefined:
120 raise RuntimeError(
"Variable '%s' not found." % var)
125 if ROOT.gSystem.Load (shlib):
126 raise RuntimeError(
"Can not load shilb '%s'." % shlib)
127 rootfile = ROOT.TFile.Open (rootFilename)
129 raise RuntimeError(
"Failed to open root file '%s'" % rootFilename)
130 tree = rootfile.Get (
'diffTree')
132 raise RuntimeError(
"Failed to get 'diffTree'")
133 size = tree.GetEntries()
134 runeventDict = {
'Run':
'run',
'Event':
'event'}
135 indexSingleDict = {
'index':
'index'}
136 indexDoubleDict = {
'index':
'index',
'delta_index':
'delta_index'}
139 for var
in variables:
140 infoSingleDict[var] = infoDoubleDict[var] = var;
142 infoDoubleDict[
'delta_' + var] =
'other_' + var
144 infoDoubleDict[
'delta_' + var] =
'delta_' + var
145 for index
in range (size):
146 tree.GetEntry (index)
147 runevent = getDictFromObject (tree, runeventDict,
'runevent')
150 firstOnlyColl = getPieceFromObject (tree, name +
'.firstOnly')
151 size = firstOnlyColl.size()
153 print "First Only:\n index ",
154 for var
in variables:
155 print "%-12s" % (
' ' + var),
157 print '-' * (12 + 11 * len(variables))
158 for index
in range (size):
159 firstOnly = firstOnlyColl[index]
160 index = getDictFromObject (firstOnly, indexSingleDict)
161 print ' ', format (index,
'index', 3, firstOnly =
True),
162 info = getDictFromObject (firstOnly, infoSingleDict)
163 for var
in variables:
164 print ' ', format (info, var, firstOnly =
True),
168 secondOnlyColl = getPieceFromObject (tree, name +
'.secondOnly')
169 size = secondOnlyColl.size()
171 print "Second Only:\n index ",
172 for var
in variables:
173 print "%-12s" % (
' ' + var),
175 print '-' * (12 + 11 * len(variables))
176 for index
in range (size):
177 secondOnly = secondOnlyColl[index]
178 index = getDictFromObject (secondOnly, indexSingleDict)
179 print ' ', format (index,
'index', 3, firstOnly =
True),
180 info = getDictFromObject (secondOnly, infoSingleDict)
181 for var
in variables:
182 print ' ', format (info, var, firstOnly =
True),
186 diffColl = getPieceFromObject (tree, name+
'.diff')
187 size = diffColl.size()
189 print "Both:\n index",
190 for var
in variables:
191 print "%-24s" % (
' ' + var),
193 print '-' * (16 + 23 * len(variables))
194 for index
in range (size):
195 diff = diffColl[index]
196 index = getDictFromObject (diff, indexDoubleDict)
197 print ' ', format (index,
'index', 3),
198 info = getDictFromObject (diff, infoDoubleDict)
199 for var
in variables:
200 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)