Logo ROOT   6.18/05
Reference Guide
mrt.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_pyroot
3## \notebook -nodraw
4## Build ROOT Ntuple from other source.
5## This program reads the `aptuple.txt' file row by row, then creates
6## the Ntuple by adding row by row.
7##
8## \macro_output
9## \macro_code
10##
11## \author Wim Lavrijsen
12
13import sys, string, os
14from ROOT import TFile, TNtuple
15
16
17ifn = os.path.expandvars("${ROOTSYS}/tutorials/pyroot/aptuple.txt")
18ofn = 'aptuple.root'
19
20print 'opening file', ifn, '...'
21infile = open( ifn, 'r' )
22lines = infile.readlines()
23title = lines[0]
24labels = string.split( lines[1] )
25
26print 'writing file', ofn, '...'
27outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )
28ntuple = TNtuple( 'ntuple', title, string.join( labels, ':') )
29
30for line in lines[2:]:
31 words = string.split( line )
32 row = map( float, words )
33 apply( ntuple.Fill, row )
34
35outfile.Write()
36
37print 'done'
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28