Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle zero-events nanoAOD files [13.0.X] #43536

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions PhysicsTools/NanoAOD/scripts/haddnano.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
fileHandles = []
goFast = True
for fn in files:
print("Adding file" + str(fn))
print("Adding file", str(fn))
fileHandles.append(ROOT.TFile.Open(fn))
if fileHandles[-1].GetCompressionSettings() != fileHandles[0].GetCompressionSettings():
goFast = False
Expand All @@ -44,7 +44,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):

for e in fileHandles[0].GetListOfKeys():
name = e.GetName()
print("Merging" + str(name))
print("Merging", str(name))
obj = e.ReadObj()
cl = ROOT.TClass.GetClass(e.GetClassName())
inputs = ROOT.TList()
Expand All @@ -53,15 +53,26 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
obj = obj.CloneTree(-1, "fast" if goFast else "")
branchNames = set([x.GetName() for x in obj.GetListOfBranches()])
for fh in fileHandles[1:]:
if isTree and obj.GetName() == 'Events' and obj.GetEntries() == 0 :
# Zero-events first file. Skip to avoid messing up branches.
print(" 'Events' tree contsins no events; skipping")
obj = fh.GetListOfKeys().FindObject(name).ReadObj()
obj = obj.CloneTree(-1, "fast" if goFast else "")
branchNames = set([x.GetName() for x in obj.GetListOfBranches()])
continue
otherObj = fh.GetListOfKeys().FindObject(name).ReadObj()
if isTree and obj.GetName() == 'Events' and otherObj.GetEntries() == 0 :
# Zero-events file; skip
print(" 'Events' tree contains no events; skipping")
continue
inputs.Add(otherObj)
if isTree and obj.GetName() == 'Events':
otherObj.SetAutoFlush(0)
otherBranches = set([x.GetName()
for x in otherObj.GetListOfBranches()])
missingBranches = list(branchNames - otherBranches)
additionalBranches = list(otherBranches - branchNames)
print("missing: " + str(missingBranches) + "\n Additional:" + str(additionalBranches))
print("missing: " + str(missingBranches) + "\n Additional: " + str(additionalBranches))
for br in missingBranches:
# fill "Other"
zeroFill(otherObj, br, obj.GetListOfBranches().FindObject(br))
Expand All @@ -76,7 +87,7 @@ def zeroFill(tree, brName, brObj, allowNonBool=False):
for x in otherObj.GetListOfBranches()])
missingBranches = list(branchNames - otherBranches)
additionalBranches = list(otherBranches - branchNames)
print("missing: " + str(missingBranches) + "\n Additional:" + str(additionalBranches))
print("missing: " + str(missingBranches) + "\n Additional: " + str(additionalBranches))
for br in missingBranches:
# fill "Other"
zeroFill(otherObj, br, obj.GetListOfBranches(
Expand Down