Logo ROOT   6.16/01
Reference Guide
Namespaces
mrt.py File Reference

Namespaces

namespace  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.

opening file /home/sftnight/build/workspace/root-makedoc-v616/rootspi/rdoc/src/v6-16-00-patches.build/tutorials/pyroot/aptuple.txt ...
writing file aptuple.root ...
done
import sys, string, os
from ROOT import TFile, TNtuple
ifn = os.path.expandvars("${ROOTSYS}/tutorials/pyroot/aptuple.txt")
ofn = 'aptuple.root'
print 'opening file', ifn, '...'
infile = open( ifn, 'r' )
lines = infile.readlines()
title = lines[0]
labels = string.split( lines[1] )
print 'writing file', ofn, '...'
outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' )
ntuple = TNtuple( 'ntuple', title, string.join( labels, ':') )
for line in lines[2:]:
words = string.split( line )
row = map( float, words )
apply( ntuple.Fill, row )
outfile.Write()
print '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
constexpr decltype(auto) apply(F &&f, Tuple &&t)
Author
Wim Lavrijsen

Definition in file mrt.py.