17from ROOT
import TFile, TTree, gROOT, addressof
38 staff = ROOT.staff_t()
43 f =
TFile(
'staff.root',
'RECREATE' )
44 tree =
TTree(
'T',
'staff data from ascii file' )
45 tree.Branch(
'staff', staff,
'Category/I:Flag:Age:Service:Children:Grade:Step:Hrweek:Cost' )
46 tree.Branch(
'Divisions', addressof( staff,
'Division' ),
'Division/C' )
47 tree.Branch(
'Nation', addressof( staff,
'Nation' ),
'Nation/C' )
50 fname = os.path.join(str(ROOT.gROOT.GetTutorialDir()),
'tree',
'cernstaff.dat')
51 for line
in open(fname).readlines():
52 t = list(filter(
lambda x: x, re.split(
'\s+', line ) ) )
53 staff.Category =
int(t[0])
54 staff.Flag =
int(t[1])
56 staff.Service =
int(t[3])
57 staff.Children =
int(t[4])
58 staff.Grade =
int(t[5])
59 staff.Step =
int(t[6])
60 staff.Hrweek =
int(t[7])
61 staff.Cost =
int(t[8])
71if __name__ ==
'__main__':
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
A TTree represents a columnar dataset.