Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: dc56e8a9db
Fetching contributors…

Cannot retrieve contributors at this time

executable file 42 lines (36 sloc) 1.193 kB
#!/usr/bin/env python
# This script converts all TTrees in a ROOT file into HDF5 format.
import sys
import os
import traceback
import tables
from rootpy.io import open as ropen
from rootpy.root2tables import convert
def main():
if len(sys.argv) != 2:
sys.exit("You must specify exactly one argument (the filename)")
inputName = sys.argv[1]
if not inputName.endswith(".root"):
sys.exit("Input file does not have a .root extension")
outputName = inputName.replace(".root",".h5")
try:
rootFile = ropen(inputName)
except:
sys.exit("Could not open %s" % inputName)
try:
filters = tables.Filters(complib='blosc', complevel=5)
hd5File = tables.openFile(filename=outputName, mode="w", title="Data",
filters=filters)
except IOError:
sys.exit("Could not create %s" % outputName)
try:
convert(rootFile, hd5File, stream=sys.stdout)
except KeyboardInterrupt:
print
print "Caught Ctrl-c ... cleaning up"
hd5File.close()
os.unlink(outputName)
finally:
hd5File.close()
hd5File.close()
if __name__=="__main__": main()
Jump to Line
Something went wrong with that request. Please try again.