【问题标题】:pyroot Ntuple handlerpyroot Ntuple 处理程序
【发布时间】:2014-06-29 04:12:52
【问题描述】:

我想创建类来处理 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 tree root-framework pyroot


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      • 2023-02-21
      • 2021-05-30
      • 2019-09-16
      • 1970-01-01
      相关资源
      最近更新 更多