Logo ROOT   6.07/09
Reference Guide
Namespaces
mrt.py File Reference

Namespaces

 mrt
 

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 Ntuple by adding row by row.

0.0112590789795
5.15563011169
opening file /mnt/vdb/lsf/workspace/root-makedoc-v608/rootspi/rdoc/src/v6-08-00-patches.build/tutorials/pyroot/aptuple.txt ...
writing file aptuple.root ...
done
1 
2 import sys, string, os
3 from ROOT import TFile, TNtuple
4 
5 
6 ifn = os.path.expandvars("${ROOTSYS}/tutorials/pyroot/aptuple.txt")
7 ofn = 'aptuple.root'
8 
9 print 'opening file', ifn, '...'
10 infile = open( ifn, 'r' )
11 lines = infile.readlines()
12 title = lines[0]
13 labels = string.split( lines[1] )
14 
15 print 'writing file', ofn, '...'
16 outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )
17 ntuple = TNtuple( 'ntuple', title, string.join( labels, ':') )
18 
19 for line in lines[2:]:
20  words = string.split( line )
21  row = map( float, words )
22  apply( ntuple.Fill, row )
23 
24 outfile.Write()
25 
26 print 'done'
Author
Wim Lavrijsen

Definition in file mrt.py.