1 from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel
import Event
2 from PhysicsTools.NanoAODTools.postprocessing.framework.treeReaderArrayTools
import clearExtraBranches
12 def beginJob(self, histFile=None, histDirName=None):
13 if histFile !=
None and histDirName !=
None:
15 prevdir = ROOT.gDirectory
23 if hasattr(self,
'objs')
and self.
objs !=
None:
24 prevdir = ROOT.gDirectory
30 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
33 def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
37 """process event, return True (go to next module) or False (fail, go to next event)""" 41 setattr(self, obj.GetName(), obj)
42 self.objs.
append(getattr(self, obj.GetName()))
46 for iname, name
in enumerate(names):
47 setattr(self, obj.GetName() +
'_' + name,
48 obj.Clone(obj.GetName() +
'_' + name))
49 objlist.append(getattr(self, obj.GetName() +
'_' + name))
50 self.
objs.
append(getattr(self, obj.GetName() +
'_' + name))
51 setattr(self, obj.GetName(), objlist)
55 modules, inputFile, outputFile, inputTree, wrappedOutputTree,
56 maxEvents=-1, eventRange=None, progress=(10000, sys.stdout),
60 m.beginFile(inputFile, outputFile, inputTree, wrappedOutputTree)
66 entries = inputTree.entries
68 entries = len(eventRange)
70 entries =
min(entries, maxEvents)
72 for ie, i
in enumerate(
range(entries)
if eventRange ==
None else eventRange):
73 if maxEvents > 0
and ie >= maxEvents:
75 e = Event(inputTree, i)
85 if (ret
or not filterOutput)
and wrappedOutputTree !=
None:
86 wrappedOutputTree.fill()
88 if ie > 0
and ie % progress[0] == 0:
90 progress[1].
write(
"Processed %8d/%8d entries, %5.2f%% (elapsed time %7.1fs, curr speed %8.3f kHz, avg speed %8.3f kHz), accepted %8d/%8d events (%5.2f%%)\n" % (
91 ie, entries, ie /
float(0.01 * entries),
92 t1 - t0, (progress[0] / 1000.) / (
max(t1 - tlast, 1e-9)),
93 ie / 1000. / (
max(t1 - t0, 1e-9)),
94 acceptedEvents, doneEvents,
95 acceptedEvents / (0.01 * doneEvents)))
98 m.endFile(inputFile, outputFile, inputTree, wrappedOutputTree)
99 return (doneEvents, acceptedEvents, time.time() - t0)
def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree)
def addObjectList(self, names, obj)
def eventLoop(modules, inputFile, outputFile, inputTree, wrappedOutputTree, maxEvents=-1, eventRange=None, progress=(10000, sys.stdout), filterOutput=True)
def beginJob(self, histFile=None, histDirName=None)
def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree)