Pyroot:: getting entry index when looping over a tree

Hi! Is there a way to get the index of the entry when doing: for e in my_tree: ?
just to prevent rdf comments: i cannot used rdf, and also Foreach seems to be not usable in python.
Thank you!

for idx, e in enumerate(my_tree)?

It might not be relevant, but note that the RDF answers to these kind of questions are due to the fact that looping in Python like this is slow. Depending on your usecase you might want to export the whole dataset (or relevant entries and branches in it) as e.g. numpy arrays and then you can operate on those arrays more efficiently.


oh, thanks a lot!! i did not compile that if e in my_tree works then my_tree is a normal iterable :slight_smile:
so, my restrictions are that:

  1. i cannot create a chain/chains as i need to use an in tree index that resets for each new file
  2. i need to group entries by the value of a branch (for which i did not get a guarantee that is strictly continuous) and then loop over these groups adn access the actual entries from the ttree

thanks a lot for the idea of numpy, i will try it out!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.