Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmake/podioMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmake/podioTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions tests/CTestCustom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
42 changes: 42 additions & 0 deletions tests/root_io/test_root_macro.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "datamodel/ExampleClusterCollection.h"
#include "datamodel/ExampleHitCollection.h"
#include "datamodel/TestLinkCollection.h"

#include <iostream>
#include <stdexcept>

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");
}
}