13 from collections
import defaultdict
14 from traceback
import format_exc
15 from unittest
import TestCase
17 FILENAME = f
"{__name__}.root"
18 FILENAMEJSON = f
"{__name__}.json"
23 import GaudiConfig2.Configurables.Gaudi.Tests.Histograms.MultiDimLayout
as T
30 algs.append(Alg(
"Alg"))
32 svcs.append(C.Gaudi.Histograming.Sink.Root(FileName=FILENAME))
33 svcs.append(C.Gaudi.Monitoring.JSONSink(FileName=FILENAMEJSON))
34 svcs.append(C.Gaudi.Monitoring.MessageSvcSink())
40 yield C.ApplicationMgr(
48 if os.path.exists(FILENAME):
53 result[
"root_output_file"] = FILENAME
55 if not os.path.exists(FILENAME):
56 causes.append(
"missing histogram file")
62 f = ROOT.TFile.Open(FILENAME)
67 h = f.Get(f
"Alg/h{i}")
69 k = f.GetKey(f
"Alg/h{i}")
73 assert h, f
"missing histogram Alg/h{i}"
79 expected = defaultdict(dict)
80 found = defaultdict(dict)
81 for x
in [i - 0.5
for i
in range(12)]:
83 expected[
"h1"][x] = value
84 found[
"h1"][x] = h1.GetBinContent(h1.FindBin(x))
85 for y
in [i - 0.5
for i
in range(12)]:
87 expected[
"h2"][(x, y)] = value
88 found[
"h2"][(x, y)] = h2.GetBinContent(h2.FindBin(x, y))
89 for z
in [i - 0.5
for i
in range(12)]:
91 expected[
"h3"][(x, y, z)] = value
92 found[
"h3"][(x, y, z)] = h3.GetBinContent(h3.FindBin(x, y, z))
99 t.assertEqual(expected[name], found[name])
100 except AssertionError
as err:
101 diffs[name] = str(err).splitlines()[0]
104 causes.append(
"histograms content")
106 result[f
"{name}_diff"] = diffs[name]
108 except AssertionError
as err:
109 causes.append(str(err))
113 causes.append(
"failure reading histogram file")
114 result[
"python_exception"] = result.Quote(format_exc())