Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
csv2tntuple.py File Reference
Variables  csv2tntuple.ifn = os.path.join(str(TROOT.GetTutorialDir()), 'io', 'tree', 'aptuple.txt')  csv2tntuple.infile = open( ifn, 'r' )  csv2tntuple.labels = lines[1].split()  csv2tntuple.lines = infile.readlines()  csv2tntuple.ntuple = TNtuple( 'ntuple', title, ':'.join( labels ) ) str csv2tntuple.ofn = 'aptuple.root'  csv2tntuple.outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )  csv2tntuple.row = map( float, words )  csv2tntuple.title = lines[0]  csv2tntuple.words = line.split()

Detailed Description

View in nbviewer Open in SWAN
Build ROOT Ntuple from other source.

This program reads the `aptuple.txt' file row by row, then creates the TNtuple by adding row by row.

opening file /usr/share/root/tutorials/io/tree/aptuple.txt ...
writing file aptuple.root ...
done
import sys, os
from ROOT import TFile, TNtuple, TROOT
ifn = os.path.join(str(TROOT.GetTutorialDir()), 'io', 'tree', 'aptuple.txt')
ofn = 'aptuple.root'
print('opening file %s ...' % ifn)
infile = open( ifn, 'r' )
lines = infile.readlines()
title = lines[0]
labels = lines[1].split()
print('writing file %s ...' % ofn)
outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )
ntuple = TNtuple( 'ntuple', title, ':'.join( labels ) )
for line in lines[2:]:
words = line.split()
row = map( float, words )
ntuple.Fill(*row)
outfile.Write()
print('done')
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition TROOT.cxx:3444
STL class.
Author
Wim Lavrijsen

Definition in file csv2tntuple.py.