python - pyroot Ntuple 处理程序

标签 python tree root-framework pyroot

我想创建类来处理 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 时发生错误:

Error
Traceback (most recent call last):
  File "/home/ja/PycharmProjects/studyChi2/python/NTupleHandlerTester.py", line 19, in testHandlerShouldReturnNoEvents
    self.assertLess(handler.getEntry(),10)
  File "/home/ja/PycharmProjects/studyChi2/python/NTupleHandler.py", line 23, in getEntry
    return self.tree.GetEntriesFast()
AttributeError: 'PyROOT_NoneType' object has no attribute 'GetEntriesFast'

如何强制 python 记住 NtupleHandler.tree 的类型?

最佳答案

如果你想在Python环境中使用ROOT类,你最好使用rootpy而不是pyroot。在 rootpy 中,已经使用 PyTables 将包含树的 ROOT 文件转换为 HDF5 格式。看看 rootpy 中是否有你想要的内容。

关于python - pyroot Ntuple 处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23598189/

相关文章:

javascript - web2py:可以使用单个 'submit' 按钮提交多个表单吗?

python - Pandas :将 df 写入文本文件 - 将 df 向右缩进 5 个空格

mysql - 如何设置树(邻接表)结构数据库的用户权限?

二叉树尾递归的Scala和

c++ - 编译几个源文件(主文件和头文件)并在 ROOT CINT 中链接它们?

c++ - cmake .exe 和终端命令之间的 ROOT 结果不匹配

python - memcache 和 python 字典的区别

python - 名称 'settings' 未定义

c - AVL 树实现的新手

c++ - 在 ROOT 中迭代绘制 TEllipse