2 from __future__
import print_function
4 ROOT.gROOT.SetBatch(
True)
8 from optparse
import OptionParser
9 parser = OptionParser(usage =
"usage: %prog [options] inputFile fraction outputFile",
10 version =
"%prog $Id:$")
11 (options, args) = parser.parse_args()
21 print(
"fraction must be a floating point number (e.g. 0.5)")
24 input = ROOT.TFile(args[0])
25 output = ROOT.TFile(args[2],
"RECREATE")
26 for k
in input.GetListOfKeys():
27 print(k.GetName(), k.GetClassName())
28 if k.GetClassName() ==
"TDirectoryFile":
29 print(
" processing directory ",k.GetName())
30 din = input.Get(k.GetName())
31 dout = output.mkdir(k.GetName())
32 for i
in din.GetListOfKeys():
33 if i.GetClassName() ==
"TTree":
34 src = din.Get(i.GetName())
35 newEntries =
int(src.GetEntries()*frac)
36 print(
" cropped TTree",i.GetName(),
", original entries",src.GetEntries(),
", new entries",newEntries)
37 cloned = src.CloneTree(newEntries)
38 dout.WriteTObject(cloned, i.GetName())
39 elif i.GetClassName() !=
"TDirectory":
40 dout.WriteTObject(i.ReadObj(), i.GetName())
41 print(
" copied ",i.GetClassName(),i.GetName())
S & print(S &os, JobReport::InputFile const &f)