Skip to content
Snippets Groups Projects
Commit f1665fdb authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Merge branch 'avoid_make_data_with_FetchDataFromFile' into 'master'

use `get_hlt1_selreports` instead of `make_data_with_FetchDataFromFile`

See merge request !1042
parents df6b3df0 184a43a8
No related branches found
No related tags found
1 merge request!1042use `get_hlt1_selreports` instead of `make_data_with_FetchDataFromFile`
Pipeline #6694299 passed
###############################################################################
# (c) Copyright 2021-2023 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2021-2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -21,7 +21,6 @@ from GaudiKernel import SystemOfUnits # type: ignore[import]
from GaudiConf.LbExec import HltSourceID # type: ignore[import]
import Functors as F # type: ignore[import]
from PyConf.reading import get_odin, get_decreports, get_hlt1_selreports, get_particles, tes_root_for_tistos # type: ignore[import]
from PyConf.application import make_data_with_FetchDataFromFile # type: ignore[import]
from PyConf.dataflow import DataHandle # type: ignore[import]
from PyConf.Algorithms import Hlt1TisTosAlg, Hlt2TisTosAlg, Hlt1TrueSimEffAlg, Hlt2TrueSimEffAlg # type: ignore[import]
import DaVinciMCTools # type: ignore[import]
......@@ -132,9 +131,6 @@ def _HltMCTrueSimEff(
mcp_data: DataHandle,
dec_reports: DataHandle,
mc2IDLink: DataHandle,
sel_reports: DataHandle = make_data_with_FetchDataFromFile(
"dummy_sel_rep_location"
),
cand_locations: list[str] = ["dummy_line_name_Decision_loc"],
):
"""
......@@ -156,8 +152,6 @@ def _HltMCTrueSimEff(
dec_reports (DataHandle): TES location of DecReports.
mc2IDLink (DataHandle): TES location of linker between MC particles and MC LHCbIDs of
their tracks. Output of e.g. make_links_lhcbids_mcparticles_tracking_system()
sel_reports (DataHandle, optional): TES location of Hlt1 SelReports.
Only relevant for HLT1, so has a dummy default value.
cand_locations (list(str), optional): List of TES locations to the reconstructed candidates
of each line. Only relevant for HLT2, so has a dummy default value.
......@@ -171,7 +165,7 @@ def _HltMCTrueSimEff(
InputMCParticles=mcp_data,
DecReports=dec_reports,
MC2IDLink=mc2IDLink,
SelReports=sel_reports,
SelReports=get_hlt1_selreports(),
TriggerLines=trigger_lines,
).P2TrueSimEffTable
elif selection_type == HltSourceID.Hlt2:
......
###############################################################################
# (c) Copyright 2022-2023 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2022-2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -34,12 +34,14 @@ def reset_global_store(algorithm_store={}):
return old_algorithm_store
@pytest.fixture()
def data_handle():
def data_handle(expected_type):
"""
Make a dummy DataHandle instance to input to FunTuple_Particles or FunTuple_MCParticles.
"""
return make_data_with_FetchDataFromFile("/Event/Spruce/MyCoolDecay/Particles")
return make_data_with_FetchDataFromFile(
"/Event/Spruce/MyCoolDecay/" + expected_type.replace(":", "_"),
force_type=expected_type,
)
# Some default arguments to FunTuple_Particles or FunTuple_MCParticles
......@@ -50,10 +52,10 @@ variables = dict(A=FC.Kinematics())
# to test both FunTuple_Particles and FunTuple_MCParticles
# available in the FunTuple module
list_function_tuple_name = (
("FunTuple_Particles", "FunTupleP"),
("FunTuple_MCParticles", "FunTupleMCP"),
("FunTuple_Composites", "FunTupleComposites"),
("FunTuple_ChargedBasics", "FunTupleChgBasics"),
("FunTuple_Particles", "FunTupleP", "SharedObjectsContainer<LHCb::Particle>"),
("FunTuple_MCParticles", "FunTupleMCP", "SharedObjectsContainer<LHCb::MCParticle>"),
("FunTuple_Composites", "FunTupleComposites", "LHCb::Event::Composites"),
("FunTuple_ChargedBasics", "FunTupleChgBasics", "LHCb::Event::ChargedBasics"),
)
# make a separate list for FunTuple_Event as it expects no inputs
......@@ -74,8 +76,10 @@ def getattr_wrapper(my_module, my_func_name, **kwargs):
return getattr(my_module, my_func_name)(**kwargs)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_dummy(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_dummy(func_name, name_argument, expected_type):
"""
Check that a dummy tupling instance with no fields is not allowed and raises a RuntimeError.
"""
......@@ -90,12 +94,14 @@ def test_dummy(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_simplest(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_simplest(func_name, name_argument, expected_type):
"""
Check the simplest tupling instance where all fields are defined via the reserved name 'ALL'.
"""
......@@ -109,12 +115,14 @@ def test_simplest(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_simple(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_simple(func_name, name_argument, expected_type):
"""
Check a very simple instantiation where only the mother particle is tupled
with the Kinematics collection.
......@@ -126,7 +134,7 @@ def test_simple(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
# Trick to compare tuple.name and name_argument
......@@ -135,8 +143,10 @@ def test_simple(data_handle, func_name, name_argument):
assert tuple.properties["run_full_counter_mode"]
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_simple_with_ALL_field(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_simple_with_ALL_field(func_name, name_argument, expected_type):
"""
Check with a typical and still simple tupling instance.
"""
......@@ -152,12 +162,14 @@ def test_simple_with_ALL_field(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_with_event_variables(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_with_event_variables(func_name, name_argument, expected_type):
"""
Check that event variables passed as an optional argument are dealt with correctly.
"""
......@@ -172,7 +184,7 @@ def test_with_event_variables(data_handle, func_name, name_argument):
fields=fields,
variables=variables,
event_variables=event_variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
if name_argument == "FunTupleMCP":
......@@ -192,8 +204,10 @@ def test_with_event_variables(data_handle, func_name, name_argument):
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_with_loki_preamble(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_with_loki_preamble(func_name, name_argument, expected_type):
"""
Check of a next-to-simple instantiation where a LoKi preamble (string)
is passed as an optional argument.
......@@ -207,7 +221,7 @@ def test_with_loki_preamble(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
loki_preamble=loki_preamble,
)
......@@ -216,8 +230,10 @@ def test_with_loki_preamble(data_handle, func_name, name_argument):
assert tuple.name.endswith(name_argument, 0, len(name_argument))
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_run_full_counter_mode(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_run_full_counter_mode(func_name, name_argument, expected_type):
"""
Check that the optional argument 'run_full_counter_mode' gets set correctly.
"""
......@@ -228,15 +244,17 @@ def test_run_full_counter_mode(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
run_full_counter_mode=False,
)
assert not tuple.properties["run_full_counter_mode"]
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_ALL_not_allowed_in_field_names(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_ALL_not_allowed_in_field_names(func_name, name_argument, expected_type):
"""
Check that using the reserved name 'ALL' as a key for 'fields' raises a ValueError.
"""
......@@ -248,12 +266,14 @@ def test_ALL_not_allowed_in_field_names(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=dict(ALL="A -> B C"), # "ALL" is not allowed since special
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_more_than_one_caret_in_field(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_more_than_one_caret_in_field(func_name, name_argument, expected_type):
"""
Check that using more than one caret symbol in a field raises a ``SyntaxError``.
"""
......@@ -265,12 +285,14 @@ def test_more_than_one_caret_in_field(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=dict(A="A -> B ^C ^D"),
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_fields_is_dict(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_fields_is_dict(func_name, name_argument, expected_type):
"""
A TypeError is raised if the 'fields' argument is not a dict.
"""
......@@ -282,12 +304,14 @@ def test_fields_is_dict(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields="A -> B C", # should be a dict
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_field_name_unused(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_field_name_unused(func_name, name_argument, expected_type):
"""
A field, 'C', is defined with no corresponding variables to tuple.
The framework removes that unused field automatically.
......@@ -302,7 +326,7 @@ def test_field_name_unused(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
assert tuple.properties["decay_descriptors"] == ["A -> ^B C"]
......@@ -313,8 +337,10 @@ def test_field_name_unused(data_handle, func_name, name_argument):
assert len(tuple.properties["thor_functors"][0]) == 7
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_field_name_unmatched_to_variable_keys(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_field_name_unmatched_to_variable_keys(func_name, name_argument, expected_type):
"""
All field names should match the particles to be tupled.
In this case the field name 'NotInVariablesKey' does not correspond to any particle
......@@ -331,12 +357,14 @@ def test_field_name_unmatched_to_variable_keys(data_handle, func_name, name_argu
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_variables_is_dict(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_is_dict(func_name, name_argument, expected_type):
"""
A TypeError is raised if the 'variables' argument is not a dict.
"""
......@@ -348,12 +376,14 @@ def test_variables_is_dict(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=FC.Kinematics(), # should be a dict
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_variables_key_ALL(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_key_ALL(func_name, name_argument, expected_type):
"""
Check that the reserved field name 'ALL' is accepted as a key to 'variables'.
"""
......@@ -366,12 +396,14 @@ def test_variables_key_ALL(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_variables_all_type_FunctorCollection(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_all_type_FunctorCollection(func_name, name_argument, expected_type):
"""
Check that the 'variables' (values) are all of type FunctorCollection.
"""
......@@ -389,13 +421,15 @@ def test_variables_all_type_FunctorCollection(data_handle, func_name, name_argum
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_key_ALL_type_FunctorCollection(
data_handle, func_name, name_argument
func_name, name_argument, expected_type
):
"""
Check complementary to the above one for the reserved name 'ALL':
......@@ -411,12 +445,14 @@ def test_variables_key_ALL_type_FunctorCollection(
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_variables_arrayindex(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_arrayindex(func_name, name_argument, expected_type):
"""
Test the checking modules of FunTuple for what concerns array variables,
see the module `common_util.py` and in particular the `conduct_checks_and_transform`
......@@ -445,12 +481,14 @@ def test_variables_arrayindex(data_handle, func_name, name_argument):
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_variables_arrayindex_ValueError_1(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_arrayindex_ValueError_1(func_name, name_argument, expected_type):
"""
Test the checking modules of FunTuple for what concerns array variables,
see the module `common_util.py` and in particular the `conduct_checks_and_transform`
......@@ -481,12 +519,14 @@ def test_variables_arrayindex_ValueError_1(data_handle, func_name, name_argument
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
@pytest.mark.parametrize("func_name,name_argument", list_function_tuple_name)
def test_variables_arrayindex_ValueError_2(data_handle, func_name, name_argument):
@pytest.mark.parametrize(
"func_name,name_argument,expected_type", list_function_tuple_name
)
def test_variables_arrayindex_ValueError_2(func_name, name_argument, expected_type):
"""
Test the checking modules of FunTuple for what concerns array variables,
see the module `common_util.py` and in particular the `conduct_checks_and_transform`
......@@ -517,7 +557,7 @@ def test_variables_arrayindex_ValueError_2(data_handle, func_name, name_argument
tuple_name=name_argument,
fields=fields,
variables=variables,
inputs=data_handle,
inputs=data_handle(expected_type),
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment