The Gaudi Framework  v36r1 (3e2fb5a8)
axes_labels.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.AxesLabels as T
20 
21  algs = []
22  svcs = []
23 
24  HistoAlgo = T.HistWithLabelsAlg
25  algs.append(HistoAlgo("HistoAlgo"))
26 
27  svcs.append(C.Gaudi.Histograming.Sink.Root(FileName=FILENAME))
28  svcs.append(C.Gaudi.Monitoring.MessageSvcSink())
29 
30  yield from algs
31  yield from svcs
32 
33  yield C.ApplicationMgr(
34  EvtMax=5,
35  EvtSel="NONE",
36  TopAlg=algs,
37  ExtSvc=svcs,
38  )
39 
40  # make sure the histogram file is not already there
41  if os.path.exists(FILENAME):
42  os.remove(FILENAME)
43 
44 
45 def check(causes, result):
46  result["root_output_file"] = FILENAME
47 
48  if not os.path.exists(FILENAME):
49  causes.append("missing histogram file")
50  return False
51 
52  try:
53  import ROOT
54  f = ROOT.TFile.Open(FILENAME)
55  h = f.Get("HistoAlgo/hist")
56  axis = h.GetXaxis()
57  labels = list(axis.GetLabels())
58  expected = ["a", "b", "c", "d", "e"]
59  if labels != expected:
60  causes.append("wrong axis labels")
61  result["expected_labels"] = ", ".join(repr(l) for l in expected)
62  result["found_labels"] = ", ".join(repr(l) for l in labels)
63  return False
64 
65  except Exception as err:
66  causes.append("failure reading histogram file")
67  result["python_exception"] = result.Quote(format_exc())
68  return False
69 
70  return True
GaudiTests.Histograms.axes_labels.check
def check(causes, result)
Definition: axes_labels.py:45
GaudiTests.Histograms.axes_labels.config
def config()
Definition: axes_labels.py:17
GaudiConfig2.Configurables
Definition: Configurables.py:1