我想创建一个类来处理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的类型?
答案 0 :(得分:1)
如果你想在Python环境中使用ROOT类,你最好使用rootpy而不是pyroot。在rootpy中,已经完成了使用PyTables将包含树的ROOT文件转换为HDF5格式。看一看,看看你想要的是rootpy。