Skip to content

Commit

Permalink
fixed branch slimming
Browse files Browse the repository at this point in the history
  • Loading branch information
zbilodea committed Jul 3, 2024
1 parent 1ca6704 commit d169277
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 4 additions & 11 deletions src/hepconvert/copy_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,12 @@ def copy_root(
)
}
)
for key in group:
if key in kb:
del chunk[key]
for key in group:
if key in kb:
del chunk[key]
if first:
first = False
if drop_branches:
branch_types = {
name: array.type
for name, array in chunk.items()
if name not in drop_branches
}
else:
branch_types = {name: array.type for name, array in chunk.items()}
branch_types = {name: array.type for name, array in chunk.items()}
of.mktree(
tree.name,
branch_types,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_copy_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ def test_keep_branches(tmp_path):
hepconvert.copy_root(
Path(tmp_path) / "drop_branches.root",
skhep_testdata.data_path("uproot-HZZ.root"),
drop_branches=["Jet_*", "MClepton_*"],
keep_branches="MClepton_*",
counter_name=lambda counted: "N" + counted,
force=True,
)
original = uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))

file = uproot.open(Path(tmp_path) / "drop_branches.root")
file["events"].show()
for key in original["events"].keys():
if key.startswith("MClepton_"):
assert key in file["events"].keys()
Expand All @@ -81,6 +82,7 @@ def test_keep_branches(tmp_path):
)
else:
assert key not in file["events"].keys()
file.close()


def test_hepdata_example(tmp_path):
Expand Down

0 comments on commit d169277

Please sign in to comment.