Skip to content

Commit 42f5efd

Browse files
committed
[ntuple] add type version, checksum to type trace report
1 parent 1c2e682 commit 42f5efd

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

tree/ntuple/src/RFieldUtils.cxx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,26 @@ bool ROOT::Internal::IsMatchingFieldType(std::string_view actualTypeName, std::s
726726

727727
std::string ROOT::Internal::GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc)
728728
{
729+
// Information to print in a single line of the type trace
730+
struct RFieldInfo {
731+
std::string fFieldName;
732+
std::string fTypeName;
733+
DescriptorId_t fFieldId = kInvalidDescriptorId;
734+
std::uint32_t fTypeVersion = 0;
735+
std::optional<std::uint32_t> fTypeChecksum;
736+
};
737+
729738
std::vector<const RFieldBase *> inMemoryStack;
730739
std::vector<const RFieldDescriptor *> onDiskStack;
731740

732-
auto fnGetLine = [](const std::string &fieldName, const std::string &fieldType, DescriptorId_t fieldId,
733-
int level) -> std::string {
734-
return std::string(2 * level, ' ') + fieldName + " [" + fieldType + "] (id: " + std::to_string(fieldId) + ")\n";
741+
auto fnGetLine = [](const RFieldInfo &fieldInfo, int level) -> std::string {
742+
std::string line = std::string(2 * level, ' ') + fieldInfo.fFieldName + " [" + fieldInfo.fTypeName;
743+
if (fieldInfo.fTypeVersion > 0)
744+
line += ", type version: " + std::to_string(fieldInfo.fTypeVersion);
745+
if (fieldInfo.fTypeChecksum)
746+
line += ", type checksum: " + std::to_string(*fieldInfo.fTypeChecksum);
747+
line += "] (id: " + std::to_string(fieldInfo.fFieldId) + ")\n";
748+
return line;
735749
};
736750

737751
const RFieldBase *fieldPtr = &field;
@@ -750,13 +764,28 @@ std::string ROOT::Internal::GetTypeTraceReport(const RFieldBase &field, const RN
750764
std::string report = "In-memory field/type hierarchy:\n";
751765
int indentLevel = 0;
752766
for (auto itr = inMemoryStack.rbegin(); itr != inMemoryStack.rend(); ++itr, ++indentLevel) {
753-
report += fnGetLine((*itr)->GetFieldName(), (*itr)->GetTypeName(), (*itr)->GetOnDiskId(), indentLevel);
767+
RFieldInfo fieldInfo;
768+
fieldInfo.fFieldName = (*itr)->GetFieldName();
769+
fieldInfo.fTypeName = (*itr)->GetTypeName();
770+
fieldInfo.fFieldId = (*itr)->GetOnDiskId();
771+
fieldInfo.fTypeVersion = (*itr)->GetTypeVersion();
772+
if ((*itr)->GetTraits() & RFieldBase::kTraitTypeChecksum)
773+
fieldInfo.fTypeChecksum = (*itr)->GetTypeChecksum();
774+
775+
report += fnGetLine(fieldInfo, indentLevel);
754776
}
755777

756778
report += "On-disk field/type hierarchy:\n";
757779
indentLevel = 0;
758780
for (auto itr = onDiskStack.rbegin(); itr != onDiskStack.rend(); ++itr, ++indentLevel) {
759-
report += fnGetLine((*itr)->GetFieldName(), (*itr)->GetTypeName(), (*itr)->GetId(), indentLevel);
781+
RFieldInfo fieldInfo;
782+
fieldInfo.fFieldName = (*itr)->GetFieldName();
783+
fieldInfo.fTypeName = (*itr)->GetTypeName();
784+
fieldInfo.fFieldId = (*itr)->GetId();
785+
fieldInfo.fTypeVersion = (*itr)->GetTypeVersion();
786+
fieldInfo.fTypeChecksum = (*itr)->GetTypeChecksum();
787+
788+
report += fnGetLine(fieldInfo, indentLevel);
760789
}
761790

762791
return report;

tree/ntuple/test/CustomStruct.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ struct StructUsingCollectionProxy {
214214
/// Classes to exercise field traits
215215
struct TrivialTraitsBase {
216216
int a;
217+
218+
ClassDefNV(TrivialTraitsBase, 5)
217219
};
218220

219221
struct TrivialTraits : TrivialTraitsBase {

tree/ntuple/test/ntuple_show.cxx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -648,34 +648,37 @@ TEST(RNTupleShow, TypeTraceReport)
648648
FileRaii fileGuard("test_ntuple_show_type_trace_report.ntuple");
649649
{
650650
auto model = RNTupleModel::Create();
651-
model->MakeField<std::variant<double, std::vector<std::pair<float, bool>>>>("f");
651+
model->MakeField<std::variant<double, std::vector<std::pair<float, TrivialTraitsBase>>>>("f");
652652
auto writer = RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());
653653
}
654654

655655
auto reader = RNTupleReader::Open("ntpl", fileGuard.GetPath());
656656

657-
// Get the field for the `bool` member of the inner `pair`
657+
// Get the field for the `a` member of the inner `TrivialTraitsBase`
658658
const auto field = reader->GetModel()
659659
.GetDefaultEntry()
660660
.begin()
661661
->GetField()
662662
.GetConstSubfields()[1]
663663
->GetConstSubfields()[0]
664-
->GetConstSubfields()[1];
664+
->GetConstSubfields()[1]
665+
->GetConstSubfields()[0];
665666

666667
const auto report = ROOT::Internal::GetTypeTraceReport(*field, reader->GetDescriptor());
667668

668669
const std::string expected{
669670
R"(In-memory field/type hierarchy:
670-
f [std::variant<double,std::vector<std::pair<float,bool>>>] (id: 0)
671-
_1 [std::vector<std::pair<float,bool>>] (id: 2)
672-
_0 [std::pair<float,bool>] (id: 3)
673-
_1 [bool] (id: 5)
671+
f [std::variant<double,std::vector<std::pair<float,TrivialTraitsBase>>>] (id: 0)
672+
_1 [std::vector<std::pair<float,TrivialTraitsBase>>] (id: 2)
673+
_0 [std::pair<float,TrivialTraitsBase>] (id: 3)
674+
_1 [TrivialTraitsBase, type version: 5, type checksum: 2623577133] (id: 5)
675+
a [std::int32_t] (id: 6)
674676
On-disk field/type hierarchy:
675-
f [std::variant<double,std::vector<std::pair<float,bool>>>] (id: 0)
676-
_1 [std::vector<std::pair<float,bool>>] (id: 2)
677-
_0 [std::pair<float,bool>] (id: 3)
678-
_1 [bool] (id: 5)
677+
f [std::variant<double,std::vector<std::pair<float,TrivialTraitsBase>>>] (id: 0)
678+
_1 [std::vector<std::pair<float,TrivialTraitsBase>>] (id: 2)
679+
_0 [std::pair<float,TrivialTraitsBase>] (id: 3)
680+
_1 [TrivialTraitsBase, type version: 5, type checksum: 2623577133] (id: 5)
681+
a [std::int32_t] (id: 6)
679682
)"};
680683

681684
EXPECT_EQ(expected, report);

0 commit comments

Comments
 (0)