def __iter__(self):
        """
        Iterator over the entries in the Tree.
        """
        if not self._buffer:
            self.create_buffer()
        if self.read_branches_on_demand:
            self._buffer.set_tree(self)
            # drop all branches from the cache
            self.DropBranchFromCache('*')
            for attr in self._always_read:
                try:
                    branch = self._branch_cache[attr]
                except KeyError:  # one-time hit
                    branch = self.GetBranch(attr)
                    if not branch:
                        raise AttributeError(
                            "branch `{0}` specified in "
                            "`always_read` does not exist".format(attr))
                    self._branch_cache[attr] = branch
                # add branches that we should always read to cache
                self.AddBranchToCache(branch)

            for i in range(self.GetEntries()):
                # Only increment current entry.
                # getattr on a branch will then GetEntry on only that branch
                # see ``TreeBuffer.get_with_read_if_cached``.
                self._current_entry = i
                self.LoadTree(i)
                for attr in self._always_read:
                    # Always read branched in ``self._always_read`` since
                    # these branches may never be getattr'd but the TreeBuffer
                    # should always be updated to reflect their current values.
                    # This is useful if you are iterating over an input tree
                    # and writing to an output tree that shares the same
                    # TreeBuffer but you don't getattr on all branches of the
                    # input tree in the logic that determines which entries
                    # to keep.
                    self._branch_cache[attr].GetEntry(i)
                self._buffer._entry.set(i)
                yield self._buffer
                self._buffer.next_entry()
                self._buffer.reset_collections()
        else:
            for i in range(self.GetEntries()):
                # Read all activated branches (can be slow!).
                super(BaseTree, self).GetEntry(i)
                self._buffer._entry.set(i)
                yield self._buffer
                self._buffer.reset_collections()
def __iter__ ( self ) : if not self . _buffer : self . create_buffer ( ) if self . read_branches_on_demand : self . _buffer . set_tree ( self ) self . DropBranchFromCache ( '*' ) for attr in self . _always_read : try : branch = self . _branch_cache [ attr ] except KeyError : branch = self . GetBranch ( attr ) if not branch : raise AttributeError ( "branch `{0}` specified in " "`always_read` does not exist" . format ( attr ) ) self . _branch_cache [ attr ] = branch self . AddBranchToCache ( branch ) for i in range ( self . GetEntries ( ) ) : self . _current_entry = i self . LoadTree ( i ) for attr in self . _always_read : self . _branch_cache [ attr ] . GetEntry ( i ) self . _buffer . _entry . set ( i ) yield self . _buffer self . _buffer . next_entry ( ) self . _buffer . reset_collections ( ) else : for i in range ( self . GetEntries ( ) ) : super ( BaseTree , self ) . GetEntry ( i ) self . _buffer . _entry . set ( i ) yield self . _buffer self . _buffer . reset_collections ( )
Iterator over the entries in the Tree.