Skip to content

Commit

Permalink
Fix up how we mark fills and how we fetch prior context for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwatts committed Jul 1, 2024
1 parent 675ea34 commit 61a2ed5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions func_adl_xAOD/common/ast_to_cpp_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,13 +1161,15 @@ def call_ResultTTree(self, node: ast.Call, args: List[ast.AST]):

# What we have is a sequence of the data values we want to fill. The iterator at play
# here is the scope we want to use to run our Fill() calls to the TTree.
scope_fill = v_rep_not_norm.iterator_value().scope()
iterator_scope = v_rep_not_norm.iterator_value().scope()

# Clean the data up so it is uniform and the next bit can proceed smoothly.
# If we don't have a tuple of data to log, turn it into a tuple.
seq_values = v_rep_not_norm.sequence_value()
if not isinstance(seq_values, crep.cpp_tuple):
seq_values = crep.cpp_tuple((v_rep_not_norm.sequence_value(),), scope_fill)
seq_values = crep.cpp_tuple(
(v_rep_not_norm.sequence_value(),), iterator_scope
)

# Make sure the number of items is the same as the number of columns specified.
if len(seq_values.values()) != len(column_names):
Expand Down Expand Up @@ -1209,7 +1211,7 @@ def call_ResultTTree(self, node: ast.Call, args: List[ast.AST]):
# Make sure that it happens at the proper scope, where what we are after is defined!
s_orig = self._gc.current_scope()
for e_rep, e_name in zip(seq_values.values(), var_names):
scope_fill = self.code_fill_ttree(e_rep, e_name[1], scope_fill)
scope_fill = self.code_fill_ttree(e_rep, e_name[1], iterator_scope)

# The fill statement. This should happen at the scope where the tuple was defined.
# The scope where this should be done is a bit tricky (note the update above):
Expand Down Expand Up @@ -1440,4 +1442,4 @@ def call_First(self, node: ast.AST, args: List[ast.AST]) -> Any:
else sv.copy_with_new_scope(self._gc.current_scope())
)

crep.set_rep(node, first_value, cs)
crep.set_rep(node, first_value, self._gc.current_scope())
8 changes: 3 additions & 5 deletions tests/atlas/xaod/test_first_last.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def test_First_with_dict():
assert l_pt_r is not None
assert l_eta_r is not None

assert l_pt_r[1] == l_eta_r[1]


def test_First_with_inner_loop():
"Check we can loop over tracks"
Expand Down Expand Up @@ -141,16 +139,16 @@ def test_First_with_inner_loop():

# Make sure the eta capture is inside the is first.
first_lines = find_line_numbers_with("if (is_first", lines)
assert len(first_lines) == 1
assert len(first_lines) == 2
assert lines[first_lines[0] + 1].strip() == "{"
lines_post_if = lines[first_lines[0] + 2 :] # noqa
is_first_closing = find_next_closing_bracket(lines_post_if)

eta_line = find_line_numbers_with("->eta()", lines_post_if)
eta_line = find_line_numbers_with("->pt()", lines_post_if)
assert len(eta_line) == 1
assert is_first_closing > eta_line[0]

# Make sure the lookup for the tracks occurs after the is_first test.
track_lines = find_line_numbers_with("TrackParticleContainer* result", lines)
assert len(track_lines) == 1
assert len(track_lines) == 2
assert track_lines[0] > first_lines[0]

0 comments on commit 61a2ed5

Please sign in to comment.