The Gaudi Framework  v36r1 (3e2fb5a8)
custom_axis.py
Go to the documentation of this file.
1 
11 import os
12 from traceback import format_exc
13 
14 FILENAME = f"{__name__}.root"
15 
16 
17 def config():
18  import GaudiConfig2.Configurables as C
19  import GaudiConfig2.Configurables.Gaudi.Tests.Histograms.CustomAxis as T
20 
21  algs = []
22  tools = []
23  svcs = []
24 
25  Alg = T.EnumAxisAlg
26  algs.append(Alg("Alg"))
27 
28  svcs.append(C.Gaudi.Histograming.Sink.Root(FileName=FILENAME))
29  svcs.append(C.Gaudi.Monitoring.MessageSvcSink())
30 
31  yield from algs
32  yield from tools
33  yield from svcs
34 
35  yield C.ApplicationMgr(
36  EvtMax=5,
37  EvtSel="NONE",
38  TopAlg=algs,
39  ExtSvc=svcs,
40  )
41 
42  # make sure the histogram file is not already there
43  if os.path.exists(FILENAME):
44  os.remove(FILENAME)
45 
46 
47 def check(causes, result):
48  result["root_output_file"] = FILENAME
49 
50  if not os.path.exists(FILENAME):
51  causes.append("missing histogram file")
52  return False
53 
54  try:
55  import ROOT
56  f = ROOT.TFile.Open(FILENAME)
57 
58  h = f.Get("Alg/Categories")
59  if not h:
60  k = f.GetKey("Alg/Categories")
61  if k:
62  h = k.ReadObj()
63 
64  assert h, "missing histogram"
65 
66  if h.GetNbinsX() != 4:
67  causes.append("number of bins")
68  result["error"] = f"expected 4 bins, got {h.GetNbinsX()}"
69  return False
70 
71  axis = h.GetXaxis()
72  labels = list(axis.GetLabels())
73  expected = ["Simple", "Complex", "Bad", "Wrong"]
74  if labels != expected:
75  causes.append("wrong axis labels")
76  result["expected_labels"] = ", ".join(repr(l) for l in expected)
77  result["found_labels"] = ", ".join(repr(l) for l in labels)
78  return False
79 
80  except AssertionError as err:
81  causes.append(str(err))
82  return False
83 
84  except Exception as err:
85  causes.append("failure reading histogram file")
86  result["python_exception"] = result.Quote(format_exc())
87  return False
88 
89  return True
GaudiTests.Histograms.custom_axis.config
def config()
Definition: custom_axis.py:17
GaudiTests.Histograms.custom_axis.check
def check(causes, result)
Definition: custom_axis.py:47
GaudiConfig2.Configurables
Definition: Configurables.py:1