Logo ROOT   6.10/09
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 
13 import sys, string, os
14 from ROOT import TFile, TNtuple
15 
16 
17 ifn = os.path.expandvars("${ROOTSYS}/tutorials/pyroot/aptuple.txt")
18 ofn = 'aptuple.root'
19 
20 print 'opening file', ifn, '...'
21 infile = open( ifn, 'r' )
22 lines = infile.readlines()
23 title = lines[0]
24 labels = string.split( lines[1] )
25 
26 print 'writing file', ofn, '...'
27 outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )
28 ntuple = TNtuple( 'ntuple', title, string.join( labels, ':') )
29 
30 for line in lines[2:]:
31  words = string.split( line )
32  row = map( float, words )
33  apply( ntuple.Fill, row )
34 
35 outfile.Write()
36 
37 print 'done'
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28
decltype(auto) constexpr apply(F &&f, Tuple &&t)