example of macro to read data from an ascii file and create a root file with a Tree.
NOTE: comparing the results of this macro with those of staff.C, you'll notice that the resultant file is a couple of bytes smaller, because the code below strips all white-spaces, whereas the .C version does not.
import os
import ROOT
from ROOT import TFile, TTree, addressof, gROOT
"""struct staff_t {
Int_t Category;
UInt_t Flag;
Int_t Age;
Int_t Service;
Int_t Children;
Int_t Grade;
Int_t Step;
Int_t Hrweek;
Int_t Cost;
Char_t Division[4];
Char_t Nation[3];
};"""
)
def staff():
f =
TFile(
"staff.root",
"RECREATE")
tree =
TTree(
"T",
"staff data from ascii file")
tree.Branch(
"staff", staff,
"Category/I:Flag:Age:Service:Children:Grade:Step:Hrweek:Cost")
with open(fname) as file:
if __name__ == "__main__":
staff()
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
A TTree represents a columnar dataset.
- Author
- Wim Lavrijsen
Definition in file staff.py.