From 61a2ed5f27026b5c65d216005de4f04264528196 Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Sun, 30 Jun 2024 22:30:06 -0700 Subject: [PATCH] Fix up how we mark fills and how we fetch prior context for variables --- func_adl_xAOD/common/ast_to_cpp_translator.py | 10 ++++++---- tests/atlas/xaod/test_first_last.py | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/func_adl_xAOD/common/ast_to_cpp_translator.py b/func_adl_xAOD/common/ast_to_cpp_translator.py index 19077b3..84f632d 100644 --- a/func_adl_xAOD/common/ast_to_cpp_translator.py +++ b/func_adl_xAOD/common/ast_to_cpp_translator.py @@ -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): @@ -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): @@ -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()) diff --git a/tests/atlas/xaod/test_first_last.py b/tests/atlas/xaod/test_first_last.py index 09f41dc..b5313e8 100644 --- a/tests/atlas/xaod/test_first_last.py +++ b/tests/atlas/xaod/test_first_last.py @@ -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" @@ -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]