3 from __future__
import print_function
4 from builtins
import range
8 from pprint
import pprint
13 """Returns piece from object """ 14 parsed = GenObject.parseVariableTofill (description)
15 return GenObject.evaluateFunction (obj, parsed)
18 """Given a object and a prefix, fills an return dictionary with the 21 obj = getPieceFromObject (obj, prefix)
23 for key, description
in varDict.items():
24 retval[key] = getPieceFromObject (obj, description)
28 def format (objDict, label, spacing=9, firstOnly = False):
29 '''return a formatted string for given object''' 30 value = objDict[label]
34 diff = objDict[
'delta_' + label]
37 if isinstance (value, float):
38 formatString =
'%%%d.%df' % (spacing, spacing - 5)
39 retval = formatString % value
40 if abs(diff) > epsilon:
42 retval +=
' [' + formatString % (diff) +
']' 44 retval +=
' (' + formatString % (value + diff) +
')' 46 retval +=
' ' * (spacing + 3)
49 formatString =
'%%%ds' % spacing
50 retval = formatString % value
52 if isinstance (value, str):
53 retval +=
' (' + formatString % diff +
')' 55 retval +=
' [' + formatString % diff +
']' 57 retval +=
' (' + formatString % (value + diff) +
')' 59 retval +=
' ' * (spacing + 3)
63 if __name__ ==
"__main__":
64 parser = optparse.OptionParser (
"Usage: %prog bla.root lib.so var1 [var2]")
65 parser.add_option (
"--delta", dest=
"delta",
66 action=
"store_true", default=
False,
67 help=
"Show deltas when difference is large enough.")
68 parser.add_option (
"--skipUndefined", dest=
"skipUndefined",
69 action=
"store_true", default=
False,
70 help=
"Skip undefined variables without warning.")
71 options, args = parser.parse_args()
74 raise RuntimeError(
"Must provide root file, shlib location, "\
75 "and at least one variable")
76 rootFilename = args.pop(0)
80 if not re.search (
r'_C.so$', shlib)
and not re.search (
r'_C$', shlib):
82 cFile = re.sub (
r'_C$',
r'.C', re.sub(
r'\.so$',
'', shlib))
83 if not os.path.exists (cFile):
84 raise RuntimeError(
"Can not find accompying C file '%s'." % cFile)
85 if not os.path.exists (rootFilename):
86 raise RuntimeError(
"Can not find root file '%s'." % rootFilename)
88 diffContRE = re.compile (
r'^class goDiffCont_(\w+)')
92 variableREDict[var] = ( re.compile (
r'\bdelta_%s\b' % var),
93 re.compile (
r'\bother_%s\b' % var) )
94 source = open (cFile,
'r') 101 match = diffContRE.search (line)
104 raise RuntimeError(
"Currently only supported for a single"\
106 name = match.group(1)
108 for key, regexTuple
in variableREDict.items():
109 if regexTuple[0].
search(line):
110 typeFoundSet.add( key )
112 if regexTuple[1].
search(line):
113 typeFoundSet.add( key )
114 stringSet.add ( key )
116 raise RuntimeError(
"Didn't find any Diff Container")
118 for var
in variables:
119 if var
not in typeFoundSet:
120 if not options.skipUndefined:
121 raise RuntimeError(
"Variable '%s' not found." % var)
126 if ROOT.gSystem.Load (shlib):
127 raise RuntimeError(
"Can not load shilb '%s'." % shlib)
128 rootfile = ROOT.TFile.Open (rootFilename)
130 raise RuntimeError(
"Failed to open root file '%s'" % rootFilename)
131 tree = rootfile.Get (
'diffTree')
133 raise RuntimeError(
"Failed to get 'diffTree'")
134 size = tree.GetEntries()
135 runeventDict = {
'Run':
'run',
'Event':
'event'}
136 indexSingleDict = {
'index':
'index'}
137 indexDoubleDict = {
'index':
'index',
'delta_index':
'delta_index'}
140 for var
in variables:
141 infoSingleDict[var] = infoDoubleDict[var] = var;
143 infoDoubleDict[
'delta_' + var] =
'other_' + var
145 infoDoubleDict[
'delta_' + var] =
'delta_' + var
146 for index
in range (size):
147 tree.GetEntry (index)
148 runevent = getDictFromObject (tree, runeventDict,
'runevent')
151 firstOnlyColl = getPieceFromObject (tree, name +
'.firstOnly')
152 size = firstOnlyColl.size()
154 print(
"First Only:\n index ", end=
' ')
155 for var
in variables:
156 print(
"%-12s" % (
' ' + var), end=
' ')
158 print(
'-' * (12 + 11 * len(variables)))
159 for index
in range (size):
160 firstOnly = firstOnlyColl[index]
161 index = getDictFromObject (firstOnly, indexSingleDict)
162 print(
' ', format (index,
'index', 3, firstOnly =
True), end=
' ')
163 info = getDictFromObject (firstOnly, infoSingleDict)
164 for var
in variables:
165 print(
' ', format (info, var, firstOnly =
True), end=
' ')
169 secondOnlyColl = getPieceFromObject (tree, name +
'.secondOnly')
170 size = secondOnlyColl.size()
172 print(
"Second Only:\n index ", end=
' ')
173 for var
in variables:
174 print(
"%-12s" % (
' ' + var), end=
' ')
176 print(
'-' * (12 + 11 * len(variables)))
177 for index
in range (size):
178 secondOnly = secondOnlyColl[index]
179 index = getDictFromObject (secondOnly, indexSingleDict)
180 print(
' ', format (index,
'index', 3, firstOnly =
True), end=
' ')
181 info = getDictFromObject (secondOnly, infoSingleDict)
182 for var
in variables:
183 print(
' ', format (info, var, firstOnly =
True), end=
' ')
187 diffColl = getPieceFromObject (tree, name+
'.diff')
188 size = diffColl.size()
190 print(
"Both:\n index", end=
' ')
191 for var
in variables:
192 print(
"%-24s" % (
' ' + var), end=
' ')
194 print(
'-' * (16 + 23 * len(variables)))
195 for index
in range (size):
196 diff = diffColl[index]
197 index = getDictFromObject (diff, indexDoubleDict)
198 print(
' ', format (index,
'index', 3), end=
' ')
199 info = getDictFromObject (diff, infoDoubleDict)
200 for var
in variables:
201 print(
' ', format (info, var), end=
' ')
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)