4 ROOT.PyConfig.IgnoreCommandLineOptions =
True 8 def __init__(self, fname="", runsAndLumis={}):
16 if run
not in self.
keep:
18 self.
keep[run] += lumis
20 if len(self.
keep[run]) == 0:
25 for (l1, l2)
in self.
keep[run]:
26 if l1 <= lumi
and lumi <= l2:
33 return (run
in self.
keep)
40 tree.SetBranchStatus(
"*", 0)
41 tree.SetBranchStatus(
'run', 1)
42 tree.SetBranchStatus(
'luminosityBlock', 1)
43 filteredList = ROOT.TEntryList(
'filteredList',
'filteredList')
45 for i
in range(elist.GetN()):
46 entry = elist.GetEntry(0)
if i == 0
else elist.Next()
49 filteredList.Enter(entry)
51 for entry
in range(tree.GetEntries()):
54 filteredList.Enter(entry)
55 tree.SetBranchStatus(
"*", 1)
59 def preSkim(tree, jsonInput=None, cutstring=None, maxEntries=None, firstEntry=0):
60 if jsonInput ==
None and cutstring ==
None:
65 if type(jsonInput)
is dict:
66 jsonFilter =
JSONFilter(runsAndLumis=jsonInput)
69 cut = jsonFilter.runCut()
71 cut =
"(%s) && (%s)" % (cutstring, cut)
if cut
else cutstring
72 if maxEntries
is None:
73 maxEntries = ROOT.TVirtualTreePlayer.kMaxEntries
74 while "AltBranch$" in cut:
75 m = re.search(
r"AltBranch\$\(\s*(\w+)\s*,\s*(\w+)\s*\)", cut)
78 "Error, found AltBranch$ in cut string, but it doesn't comply with the syntax this code can support. The cut is %r" % cut)
79 cut = cut.replace(m.group(0), m.group(
80 1)
if tree.GetBranch(m.group(1))
else m.group(2))
81 tree.Draw(
'>>elist', cut,
"entrylist", maxEntries, firstEntry)
82 elist = ROOT.gDirectory.Get(
'elist')
84 elist = jsonFilter.filterEList(tree, elist)
85 return elist, jsonFilter
def filterRunLumi(self, run, lumi)
def filterEList(self, tree, elist)
def __init__(self, fname="", runsAndLumis={})
def preSkim(tree, jsonInput=None, cutstring=None, maxEntries=None, firstEntry=0)
def filterRunOnly(self, run)