#!/usr/bin/python

import ROOT
import numpy as np

f = ROOT.TFile("test.root", "recreate")

t1 = ROOT.TTree("t1", "t1")
id1 = np.array([0], dtype=np.int32)
t1.Branch("id", id1, "id/I")
t1.Fill()
t1.Write()

t2 = ROOT.TTree("t2", "t2")
id2 = np.array([0], dtype=np.int32)
t2.Branch("id", id1, "id/I")
t2.Fill()
#t2.AddFriend(t1)
t2.Write()

id1[0]=1
t1.Fill()
t1.Write()

id2[0]=1
t2.Fill()
#t2.RemoveFriend(t1)
t2.AddFriend(t1)
t2.Write()

f.Close()

f = ROOT.TFile("test.root", "read")
t1 = f.t1
t2 = f.t2
for i in range(t2.GetEntries()):
	t2.GetEntry(i)
	print(t2.id, t1.id)

print("Closing")
f.Close()
