Merge TTrees with Deduplication

Hi, I have a set of tiles with compatible TTrees that I wish to merge. My current code is very simple (PyROOT):

import ROOT

infilenames = ["foo1.root","foo2.root",...]
outfilename = "merged.root"

tc = ROOT.TChain("environment","environment")
for fn in infilenames:
    f = ROOT.TFile(fn,"READ")
    t = f.Get("environment")
    tc.Add(fn)
tc.Merge(outfilename)

I have realized that some of the input .root files actually have duplicates of entries from some of the other files. When I say duplicate I mean exactly: every branch compares “==”, but each entry has an integer time branch so comparing just the time is enough.

Is there a simple way to deduplicate the entries in the output tree? My only solution is to iterate over every entry and manually look for it in the growing output tree. This seems very inefficient and hard to code correctly.

After some tedious examination of the timestamps, I have determined that the problem is much simpler than I feared. I just needed to merge partial CONTIGUOUS bits of various TTrees in different files. I tried using TEventLists for this but I couldn’t get it to work. I ended up coding a dumb loop over all the entries in all the input files and copying branch-by-branch each entry. There has to be an easier way, but this was a one-time thing.