Retrieving value from TVector in uproot

Hi,

I’m saving a value to a Rootfile as a TVector Object. Problem is I do not know how to retrieve the stored value. I also use uproot to read and write to files.

import ROOT
import uproot

file = uproot.recreate('myfile.root')

valueToStore = 100
vec = ROOT.TVector(valueToStore)

#Writing to rootfile
file['myvector'] = vec

file.close()

Trying to retrieve the value:

file = uproot.open('myfile.root')

value = file.get('myvector')

This prints:

<Unknown TVectorT<float> at 0x7f1037383f70>

How do I get the value from this? Appreciate the help!

Hi @Tim_Buktu ,

uproot is not maintained by the ROOT team, so I am not sure we can help here. However you can write and read TVectors to ROOT files with ROOT itself, which should work fine:

import ROOT
f = ROOT.TFile.Open("myfile.root", "recreate")
vec = ROOT.TVector(100)
f.WriteObject(vec, "vec")
f.Close()

and then

f = ROOT.TFile.Open("myfile.root")
vec = f.vec

Cheers,
Enrico

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