Skip to content
Snippets Groups Projects
Commit 8831b35e authored by Nikolai.Hartmann's avatar Nikolai.Hartmann
Browse files

Prepend original tree name to friend tree name in outputfile for addFriend.py

parent bd903149
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,10 @@ args = parser.parse_args()
outfile = ROOT.TFile.Open(args.outfile, "UPDATE")
infile = ROOT.TFile.Open(args.infile)
friend_name = args.outtree+"_friend_"+args.intree
for k in outfile.GetListOfKeys():
if k.GetName() == args.intree:
if k.GetName() == friend_name:
raise ValueError("Tree with name {} already exists in outputfile".format(args.intree))
outfile.cd()
......@@ -28,7 +30,7 @@ if not outtree:
if outtree.GetListOfFriends():
for k in outtree.GetListOfFriends():
if k.GetName() == args.intree:
if k.GetName() == friend_name:
raise ValueError("Tree with name {} is already friend of {}".format(args.intree, args.outtree))
infile.cd()
......@@ -39,10 +41,11 @@ if not intree:
# Add friend and write friend tree and original tree to outfile
outfile.cd()
outtree.AddFriend(intree)
outtree.Write(outtree.GetName())
outfile.cd()
clonetree = intree.CloneTree(-1, "fast")
clonetree.Write(intree.GetName())
clonetree.SetName(friend_name)
clonetree.SetTitle(friend_name)
clonetree.Write(friend_name)
outtree.AddFriend(clonetree)
outtree.Write(outtree.GetName())
infile.Close()
outfile.Close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment