Skip to content

Commit

Permalink
Add datamodel dumping roundtrip tests and make sure they work
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Nov 24, 2023
1 parent 82d4d44 commit f20d0a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ROOTNTupleReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void ROOTNTupleReader::openFiles(const std::vector<std::string>& filenames) {

auto edmView = m_metadata->GetView<std::vector<std::tuple<std::string, std::string>>>(root_utils::edmDefBranchName);
auto edm = edmView(0);
m_datamodelHolder = DatamodelDefinitionHolder(std::move(edm));

auto availableCategoriesField = m_metadata->GetView<std::vector<std::string>>(root_utils::availableCategories);
m_availableCategories = availableCategoriesField(0);
Expand Down
6 changes: 5 additions & 1 deletion src/ROOTNTupleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ std::unique_ptr<ROOT::Experimental::RNTupleModel>
ROOTNTupleWriter::createModels(const std::vector<StoreCollection>& collections) {
auto model = ROOT::Experimental::RNTupleModel::CreateBare();
for (auto& [name, coll] : collections) {
// For the first entry in each category we also record the datamodel
// definition
m_datamodelCollector.registerDatamodelDefinition(coll, name);

const auto collBuffers = coll->getBuffers();

if (collBuffers.vecPtr) {
Expand Down Expand Up @@ -252,7 +256,7 @@ void ROOTNTupleWriter::finish() {
auto edmDefinitions = m_datamodelCollector.getDatamodelDefinitionsToWrite();
auto edmField =
m_metadata->MakeField<std::vector<std::tuple<std::string, std::string>>>(root_utils::edmDefBranchName);
*edmField = edmDefinitions;
*edmField = std::move(edmDefinitions);

auto availableCategoriesField = m_metadata->MakeField<std::vector<std::string>>(root_utils::availableCategories);
for (auto& [c, _] : m_categories) {
Expand Down
33 changes: 33 additions & 0 deletions tests/dumpmodel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,43 @@ if (ENABLE_SIO)
)
endif()

set(rntuple_roundtrip_tests "")
if (ENABLE_RNTUPLE)
add_test(NAME datamodel_def_store_roundtrip_rntuple COMMAND
${PROJECT_SOURCE_DIR}/tests/scripts/dumpModelRoundTrip.sh
${PROJECT_BINARY_DIR}/tests/root_io/example_rntuple.root
datamodel
${PROJECT_SOURCE_DIR}/tests
)
PODIO_SET_TEST_ENV(datamodel_def_store_roundtrip_rntuple)

add_test(NAME datamodel_def_store_roundtrip_rntuple_extension COMMAND
${PROJECT_SOURCE_DIR}/tests/scripts/dumpModelRoundTrip.sh
${PROJECT_BINARY_DIR}/tests/root_io/example_rntuple.root
extension_model
${PROJECT_SOURCE_DIR}/tests/extension_model
--upstream-edm=datamodel:${PROJECT_SOURCE_DIR}/tests/datalayout.yaml
)
PODIO_SET_TEST_ENV(datamodel_def_store_roundtrip_rntuple_extension)

set(rntuple_roundtrip_tests
datamodel_def_store_roundtrip_rntuple
datamodel_def_store_roundtrip_rntuple_extension
)

set_tests_properties(
${rntuple_roundtrip_tests}
PROPERTIES
DEPENDS write_rntuple
)

endif()

set_tests_properties(
datamodel_def_store_roundtrip_root
datamodel_def_store_roundtrip_root_extension
${sio_roundtrip_tests}
${rntuple_roundtrip_tests}
PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

0 comments on commit f20d0a1

Please sign in to comment.