summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-11-08 14:45:34 -0500
committertlatorre <tlatorre@uchicago.edu>2021-05-09 08:42:38 -0700
commit0e2fe795cd013e7e379123f3f7f02c3f5b92d182 (patch)
treea4ec7a3e16caa19a021d7500b91cdcffffdaf777
parentaa8bdebe44b2834cdbd45b5336585dc378d0bf48 (diff)
downloadchroma-0e2fe795cd013e7e379123f3f7f02c3f5b92d182.tar.gz
chroma-0e2fe795cd013e7e379123f3f7f02c3f5b92d182.tar.bz2
chroma-0e2fe795cd013e7e379123f3f7f02c3f5b92d182.zip
Make chroma.io.root.RootReader follow the Python iterator protocol.
Now you can do: reader = RootReader('file.root') for ev in reader: # Do stuff
-rw-r--r--chroma/io/root.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/chroma/io/root.py b/chroma/io/root.py
index d95b896..20c20e2 100644
--- a/chroma/io/root.py
+++ b/chroma/io/root.py
@@ -115,6 +115,11 @@ class RootReader(object):
'''Returns number of events in this file.'''
return self.T.GetEntries()
+ def __iter__(self):
+ for i in xrange(self.T.GetEntries()):
+ self.T.GetEntry(i)
+ yield root_event_to_python_event(self.T.ev)
+
def next(self):
'''Return the next event in the file. Raises StopIteration
when you get to the end.'''
@@ -138,7 +143,7 @@ class RootReader(object):
def current(self):
'''Return the current event in the file.'''
- self.T.GetEntry(self.i) # just in case?
+ self.T.GetEntry(self.i) # in case we were iterated over elsewhere
return root_event_to_python_event(self.T.ev)
def jump_to(self, index):