3 from __future__
import print_function
4 from builtins
import range
8 from pprint
import pprint
14 """Returns piece from object """ 15 parsed = GenObject.parseVariableTofill (description)
16 return GenObject.evaluateFunction (obj, parsed)
19 """Given a object and a prefix, fills an return dictionary with the 22 obj = getPieceFromObject (obj, prefix)
24 for key, description
in six.iteritems(varDict):
25 retval[key] = getPieceFromObject (obj, description)
29 def format (objDict, label, spacing=9, firstOnly = False):
30 '''return a formatted string for given object''' 31 value = objDict[label]
35 diff = objDict[
'delta_' + label]
38 if isinstance (value, float):
39 formatString =
'%%%d.%df' % (spacing, spacing - 5)
40 retval = formatString % value
41 if abs(diff) > epsilon:
43 retval +=
' [' + formatString % (diff) +
']' 45 retval +=
' (' + formatString % (value + diff) +
')' 47 retval +=
' ' * (spacing + 3)
50 formatString =
'%%%ds' % spacing
51 retval = formatString % value
53 if isinstance (value, str):
54 retval +=
' (' + formatString % diff +
')' 56 retval +=
' [' + formatString % diff +
']' 58 retval +=
' (' + formatString % (value + diff) +
')' 60 retval +=
' ' * (spacing + 3)
64 if __name__ ==
"__main__":
65 parser = optparse.OptionParser (
"Usage: %prog bla.root lib.so var1 [var2]")
66 parser.add_option (
"--delta", dest=
"delta",
67 action=
"store_true", default=
False,
68 help=
"Show deltas when difference is large enough.")
69 parser.add_option (
"--skipUndefined", dest=
"skipUndefined",
70 action=
"store_true", default=
False,
71 help=
"Skip undefined variables without warning.")
72 options, args = parser.parse_args()
75 raise RuntimeError(
"Must provide root file, shlib location, "\
76 "and at least one variable")
77 rootFilename = args.pop(0)
81 if not re.search (
r'_C.so$', shlib)
and not re.search (
r'_C$', shlib):
83 cFile = re.sub (
r'_C$',
r'.C', re.sub(
r'\.so$',
'', shlib))
84 if not os.path.exists (cFile):
85 raise RuntimeError(
"Can not find accompying C file '%s'." % cFile)
86 if not os.path.exists (rootFilename):
87 raise RuntimeError(
"Can not find root file '%s'." % rootFilename)
89 diffContRE = re.compile (
r'^class goDiffCont_(\w+)')
93 variableREDict[var] = ( re.compile (
r'\bdelta_%s\b' % var),
94 re.compile (
r'\bother_%s\b' % var) )
95 source = open (cFile,
'r') 102 match = diffContRE.search (line)
105 raise RuntimeError(
"Currently only supported for a single"\
107 name = match.group(1)
109 for key, regexTuple
in six.iteritems(variableREDict):
110 if regexTuple[0].
search(line):
111 typeFoundSet.add( key )
113 if regexTuple[1].
search(line):
114 typeFoundSet.add( key )
115 stringSet.add ( key )
117 raise RuntimeError(
"Didn't find any Diff Container")
119 for var
in variables:
120 if var
not in typeFoundSet:
121 if not options.skipUndefined:
122 raise RuntimeError(
"Variable '%s' not found." % var)
127 if ROOT.gSystem.Load (shlib):
128 raise RuntimeError(
"Can not load shilb '%s'." % shlib)
129 rootfile = ROOT.TFile.Open (rootFilename)
131 raise RuntimeError(
"Failed to open root file '%s'" % rootFilename)
132 tree = rootfile.Get (
'diffTree')
134 raise RuntimeError(
"Failed to get 'diffTree'")
135 size = tree.GetEntries()
136 runeventDict = {
'Run':
'run',
'Event':
'event'}
137 indexSingleDict = {
'index':
'index'}
138 indexDoubleDict = {
'index':
'index',
'delta_index':
'delta_index'}
141 for var
in variables:
142 infoSingleDict[var] = infoDoubleDict[var] = var;
144 infoDoubleDict[
'delta_' + var] =
'other_' + var
146 infoDoubleDict[
'delta_' + var] =
'delta_' + var
147 for index
in range (size):
148 tree.GetEntry (index)
149 runevent = getDictFromObject (tree, runeventDict,
'runevent')
152 firstOnlyColl = getPieceFromObject (tree, name +
'.firstOnly')
153 size = firstOnlyColl.size()
155 print(
"First Only:\n index ", end=
' ')
156 for var
in variables:
157 print(
"%-12s" % (
' ' + var), end=
' ')
159 print(
'-' * (12 + 11 * len(variables)))
160 for index
in range (size):
161 firstOnly = firstOnlyColl[index]
162 index = getDictFromObject (firstOnly, indexSingleDict)
163 print(
' ', format (index,
'index', 3, firstOnly =
True), end=
' ')
164 info = getDictFromObject (firstOnly, infoSingleDict)
165 for var
in variables:
166 print(
' ', format (info, var, firstOnly =
True), end=
' ')
170 secondOnlyColl = getPieceFromObject (tree, name +
'.secondOnly')
171 size = secondOnlyColl.size()
173 print(
"Second Only:\n index ", end=
' ')
174 for var
in variables:
175 print(
"%-12s" % (
' ' + var), end=
' ')
177 print(
'-' * (12 + 11 * len(variables)))
178 for index
in range (size):
179 secondOnly = secondOnlyColl[index]
180 index = getDictFromObject (secondOnly, indexSingleDict)
181 print(
' ', format (index,
'index', 3, firstOnly =
True), end=
' ')
182 info = getDictFromObject (secondOnly, infoSingleDict)
183 for var
in variables:
184 print(
' ', format (info, var, firstOnly =
True), end=
' ')
188 diffColl = getPieceFromObject (tree, name+
'.diff')
189 size = diffColl.size()
191 print(
"Both:\n index", end=
' ')
192 for var
in variables:
193 print(
"%-24s" % (
' ' + var), end=
' ')
195 print(
'-' * (16 + 23 * len(variables)))
196 for index
in range (size):
197 diff = diffColl[index]
198 index = getDictFromObject (diff, indexDoubleDict)
199 print(
' ', format (index,
'index', 3), end=
' ')
200 info = getDictFromObject (diff, infoDoubleDict)
201 for var
in variables:
202 print(
' ', format (info, var), end=
' ')
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
S & print(S &os, JobReport::InputFile const &f)
Abs< T >::type abs(const T &t)