10 def iterate(thisdir: ROOT.TDirectory, targetdir: ROOT.TDirectory, prefix: str, regex: typing.Pattern,
12 """Recurse to copy all objects except those of regex"""
13 for k
in thisdir.GetListOfKeys():
14 if k.GetClassName().startswith(
'TDirectory'):
15 targetsubdirname = thisdir.GetPath()[len(prefix):] +
'/' + k.GetName()
16 if regex.fullmatch(targetsubdirname):
17 print(
'Now skipping', targetsubdirname)
19 targetsubdir = targetdir.mkdir(k.GetName())
20 iterate(o := k.ReadObj(), targetsubdir, prefix, regex, excludeTrees)
21 ROOT.SetOwnership(o,
True)
23 if k.GetClassName().startswith(
'TTree'):
24 if not args.excludeTrees
or k.GetName() ==
'metadata':
25 targetdir.WriteObject(o := k.ReadObj().CloneTree(), k.GetName())
26 ROOT.SetOwnership(o,
True)
28 targetdir.WriteObject(o := k.ReadObj(), k.GetName())
29 ROOT.SetOwnership(o,
True)