-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ntuple] fix schema evolution with streamer fields #18451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jblomer
wants to merge
7
commits into
root-project:master
Choose a base branch
from
jblomer:ntuple-test-streamed-evolution
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8cfc0d
[ntuple] fix de-s11n of streamer info records
jblomer 4e38886
[ntuple] add RPageSource::RegisterStreamerInfos()
jblomer 9a0278f
[ntuple] add RStreamerField::BeforeConnectPageSource()
jblomer 2034c23
[ntuple] test automatic schema evolution for streamer field
jblomer fb3284d
[ntuple] test I/O rules for streamer fields
jblomer a7f514a
[ntuple] test failure on streamer field type mismatch
jblomer 9851b52
[ntuple] add integration test for streamer field evolution
jblomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
ROOTTEST_GENERATE_DICTIONARY( | ||
event_v2_dict | ||
${CMAKE_CURRENT_SOURCE_DIR}/Event_v2.hxx | ||
LINKDEF ${CMAKE_CURRENT_SOURCE_DIR}/Event_v2_LinkDef.h | ||
NO_ROOTMAP NO_CXXMODULE | ||
FIXTURES_SETUP generated_event_v2_dictionary | ||
) | ||
|
||
ROOTTEST_GENERATE_EXECUTABLE( | ||
write_event | ||
LIBRARIES Core RIO ROOTNTuple | ||
FIXTURES_REQUIRED generated_event_v2_dictionary | ||
FIXTURES_SETUP write_event_excutable) | ||
|
||
target_sources( | ||
write_event | ||
PRIVATE write_event.cxx event_v2_dict.cxx | ||
) | ||
|
||
ROOTTEST_ADD_TEST(write_event | ||
EXEC ./write_event | ||
FIXTURES_REQUIRED write_event_excutable | ||
FIXTURES_SETUP written_event) | ||
|
||
ROOTTEST_GENERATE_DICTIONARY( | ||
event_v3_dict | ||
${CMAKE_CURRENT_SOURCE_DIR}/Event_v3.hxx | ||
LINKDEF ${CMAKE_CURRENT_SOURCE_DIR}/Event_v3_LinkDef.h | ||
NO_ROOTMAP NO_CXXMODULE | ||
FIXTURES_SETUP generated_event_v3_dictionary | ||
) | ||
|
||
ROOTTEST_GENERATE_EXECUTABLE( | ||
read_event | ||
LIBRARIES Core RIO ROOTNTuple | ||
FIXTURES_REQUIRED generated_event_v3_dictionary | ||
FIXTURES_SETUP read_event_executable) | ||
|
||
target_sources( | ||
read_event | ||
PRIVATE read_event.cxx event_v3_dict.cxx | ||
) | ||
|
||
ROOTTEST_ADD_TEST(read_event | ||
EXEC ./read_event | ||
FIXTURES_REQUIRED read_event_executable written_event) |
This file contains hidden or 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,36 @@ | ||
#ifndef EVENT_V2_H | ||
#define EVENT_V2_H | ||
|
||
#include <RtypesCore.h> | ||
|
||
#include <memory> | ||
|
||
struct StreamerBase { | ||
int fBase = 0; | ||
virtual ~StreamerBase() = default; | ||
|
||
ClassDef(StreamerBase, 2) | ||
}; | ||
|
||
struct StreamerDerived : public StreamerBase { | ||
int fFirst = 1; | ||
int fSecond = 2; | ||
virtual ~StreamerDerived() = default; | ||
|
||
ClassDef(StreamerDerived, 2) | ||
}; | ||
|
||
struct StreamerContainer { | ||
std::unique_ptr<StreamerBase> fPtr; | ||
|
||
ClassDefNV(StreamerContainer, 2) | ||
}; | ||
|
||
struct Event { | ||
int fX = 137; | ||
StreamerContainer fField; | ||
|
||
ClassDefNV(Event, 2) | ||
}; | ||
|
||
#endif // EVENT_V2_H |
This file contains hidden or 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,8 @@ | ||
#ifdef __ROOTCLING__ | ||
|
||
#pragma link C++ class StreamerBase+; | ||
#pragma link C++ class StreamerDerived+; | ||
#pragma link C++ options = rntupleStreamerMode(true) class StreamerContainer+; | ||
#pragma link C++ class Event+; | ||
|
||
#endif |
This file contains hidden or 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,36 @@ | ||
#ifndef EVENT_V3_H | ||
#define EVENT_V3_H | ||
|
||
#include <RtypesCore.h> | ||
|
||
#include <memory> | ||
|
||
struct StreamerBase { | ||
int fBase = 0; | ||
virtual ~StreamerBase() = default; | ||
|
||
ClassDef(StreamerBase, 2) | ||
}; | ||
|
||
struct StreamerDerived : public StreamerBase { | ||
int fSecond = 2; | ||
int fFirst = 1; | ||
virtual ~StreamerDerived() = default; | ||
|
||
ClassDef(StreamerDerived, 3) | ||
}; | ||
|
||
struct StreamerContainer { | ||
std::unique_ptr<StreamerBase> fPtr; | ||
|
||
ClassDefNV(StreamerContainer, 2) | ||
}; | ||
|
||
struct Event { | ||
StreamerContainer fField; | ||
int fY = 42; | ||
|
||
ClassDefNV(Event, 3) | ||
}; | ||
|
||
#endif // EVENT_V3_H |
This file contains hidden or 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,12 @@ | ||
#ifdef __ROOTCLING__ | ||
|
||
#pragma link C++ class StreamerBase+; | ||
#pragma link C++ class StreamerDerived+; | ||
#pragma link C++ options = rntupleStreamerMode(true) class StreamerContainer+; | ||
#pragma link C++ class Event+; | ||
|
||
#pragma read sourceClass = "StreamerBase" source = "int fBase;" version = "[2]" \ | ||
targetClass = "StreamerBase" target = "fBase" \ | ||
code = "{ fBase = onfile.fBase + 1000; }" | ||
|
||
#endif |
This file contains hidden or 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,34 @@ | ||
#include <ROOT/RNTupleReader.hxx> | ||
|
||
#include "Event_v3.hxx" | ||
|
||
#include <cstdio> | ||
|
||
int main() | ||
{ | ||
auto reader = ROOT::RNTupleReader::Open("ntpl", "root_test_streamerfield.root"); | ||
|
||
auto ptrEvent = reader->GetModel().GetDefaultEntry().GetPtr<Event>("event"); | ||
|
||
reader->LoadEntry(0); | ||
|
||
if (!dynamic_cast<const ROOT::RStreamerField *>(&reader->GetModel().GetConstField("event.fField"))) | ||
return 10; | ||
|
||
if (!ptrEvent->fField.fPtr) | ||
return 1; | ||
auto derived = dynamic_cast<StreamerDerived *>(ptrEvent->fField.fPtr.get()); | ||
if (!derived) | ||
return 2; | ||
if (derived->fBase != 1000) | ||
return 3; | ||
if (derived->fFirst != 1) | ||
return 4; | ||
if (derived->fSecond != 2) | ||
return 5; | ||
if (ptrEvent->fY != 42) | ||
return 6; | ||
|
||
std::remove("root_test_streamerfield.root"); | ||
return 0; | ||
} |
This file contains hidden or 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 @@ | ||
#include <ROOT/RNTupleModel.hxx> | ||
#include <ROOT/RNTupleWriter.hxx> | ||
|
||
#include "Event_v2.hxx" | ||
|
||
#include <memory> | ||
|
||
int main() | ||
{ | ||
auto model = ROOT::RNTupleModel::Create(); | ||
auto field = model->MakeField<Event>("event"); | ||
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl", "root_test_streamerfield.root"); | ||
|
||
field->fField.fPtr = std::unique_ptr<StreamerBase>(new StreamerDerived()); | ||
writer->Fill(); | ||
|
||
return 0; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test the indirect collection of StreamerInfo, there should be here a pointer to another class (possibly initialized with an instance of a derived class).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we already test that with
root/tree/ntuple/test/rfield_streamer.cxx
Line 126 in 031f6bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically the test linked will succeed whether or not the
StreamerInfo
are stored ... since they are still in memory from the already loaded dictionary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. like here to test the feature, one need 2 separate processes and 2 distinct schemas/versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I left the unit tests unchanged but I added this as an integration test.