17 from 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(ROOT.gROOT.GetTutorialsDir(),
'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])
71 if __name__ ==
'__main__':
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
A TTree object has a header with a name and a title.