ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mrt.py
Go to the documentation of this file.
1 """
2  Build ROOT Ntuple from other source.
3  This program reads the `aptuple.txt' file row by row, then creates
4  the Ntuple by adding row by row.
5 """
6 
7 import sys, string
8 from ROOT import TFile, TNtuple
9 
10 
11 ifn = 'aptuple.txt'
12 ofn = 'aptuple.root'
13 
14 print 'opening file', ifn, '...'
15 infile = open( 'aptuple.txt', 'r' )
16 lines = infile.readlines()
17 title = lines[0]
18 labels = string.split( lines[1] )
19 
20 print 'writing file', ofn, '...'
21 outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )
22 ntuple = TNtuple( 'ntuple', title, string.join( labels, ':') )
23 
24 for line in lines[2:]:
25  words = string.split( line )
26  row = map( float, words )
27  apply( ntuple.Fill, row )
28 
29 outfile.Write()
30 
31 print 'done'