我想创建类来处理 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 的类型?