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