Belle II Software development
OnlineImport2.py
1#!/usr/bin/env python3
2
3
10'''
11DQM RootImport test
12Test import for Online system root file
13with histograms in subdirs
14'''
15import os
16import basf2 as b2
17from ROOT import Belle2, TFile, TH1F, gROOT
18
19gROOT.SetBatch(True)
20
21filein = "histino2.root"
22fileout = 'histouto2.root'
23statfile = "statso2.txt"
24
25f = TFile(filein, "RECREATE")
26
27f.mkdir("DQMInfo")
28f.cd("DQMInfo")
29h_expno = TH1F("expno", "1", 1, 0, 1)
30h_runno = TH1F("runno", "1", 1, 0, 1)
31h_rtype = TH1F("rtype", "null", 1, 0, 1)
32f.cd("..")
33
34f.mkdir("TEST")
35f.cd("TEST")
36h_test = TH1F("test", "", 1, 0, 1)
37f.cd("..")
38
39f.mkdir("DAQ")
40f.cd("DAQ")
41h_nevent = TH1F("Nevent", "", 1, 0, 1)
42for n in range(0, 10):
43 h_nevent.Fill(n)
44f.cd("..")
45
46f.Write()
47f.Close()
48
49Belle2.Environment.Instance().setNumberEventsOverride(1)
50
51main = b2.create_path()
52emptypath = b2.create_path()
53
54dqminput = b2.register_module('DQMHistAnalysisInput2')
55dqminput.param('HistMemoryPath', filein)
56dqminput.param('RefreshInterval', 0)
57dqminput.param('StatFileName', statfile)
58dqminput.param("EnableRunInfo", True)
59dqminput.if_false(emptypath)
60main.add_module(dqminput)
61
62main.add_module("DQMHistAutoCanvas")
63
64dqmoutput = b2.register_module('DQMHistAnalysisOutputFile')
65dqmoutput.param('OutputFolder', './')
66dqmoutput.param('Filename', fileout)
67main.add_module(dqmoutput)
68
69# Process all events
70b2.process(main)
71
72expected = ["DQMInfo/c_info", "DAQ/c_Nevent", "DQMInfo/c_expno", "DQMInfo/c_runno", "DQMInfo/c_rtype", "TEST/c_test"]
73b2.B2INFO("== resulting file content ==")
74f = TFile(fileout, "READ")
75for k in f.GetListOfKeys():
76 o = k.ReadObj()
77 b2.B2INFO(o.ClassName(), k)
78 if o.GetName() == "DQMInfo/c_info":
79 if "Exp 1, Run 1, RunType null" not in o.GetTitle():
80 b2.B2ERROR(f"Run Info not found in {o.GetName()}: {o.GetTitle()}")
81 if o.GetName() in expected:
82 expected.remove(o.GetName())
83b2.B2INFO("============================")
84if len(expected) > 0:
85 b2.B2ERROR("missing items in outfile: ", expected)
86b2.B2INFO("== resulting stat content ==")
87with open(statfile, 'r') as f:
88 b2.B2INFO(f.read())
89b2.B2INFO("=========================")
90
91os.remove(statfile)
92os.remove(filein)
93os.remove(fileout)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28