diff --git a/cmake/podioMacros.cmake b/cmake/podioMacros.cmake index 05f13315b..30a064004 100644 --- a/cmake/podioMacros.cmake +++ b/cmake/podioMacros.cmake @@ -252,6 +252,20 @@ function(PODIO_ADD_ROOT_IO_DICT dict_name CORE_LIB HEADERS SELECTION_XML) # the core headers LIST(FILTER HEADERS EXCLUDE REGEX .*SIOBlock.h) LIST(FILTER HEADERS EXCLUDE REGEX .*ArrowMapper.h) + # Exclude the datamodel header (e.g. edm4hep.h) + # since it will include everything and include guards will be set + # causing clashes with Link type aliases at runtime. + # Find patters like datamodel/datamodel.h or edm4hep/edm4hep.h + # to exclude them + foreach(_header ${HEADERS}) + get_filename_component(_header_stem ${_header} NAME_WE) + get_filename_component(_header_dir ${_header} DIRECTORY) + get_filename_component(_parent_name ${_header_dir} NAME) + if(_header_stem STREQUAL _parent_name) + list(REMOVE_ITEM HEADERS ${_header}) + break() + endif() + endforeach() add_library(${dict_name} SHARED) target_link_libraries(${dict_name} PUBLIC diff --git a/cmake/podioTest.cmake b/cmake/podioTest.cmake index 8105e4c22..5ab39a3c0 100644 --- a/cmake/podioTest.cmake +++ b/cmake/podioTest.cmake @@ -37,7 +37,7 @@ endif() # preloaded via LD_PRELOAD so that cling can dlopen instrumented shared # libraries in case a sanitizer has been enabled for the build. function(PODIO_SET_TEST_ENV test) - cmake_parse_arguments(PARSE_ARGV 1 ARG "PYTHON" "" "") + cmake_parse_arguments(PARSE_ARGV 1 ARG "PYTHON;CLING" "" "") # We need to convert this into a list of arguments that can be used as environment variable list(JOIN PODIO_IO_HANDLERS " " IO_HANDLERS) set(test_environment @@ -64,7 +64,7 @@ function(PODIO_SET_TEST_ENV test) ) endif() # Preload the sanitizer runtime so cling can dlopen instrumented libraries - if(ARG_PYTHON AND PODIO_SANITIZER_LIBRARY) + if((ARG_PYTHON OR ARG_CLING) AND PODIO_SANITIZER_LIBRARY) list(APPEND test_environment "LD_PRELOAD=${PODIO_SANITIZER_LIBRARY}:$ENV{LD_PRELOAD}") endif() set_property(TEST ${test} diff --git a/tests/CTestCustom.cmake b/tests/CTestCustom.cmake index 6b8945786..2b8ee25c4 100644 --- a/tests/CTestCustom.cmake +++ b/tests/CTestCustom.cmake @@ -107,6 +107,8 @@ if ((NOT "@FORCE_RUN_ALL_TESTS@" STREQUAL "ON") AND (NOT "@USE_SANITIZER@" STREQ podio-dump-rntuple podio-dump-detailed-rntuple + root_test_macro + datamodel_def_store_roundtrip_rntuple datamodel_def_store_roundtrip_rntuple_extension diff --git a/tests/root_io/CMakeLists.txt b/tests/root_io/CMakeLists.txt index 2c337f906..de4d96530 100644 --- a/tests/root_io/CMakeLists.txt +++ b/tests/root_io/CMakeLists.txt @@ -128,7 +128,10 @@ PODIO_SET_TEST_ENV(param_reading_rdataframe PYTHON) set_tests_properties(param_reading_rdataframe PROPERTIES FIXTURES_REQUIRED podio_write_root_fixture) if(ENABLE_DATASOURCE) - add_test(NAME read_python_with_rdatasource_root COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/root_io/read_datasource.py) - PODIO_SET_TEST_ENV(read_python_with_rdatasource_root PYTHON) - set_tests_properties(read_python_with_rdatasource_root PROPERTIES FIXTURES_REQUIRED podio_write_root_fixture) -endif() + add_test(NAME read_python_with_rdatasource_root COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/root_io/read_datasource.py) + PODIO_SET_TEST_ENV(read_python_with_rdatasource_root PYTHON) + set_tests_properties(read_python_with_rdatasource_root PROPERTIES FIXTURES_REQUIRED podio_write_root_fixture) + endif() + +add_test(NAME root_test_macro COMMAND root -l -b -q ${CMAKE_CURRENT_SOURCE_DIR}/test_root_macro.C) +PODIO_SET_TEST_ENV(root_test_macro CLING) diff --git a/tests/root_io/test_root_macro.C b/tests/root_io/test_root_macro.C new file mode 100644 index 000000000..715850a78 --- /dev/null +++ b/tests/root_io/test_root_macro.C @@ -0,0 +1,42 @@ +#include "datamodel/ExampleClusterCollection.h" +#include "datamodel/ExampleHitCollection.h" +#include "datamodel/TestLinkCollection.h" + +#include +#include + +void test_root_macro() { + auto success = true; + const auto check = [&success](const char* name, const auto& actual, const auto& expected) { + if (actual == expected) { + return; + } + + std::cerr << "test_root_macro: " << name << " failed: expected " << expected << ", got " << actual << '\n'; + success = false; + }; + + // Link collection + auto linkCol = TestLinkCollection{}; + auto link = linkCol.create(); + link.setWeight(0.5); + check("link weight", link.getWeight(), 0.5); + check("link collection size", linkCol.size(), 1u); + + // Regular datatype collections + auto hitCol = ExampleHitCollection{}; + auto hit = hitCol.create(); + hit.energy(42.0); + check("hit energy", hit.energy(), 42.0); + check("hit collection size", hitCol.size(), 1u); + + auto clusterCol = ExampleClusterCollection{}; + auto cluster = clusterCol.create(); + cluster.energy(7.0); + check("cluster energy", cluster.energy(), 7.0); + check("cluster collection size", clusterCol.size(), 1u); + + if (!success) { + throw std::runtime_error("test_root_macro failed"); + } +}