I am using uproot to read root files in Python. My files are such that I am doing this:
ifile = uproot.open(path_to_root_file)
metadata = ifile['Metadata']
waveforms = ifile['Waveforms']
waveforms.show()
waveforms_of_event_50 = waveforms['voltages'].array()[50]
print(waveforms_of_event_50)
and I get as output
name | typename | interpretation
---------------------+--------------------------+-------------------------------
event | int32_t | AsDtype('>i4')
producer | std::string | AsStrings()
voltages | std::vector<std::vect... | AsObjects(AsVector(True, As...
[[0.00647, 0.00647, 0.00671, 0.00647, ..., 0.00769, 0.00769, 0.00647], ...]
Since the waveforms['voltages']
is an array of array of waveforms, it is heavy and, consequently, the line waveforms_of_event_50 = waveforms['voltages'].array()[50]
takes long, because it has to load all the waveforms into memory only to discard all of them but the 50th. Even more, for some of the files this is not even possible because they simply don't fit in memory. What I want to do is instead to get the i
th waveform without loading all of them into memory, which I understand is one of the things root files are good for, i.e. something like waveforms['voltages'].get_element_number(50)
. Is this possible? How?