Hello,
I wanted to create a tree with vectors in which I can save different values and the time I get these. To keep it simple i tried this code to create my file with the values.
file = ROOT.TFile.Open(name,“create”)
tree = ROOT.TTree(“tree”, “tree”)
pv1 = ROOT.vector(‘float’)(0)
tree.Branch(“pv1”, pv1)
…
tree.Fill()
file.Write()
I’m resizing my vectors while running in order to save the new values.
Now I’m trying to load those vectors again in order to print just a single random value but dunno how to do this. I tried :
file = ROOT.TFile(name,“READ”)
tree = file.Get(‘tree’)
pv1 = tree.Branch(“pv1”)
print(pv1[0])
but I’m getting the following error and I’ve the feeling there should be a better way to do this.
TypeError: ‘int’ object is not subscriptable
Would appreciate any kind of help or new input regarding my problem.
Henry
ROOT Version: 6.22.06 Platform: Ubuntu 20.04 Compiler: Not Provided
This is working but it seems like my Values are not getting saved on my file.
I’m using this code to save them at the moment to try out everything I wanna use later.
def load():
file = ROOT.TFile.Open(name, "recreate")
tree = ROOT.TTree("new","new")
pv1 = np.empty(1000, "float64")
pv2 = np.empty(1000,"float64")
pv3 = np.empty(1000,"float64")
time = np.empty(1000,"float64")
tree.Branch("time",time,"time/F")
tree.Branch("pv1",pv1,"pv1/F")
tree.Branch("pv2",pv2,"pv2/F")
tree.Branch("pv3",pv3,"pv3/F")
return file,pv1,pv2,pv3,time,tree
def save():
tree.Fill()
file.Write()
while i < n:
if i == 0:
file,pv1,pv2,pv3,time, tree = load()
pv1[i]=1
pv2[i]=2
pv3[i] = 3
time[i] = 0
i=i+1
save()
But if I open my file again the values aren’t saved. Would you mind taking a quick look at this code? Maybe you are able to see my fault.