Skip to content

Commit

Permalink
add extension data model with interface
Browse files Browse the repository at this point in the history
add test for interface with types from data model and its extension
  • Loading branch information
m-fila committed Nov 29, 2024
1 parent 25abd06 commit 999a5eb
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions tests/datalayout_interface_extension.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions tests/unittests/interface_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<ExampleCluster>());
REQUIRE(wrapper.as<ExampleCluster>().energy() == 3.14f);

iextension::MutableAnotherHit hit{};
hit.energy(4.2f);
wrapper = hit;

REQUIRE(wrapper.energy() == 4.2f);
REQUIRE(wrapper.isA<iextension::AnotherHit>());
REQUIRE(wrapper.as<iextension::AnotherHit>().energy() == 4.2f);
}

0 comments on commit 999a5eb

Please sign in to comment.