派洛特双针

2024-04-25 03:31:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建类来处理TTree:

from ROOT import *
from Exceptions import  *
import os.path

class NTupleHandler:

    def __init__(self, fileName, eventType):
        if not os.path.isfile(fileName):
            raise InputError( fileName)
        f = TFile(fileName, 'read')
        if f is None:
            raise InputError("openError"+fileName)
        dir=f.Get(eventType)
        if dir is None:
            raise InputError("directory Error"+eventType)
        tree=dir.Get('particle')
        self.tree=tree
        self.tree.GetEntriesFast()
        print

    def getEntry(self):
        return self.tree.GetEntriesFast()

但调用函数getEntry i时发生错误:

^{pr2}$

如何强迫python记住NtupleHandler.tree?在


Tags: pathfromimportselfnonetreeifis
1条回答
网友
1楼 · 发布于 2024-04-25 03:31:27

如果您想在Python环境中使用根类,那么最好使用rootpy而不是pyroot。在rootpy中,包含树的根文件已经用PyTables转换成HDF5格式。看看你想要的是不是rootpy。在

相关问题 更多 >