diff --git a/.gitignore b/.gitignore index 8da0b83df..ffa686f7f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ install tests/src tests/datamodel tests/extension_model +tests/interface_extension_model tests/datamodeljulia tests/unittests/Project.toml tests/unittests/Manifest.toml diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 65608cca7..c2815738e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,6 +48,21 @@ PODIO_ADD_ROOT_IO_DICT(ExtensionDataModelDict ExtensionDataModel "${ext_headers} PODIO_ADD_SIO_IO_BLOCKS(ExtensionDataModel "${ext_headers}" "${ext_sources}") +# Build the interface extension data model and link it against the upstream model +PODIO_GENERATE_DATAMODEL(interface_extension_model datalayout_interface_extension.yaml iext_headers iext_sources + UPSTREAM_EDM datamodel:datalayout.yaml + IO_BACKEND_HANDLERS ${PODIO_IO_HANDLERS} + OUTPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface_extension_model) + +PODIO_ADD_DATAMODEL_CORE_LIB(InterfaceExtensionDataModel "${iext_headers}" "${iext_sources}" + OUTPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface_extension_model) +target_link_libraries(InterfaceExtensionDataModel PUBLIC TestDataModel) + +PODIO_ADD_ROOT_IO_DICT(InterfaceExtensionDataModelDict InterfaceExtensionDataModel "${iext_headers}" ${CMAKE_CURRENT_SOURCE_DIR}/interface_extension_model/src/selection.xml + OUTPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface_extension_model) + +PODIO_ADD_SIO_IO_BLOCKS(InterfaceExtensionDataModel "${iext_headers}" "${iext_sources}") + # Add a legacy test case based on a base executable and a version for which an # input file exists macro(ADD_PODIO_LEGACY_TEST version base_test input_file) diff --git a/tests/datalayout_interface_extension.yaml b/tests/datalayout_interface_extension.yaml new file mode 100644 index 000000000..a873d6cde --- /dev/null +++ b/tests/datalayout_interface_extension.yaml @@ -0,0 +1,35 @@ +--- +schema_version: 1 +options: + getSyntax: False + exposePODMembers: False + includeSubfolder: True + +components: + iextension::PolarVector: + Members: + - float r + - float theta + - float phi + +datatypes: + iextension::AnotherHit: + Author: "Mateusz Jakub Fila" + Description: "A datatype in the extension with components from the extension and an upstream datamodel" + Members: + - unsigned long long cellID // cellID + - SimpleStruct aStruct // component defined in an upstream datamodel + - iextension::PolarVector aVector // component defined in the extension + - double energy [GeV] // measured energy deposit + +interfaces: + iextension::EnergyInterface: + Description: "Generic interface for types with an energy member" + Author: "Mateusz Jakub Fila" + Types: + - ExampleHit + - ExampleMC + - ExampleCluster + - iextension::AnotherHit + Members: + - double energy // the energy diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index 07c304a57..10f67f66a 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -41,7 +41,7 @@ endif() find_package(Threads REQUIRED) add_executable(unittest_podio unittest.cpp frame.cpp buffer_factory.cpp interface_types.cpp std_interoperability.cpp links.cpp) -target_link_libraries(unittest_podio PUBLIC TestDataModel PRIVATE Catch2::Catch2WithMain Threads::Threads podio::podioRootIO) +target_link_libraries(unittest_podio PUBLIC TestDataModel InterfaceExtensionDataModel PRIVATE Catch2::Catch2WithMain Threads::Threads podio::podioRootIO) if (ENABLE_SIO) target_link_libraries(unittest_podio PRIVATE podio::podioSioIO) endif() diff --git a/tests/unittests/interface_types.cpp b/tests/unittests/interface_types.cpp index 876e7c14e..b8d649aa6 100644 --- a/tests/unittests/interface_types.cpp +++ b/tests/unittests/interface_types.cpp @@ -6,6 +6,10 @@ #include "datamodel/MutableExampleMC.h" #include "datamodel/TypeWithEnergy.h" +#include "interface_extension_model/AnotherHit.h" +#include "interface_extension_model/EnergyInterface.h" +#include "interface_extension_model/MutableAnotherHit.h" + #include "podio/ObjectID.h" #include "podio/utilities/TypeHelpers.h" @@ -131,3 +135,26 @@ TEST_CASE("InterfaceType getters", "[basics][interface-types][code-gen]") { TypeWithEnergy interfaceType = cluster; REQUIRE(interfaceType.energy() == 3.14f); } + +TEST_CASE("InterfaceType extension model", "[interface-types][extension]") { + using WrapperT = iextension::EnergyInterface; + + auto wrapper = WrapperT::makeEmpty(); + REQUIRE_FALSE(wrapper.isAvailable()); + + MutableExampleCluster cluster{}; + cluster.energy(3.14f); + wrapper = cluster; + + REQUIRE(wrapper.energy() == 3.14f); + REQUIRE(wrapper.isA()); + REQUIRE(wrapper.as().energy() == 3.14f); + + iextension::MutableAnotherHit hit{}; + hit.energy(4.2f); + wrapper = hit; + + REQUIRE(wrapper.energy() == 4.2f); + REQUIRE(wrapper.isA()); + REQUIRE(wrapper.as().energy() == 4.2f); +}