Skip to content

How to measure size (in bytes) of a column read from a ROOT file? #1081

Answered by jpivarski
kondratyevd asked this question in Q&A
Discussion options

You must be logged in to vote

After opening the file and selecting the TBranch like this:

file = uproot.open("PATH/TO/FILE.root")
tree = file["TREE_NAME"]
branch = tree["BRANCH_NAME"]

(replacing everything in UPPERCASE), you can get the compressed size on disk with branch.compressed_bytes, the uncompressed size with branch.uncompressed_bytes, and you can read the data into an array with array = branch.array() and then look at the array's number of bytes with array.nbytes.

If you pass library="np" to the array function, it will be a NumPy array, for which nbytes counts the size of the single buffer in memory only (so if it's not numerical data and it gets materialized as Python objects in an array with dtype=object, the

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by kondratyevd
Comment options

You must be logged in to vote
1 reply
@jpivarski
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants