-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[ntuple] fix type names with [U]Long64_t template args #20478
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
base: master
Are you sure you want to change the base?
Changes from all commits
e142a0a
051e95b
e06d376
4bf7473
16a90ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -380,3 +380,19 @@ TEST(RNTuple, ContextDependentTypeNames) | |
| } | ||
| } | ||
| } | ||
|
|
||
| TEST(RNTuple, NeedsMetaNameAsAlias) | ||
| { | ||
| using ROOT::Internal::NeedsMetaNameAsAlias; | ||
|
|
||
| std::string renormalizedAlias; | ||
| EXPECT_FALSE(NeedsMetaNameAsAlias("bool", renormalizedAlias)); | ||
| EXPECT_FALSE(NeedsMetaNameAsAlias("std::vector<long>", renormalizedAlias)); | ||
| EXPECT_FALSE(NeedsMetaNameAsAlias("std::vector<Long64_t>", renormalizedAlias)); | ||
| EXPECT_TRUE(NeedsMetaNameAsAlias("::MyClass<Long64_t>", renormalizedAlias)); | ||
| EXPECT_EQ("MyClass<Long64_t>", renormalizedAlias); | ||
| EXPECT_TRUE(NeedsMetaNameAsAlias("MyClass<ULong64_t>", renormalizedAlias)); | ||
| EXPECT_TRUE(NeedsMetaNameAsAlias("std::vector<MyClass<Long64_t> >", renormalizedAlias)); | ||
| EXPECT_EQ("std::vector<MyClass<Long64_t>>", renormalizedAlias); | ||
| EXPECT_FALSE(NeedsMetaNameAsAlias("MyClass<ROOT::RVec<Long64_t>>", renormalizedAlias)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also test |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #include "ntuple_test.hxx" | ||
| #include "SimpleCollectionProxy.hxx" | ||
|
|
||
| #include <TMath.h> | ||
| #include <TObject.h> | ||
|
|
@@ -391,41 +392,56 @@ TEST(RNTuple, TClassMetaName) | |
| auto f4 = RFieldBase::Create("f", "EdmContainer").Unwrap(); | ||
| EXPECT_STREQ("EdmWrapper<Long64_t>", | ||
| static_cast<const ROOT::RClassField *>(f4->GetConstSubfields()[0])->GetClass()->GetName()); | ||
|
|
||
| SimpleCollectionProxy<StructUsingCollectionProxy<Long64_t>> proxy; | ||
| auto cl = TClass::GetClass("StructUsingCollectionProxy<Long64_t>"); | ||
| cl->CopyCollectionProxy(proxy); | ||
|
|
||
| auto f5 = std::make_unique<ROOT::RField<StructUsingCollectionProxy<Long64_t>>>("f"); | ||
| EXPECT_TRUE(dynamic_cast<ROOT::RProxiedCollectionField *>(f5.get())); | ||
| EXPECT_EQ("StructUsingCollectionProxy<Long64_t>", f5->GetTypeAlias()); | ||
|
|
||
| ROOT::RStreamerField f6("f", "EdmWrapper<long long>"); | ||
| EXPECT_STREQ("EdmWrapper<Long64_t>", f6.GetClass()->GetName()); | ||
| EXPECT_EQ("EdmWrapper<Long64_t>", f6.GetTypeAlias()); | ||
| } | ||
|
|
||
| TEST(RNTuple, StreamerInfoRecords) | ||
| { | ||
| // Every testee consists of the type stored on disk and the expected streamer info records | ||
| std::vector<std::pair<std::string, std::vector<std::string>>> testees{ | ||
| {"float", {}}, | ||
| {"std::vector<float>", {}}, | ||
| {"std::pair<float, float>", {}}, | ||
| {"std::map<int, float>", {}}, | ||
| {"CustomStruct", {"CustomStruct"}}, | ||
| {"std::vector<CustomStruct>", {"CustomStruct"}}, | ||
| {"std::map<int, CustomStruct>", {"CustomStruct"}}, | ||
| {"DerivedA", {"DerivedA", "CustomStruct"}}, | ||
| {"std::pair<CustomStruct, DerivedA>", {"DerivedA", "CustomStruct"}}, | ||
| {"EdmWrapper<long long>", {"EdmWrapper<Long64_t>"}}, | ||
| {"TRotation", {"TRotation"}}}; | ||
| // Every testee consists of the type stored on disk, the expected streamer info records, and the expected type alias | ||
| std::vector<std::tuple<std::string, std::vector<std::string>, std::string>> testees{ | ||
| {"float", {}, ""}, | ||
| {"std::vector<float>", {}, ""}, | ||
| {"std::pair<float, float>", {}, ""}, | ||
| {"std::map<int, float>", {}, ""}, | ||
| {"CustomStruct", {"CustomStruct"}, ""}, | ||
| {"std::vector<CustomStruct>", {"CustomStruct"}, ""}, | ||
| {"std::map<int, CustomStruct>", {"CustomStruct"}, ""}, | ||
| {"DerivedA", {"DerivedA", "CustomStruct"}, ""}, | ||
| {"std::pair<CustomStruct, DerivedA>", {"DerivedA", "CustomStruct"}, ""}, | ||
| {"EdmWrapper<long long>", {"EdmWrapper<Long64_t>"}, "EdmWrapper<Long64_t>"}, | ||
| {"EdmContainer", {"EdmContainer", "EdmWrapper<Long64_t>"}, ""}, | ||
| {"EdmWrapper<long long>::Inner", {"EdmWrapper<Long64_t>::Inner"}, "EdmWrapper<Long64_t>::Inner"}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also test (besides for |
||
| {"EdmContainer::EdmWrapperLong64_t", {"EdmWrapper<Long64_t>"}, "EdmContainer::EdmWrapperLong64_t"}, | ||
| {"TRotation", {"TRotation"}, ""}}; | ||
|
|
||
| for (const auto &t : testees) { | ||
| FileRaii fileGuard("test_ntuple_streamer_info_records.root"); | ||
|
|
||
| { | ||
| auto model = ROOT::RNTupleModel::Create(); | ||
| if (t.first == "TRotation") { | ||
| model->AddField(std::make_unique<ROOT::RStreamerField>("f", t.first)); | ||
| if (std::get<0>(t) == "TRotation") { | ||
| model->AddField(std::make_unique<ROOT::RStreamerField>("f", std::get<0>(t))); | ||
| } else { | ||
| model->AddField(ROOT::RFieldBase::Create("f", t.first).Unwrap()); | ||
| model->AddField(ROOT::RFieldBase::Create("f", std::get<0>(t)).Unwrap()); | ||
| } | ||
| auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath()); | ||
| } | ||
|
|
||
| auto f = std::unique_ptr<TFile>(TFile::Open(fileGuard.GetPath().c_str())); | ||
| ASSERT_TRUE(f && !f->IsZombie()); | ||
|
|
||
| std::unordered_set<std::string> expectedInfos{t.second.begin(), t.second.end()}; | ||
| std::unordered_set<std::string> expectedInfos{std::get<1>(t).begin(), std::get<1>(t).end()}; | ||
| expectedInfos.insert("ROOT::RNTuple"); | ||
| for (const auto info : TRangeDynCast<TVirtualStreamerInfo>(*f->GetStreamerInfoList())) { | ||
| auto itr = expectedInfos.find(info->GetName()); | ||
|
|
@@ -436,5 +452,12 @@ TEST(RNTuple, StreamerInfoRecords) | |
| expectedInfos.erase(itr); | ||
| } | ||
| EXPECT_TRUE(expectedInfos.empty()); | ||
|
|
||
| // Make sure we can reconstruct the fields | ||
| auto reader = RNTupleReader::Open("ntpl", fileGuard.GetPath()); | ||
| EXPECT_EQ(std::get<2>(t), reader->GetModel().GetConstField("f").GetTypeAlias()); | ||
| if (auto field = dynamic_cast<const ROOT::RClassField *>(&reader->GetModel().GetConstField("f"))) { | ||
| EXPECT_EQ(std::get<1>(t)[0], field->GetClass()->GetName()); | ||
| } | ||
| } | ||
| } | ||
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.
This seems similar to (but better than):
TClassEdit::GetLong64_Name, isn't it?