从 HDF5 文件填充 ROOT TTree

问题描述

我必须将 hdf5 文件转换为 ROOT TTree。 (超过100个数据集) 每个数据集有 (30000 x 2) float64 我试图分支一个表格,但最后我的树全是零...... 这是我的代码

import h5py
from ROOT import TFile,TTree,AddressOf
import numpy as np


filename="THE_file.h5"
f = h5py.File(filename,'r')

the_list_of_key=[]

for el in list(f.keys()):
    the_list_of_key.append(el)

myfile = TFile( 'convert_h5_to_root.root','RECREATE' )
t1 = TTree("t1","a simple Tree with fake data")


tmp_data =np.zeros((1),dtype="float64")
list_of_data=[tmp_data]*len( the_list_of_key)

### Here I branch the list_of_data ###
for i in range(len(the_list_of_key)):
    tmp=the_list_of_key[i]+"/C"
    t1.Branch(the_list_of_key[i],list_of_data[i],tmp)


### for 300 entries foreach dataset,I fill the branch    
for j in range(300):
    for i in range(len(the_list_of_key)):
        data=f[the_list_of_key[i]]  ###--> I can print on screen the right values
        val = data[j][1]
        list_of_data[i][0] = val
    t1.Fill()

myfile.Write()
myfile.Close()

谢谢你的帮助! 是

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...