-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first simple tests for "trivial" schema evolution
- Loading branch information
Showing
9 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Schema Evolution tests | ||
This folder contains tests for the schema evolution functionality in podio. The | ||
functionality is tested by first writing data with an old schema version and | ||
then reading in with the current schema version. | ||
[`datalayout_old.yaml`](./datalayout_old.yaml) holds the definition of the old | ||
version, using schema version 1, while the | ||
[`datalayout.yaml`](../datalayout.yaml) that is also used for the other I/O | ||
tests is used as the current version (schema version 2). | ||
|
||
## Differences between the two schema versions | ||
Since it is not immediately visible from the test code this list contains the | ||
differences between the two schema versions, and also how this evolution is | ||
tested (if it is supported) | ||
|
||
| component / datatype | difference from v1 to v2 | purpose of test | tested with | | ||
|--|--|--|--| | ||
| `SimpleStruct` | no `int y` member in v1 | Addition of new members in components | As member of `ExampleWithArrayComponent` | | ||
| `ExampleHit` | no `double energy` member in v1 | Addition of new members in datatypes | Directly via `ExampleHit` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef PODIO_TESTS_SCHEMAEVOLUTION_READNEWDATA_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
#define PODIO_TESTS_SCHEMAEVOLUTION_READNEWDATA_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
|
||
#include "datamodel/ExampleHitCollection.h" | ||
#include "datamodel/ExampleWithArrayComponentCollection.h" | ||
|
||
#include "podio/Frame.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
int readSimpleStruct(const podio::Frame& event) { | ||
const auto& coll = event.get<ExampleWithArrayComponentCollection>("simpleStructTest"); | ||
auto elem = coll[0]; | ||
const auto sstruct = elem.s(); | ||
|
||
if (sstruct.y != 0 || sstruct.x != 42 || sstruct.z != 123) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int readExampleHit(const podio::Frame& event) { | ||
const auto& coll = event.get<ExampleHitCollection>("datatypeMemberAdditionTest"); | ||
auto elem = coll[0]; | ||
|
||
if (elem.energy() != 0) { | ||
return 1; | ||
} | ||
if (elem.x() != 1.23 || elem.y() != 1.23 || elem.z() != 1.23 || elem.cellID() != 0xcaffee) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
template <typename ReaderT> | ||
int read_new_data(const std::string& filename) { | ||
ReaderT reader{}; | ||
reader.openFile(filename); | ||
|
||
const auto event = podio::Frame(reader.readEntry("events", 0)); | ||
|
||
int result = 0; | ||
result += readSimpleStruct(event); | ||
result += readExampleHit(event); | ||
|
||
return result; | ||
} | ||
|
||
#endif // PODIO_TESTS_SCHEMAEVOLUTION_WRITEOLDDATA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PODIO_CREATE_WRITE_OLD_DATA_TEST(write_old_data_root.cpp "TestDataModel_v1Dict;podio::podioRootIO") | ||
|
||
CREATE_PODIO_TEST(read_new_data_root.cpp "TestDataModelDict;podioRootIO") | ||
set_property(TEST read_new_data_root PROPERTY DEPENDS write_old_data_root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "schema_evolution/read_new_data.h" | ||
|
||
#include "podio/ROOTFrameReader.h" | ||
|
||
int main() { | ||
return read_new_data<podio::ROOTFrameReader>("example_data_old_schema.root"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "write_old_data.h" | ||
|
||
#include "podio/ROOTFrameWriter.h" | ||
|
||
int main() { | ||
return writeData<podio::ROOTFrameWriter>("example_data_old_schema.root"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef PODIO_TESTS_SCHEMAEVOLUTION_WRITEOLDDATA_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
#define PODIO_TESTS_SCHEMAEVOLUTION_WRITEOLDDATA_H // NOLINT(llvm-header-guard): folder structure not suitable | ||
|
||
#include "datamodel/ExampleHitCollection.h" | ||
#include "datamodel/ExampleWithArrayComponentCollection.h" | ||
|
||
#include "podio/Frame.h" | ||
|
||
#include <string> | ||
|
||
/// This is a datatype that holds a SimpleStruct component | ||
auto writeSimpleStruct() { | ||
ExampleWithArrayComponentCollection coll; | ||
auto elem = coll.create(); | ||
auto sstruct = SimpleStruct(); | ||
sstruct.x = 42; | ||
sstruct.z = 123; | ||
elem.s(sstruct); | ||
|
||
return coll; | ||
} | ||
|
||
auto writeExampleHit() { | ||
ExampleHitCollection coll; | ||
auto elem = coll.create(); | ||
elem.x(1.23); | ||
elem.y(1.23); | ||
elem.z(1.23); | ||
elem.cellID(0xcaffee); | ||
|
||
return coll; | ||
} | ||
|
||
podio::Frame createFrame() { | ||
podio::Frame event; | ||
|
||
event.put(writeSimpleStruct(), "simpleStructTest"); | ||
event.put(writeExampleHit(), "dataTypeMemberAdditionTest"); | ||
|
||
return event; | ||
} | ||
|
||
template <typename WriterT> | ||
int writeData(const std::string& filename) { | ||
WriterT writer(filename); | ||
|
||
auto event = createFrame(); | ||
writer.writeFrame(event, "events"); | ||
|
||
writer.finish(); | ||
|
||
return 0; | ||
} | ||
|
||
#endif // PODIO_TESTS_SCHEMAEVOLUTION_WRITEOLDDATA_H |