CMS 3D CMS Logo

eventstfile.py
Go to the documentation of this file.
1 # Copyright (C) 2014 Colin Bernet
2 # https://github.com/cbernet/heppy/blob/master/LICENSE
3 
4 from ROOT import TFile
5 
6 class Events(object):
7  '''Event list from a tree in a root file.
8  '''
9  def __init__(self, filename, treename, options=None):
10  self.file = TFile(filename)
11  if self.file.IsZombie():
12  raise ValueError('file {fnam} does not exist'.format(fnam=filename))
13  self.tree = self.file.Get(treename)
14  if self.tree == None: # is None would not work
15  raise ValueError('tree {tree} does not exist in file {fnam}'.format(
16  tree = treename,
17  fnam = filename
18  ))
19 
20  def size(self):
21  return self.tree.GetEntries()
22 
23  def to(self, iEv):
24  '''navigate to event iEv.'''
25  self.tree.GetEntry(iEv)
26  return self.tree
27 
28  def __iter__(self):
29  return iter(self.tree)
def __iter__(self)
Definition: eventstfile.py:28
def to(self, iEv)
Definition: eventstfile.py:23
def __init__(self, filename, treename, options=None)
Definition: eventstfile.py:9
T * Get(Args... args)
Definition: Trend.h:122