From fe202e59c0d506d1c6e915bb3e2a7b5b13b8e7f6 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Fri, 17 May 2024 15:53:24 +0200 Subject: [PATCH 1/2] Fix param type determination on macOS --- python/podio/frame.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/podio/frame.py b/python/podio/frame.py index faf886e35..cdbfe65c9 100644 --- a/python/podio/frame.py +++ b/python/podio/frame.py @@ -53,7 +53,18 @@ def _determine_cpp_type(idx_and_type): if _FRAME_HEADER_AVAILABLE: - SUPPORTED_PARAMETER_TYPES = _determine_supported_parameter_types() + try: + SUPPORTED_PARAMETER_TYPES = _determine_supported_parameter_types() + except AttributeError: + # On macOS there is an issue that makes the template machinery not work + # so we just hard code the map here in case we hit that issue. See + # https://github.com/root-project/root/issues/14232 + SUPPORTED_PARAMETER_TYPES = ( + ("int", "int"), + ("float", "float"), + ("std::string", "str"), + ("double", "float"), + ) def _get_cpp_types(type_str): From 1a2f6d9a21cfc20da427e261e5385a5dd8115527 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 3 Jun 2024 14:57:17 +0200 Subject: [PATCH 2/2] Completely remove dynamic determination of supported types --- python/podio/frame.py | 65 +++++++++---------------------------------- 1 file changed, 13 insertions(+), 52 deletions(-) diff --git a/python/podio/frame.py b/python/podio/frame.py index cdbfe65c9..e35ad6bac 100644 --- a/python/podio/frame.py +++ b/python/podio/frame.py @@ -12,59 +12,20 @@ if ROOT.gInterpreter.LoadFile("podio/Frame.h") == 0: # noqa: E402 from ROOT import podio # noqa: E402 # pylint: disable=wrong-import-position - _FRAME_HEADER_AVAILABLE = True -else: - _FRAME_HEADER_AVAILABLE = False - -def _determine_supported_parameter_types(): - """Determine the supported types for the parameters. - - Returns: - tuple(tuple(str, str)): the tuple with the string representation of all - c++ and their corresponding python types that are supported - """ - types_tuple = podio.SupportedGenericDataTypes() - n_types = cppyy.gbl.std.tuple_size[podio.SupportedGenericDataTypes].value - - # Get the python types with the help of cppyy and the STL - py_types = [type(cppyy.gbl.std.get[i](types_tuple)).__name__ for i in range(n_types)] - - def _determine_cpp_type(idx_and_type): - """Determine the actual c++ type from the python type name. - - Mainly maps 'str' to 'std::string', and also determines whether a python - 'float' is actually a 'double' or a 'float' in c++. The latter is necessary - since python only has float (corresponding to double in c++) and we - need the exact c++ type - """ - idx, typename = idx_and_type - if typename == "float": - cpp_type = cppyy.gbl.std.tuple_element[idx, podio.SupportedGenericDataTypes].type - if cppyy.typeid(cpp_type).name() == "d": - return "double" - return "float" - if typename == "str": - return "std::string" - return typename - - cpp_types = list(map(_determine_cpp_type, enumerate(py_types))) - return tuple(zip(cpp_types, py_types)) - - -if _FRAME_HEADER_AVAILABLE: - try: - SUPPORTED_PARAMETER_TYPES = _determine_supported_parameter_types() - except AttributeError: - # On macOS there is an issue that makes the template machinery not work - # so we just hard code the map here in case we hit that issue. See - # https://github.com/root-project/root/issues/14232 - SUPPORTED_PARAMETER_TYPES = ( - ("int", "int"), - ("float", "float"), - ("std::string", "str"), - ("double", "float"), - ) +# This is the list of supported types for the GenericParameters in both c++ and +# python. It is used as a bi-directional map for converting between c++ and +# python types. The mapping mostly takes care of mapping 'str' to 'std::string' +# as well as 'double' to 'float' (since python does not have an actual 32 bit +# floating point type).We are not determining this list from the +# SupportedGenericDataTypes tuple dynamically since we are running into +# https://github.com/root-project/root/issues/14232 otherwise +SUPPORTED_PARAMETER_TYPES = ( + ("int", "int"), + ("float", "float"), + ("std::string", "str"), + ("double", "float"), +) def _get_cpp_types(type_str):