我想创建类来处理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发生了错误:
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的类型?
发布于 2014-05-17 13:19:16
如果您想在Python环境中使用根类,最好使用rootpy而不是pyroot。在rootpy中,包含树的根文件到HDF5格式的PyTables转换已经完成。看看你想要的是不是根。
https://stackoverflow.com/questions/23598189
复制相似问题