uproot5 icon indicating copy to clipboard operation
uproot5 copied to clipboard

Usage of options like max_num_elements with uproot.open()

Open dudarboh opened this issue 8 months ago • 1 comments

Maybe it is just me, but I don't understand how to use the max_num_elements argument with uproot.open()

I have tried a few options on my ROOT file and none of them work:

import uproot

with uproot.open("filename.root:treename", options={"max_num_elements":1000}) as events:
    data = events.arrays(["mcTotal"])
    print(len(data["mcTotal"]))

with uproot.open("filename.root:treename", max_num_elements=1000) as events:
    data = events.arrays(["mcTotal"])
    print(len(data["mcTotal"]))

I assume it is not a bug, but rather I am missing something very simple. If that is the case, I think a little example in the docs wouldn't hurt. Or is it a bug?

dudarboh avatar Apr 28 '25 14:04 dudarboh

Hi @dudarboh, thanks for bringing this up! This is definitely something that could use some better documentation. max_num_elements is used when opening a file with xrootd to figure out how to split things up (as far as I understand).

What you want is the entry_stop argument of the arrays function.

with uproot.open("filename.root:treename") as events:
    data = events.arrays(["mcTotal"], entry_stop=1000)
    print(len(data["mcTotal"]))

ariostas avatar Apr 28 '25 14:04 ariostas