Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:30

0001 # Copyright (C) 2014 Colin Bernet
0002 # https://github.com/cbernet/heppy/blob/master/LICENSE
0003 
0004 from ROOT import TFile
0005 
0006 class Events(object):
0007     '''Event list from a tree in a root file.
0008     '''
0009     def __init__(self, filename, treename, options=None):
0010         self.file = TFile(filename)
0011         if self.file.IsZombie():
0012             raise ValueError('file {fnam} does not exist'.format(fnam=filename))
0013         self.tree = self.file.Get(treename)
0014         if self.tree == None: # is None would not work
0015             raise ValueError('tree {tree} does not exist in file {fnam}'.format(
0016                 tree = treename,
0017                 fnam = filename
0018                 ))
0019 
0020     def size(self):
0021         return self.tree.GetEntries()
0022 
0023     def to(self, iEv):
0024         '''navigate to event iEv.'''
0025         self.tree.GetEntry(iEv)
0026         return self.tree
0027 
0028     def __iter__(self):
0029         return iter(self.tree)