Skip to content

Commit 45a5104

Browse files
[ntuple] Add GetColumnIds methods in Inspector
Changed GetColumnsBy... to GetColumnIds with parameter overloading, also made GetColumnIdsRecursive and GetColumnIds two different methods
1 parent 9b42f54 commit 45a5104

File tree

3 files changed

+98
-20
lines changed

3 files changed

+98
-20
lines changed

tree/ntupleutil/v7/inc/ROOT/RNTupleInspector.hxx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,23 @@ public:
269269
/// \param[in] colType The column type to collect, as defined by ROOT::ENTupleColumnType.
270270
///
271271
/// \return A vector containing the physical IDs of columns of the provided type.
272-
std::vector<ROOT::DescriptorId_t> GetColumnsByType(ROOT::ENTupleColumnType colType);
272+
std::vector<ROOT::DescriptorId_t> GetColumnIds(ROOT::ENTupleColumnType colType);
273273

274274
/////////////////////////////////////////////////////////////////////////////
275275
/// \brief Get the columns that make up the given field, including its subfields.
276276
///
277277
/// \param [in] fieldId The ID of the field for which to collect the columns.
278278
///
279279
/// \return A vector containing the IDs of all columns for the provided field ID.
280-
std::vector<ROOT::DescriptorId_t> GetColumnsByFieldId(ROOT::DescriptorId_t fieldId) const;
280+
std::vector<ROOT::DescriptorId_t> GetColumnIdsRecursive(ROOT::DescriptorId_t fieldId) const;
281+
282+
/////////////////////////////////////////////////////////////////////////////
283+
/// \brief Get the columns that make up the given field, excluding its subfields.
284+
///
285+
/// \param [in] fieldId The ID of the field for which to collect the columns.
286+
///
287+
/// \return A vector containing the IDs of all columns for the provided field ID.
288+
std::vector<ROOT::DescriptorId_t> GetColumnIds(ROOT::DescriptorId_t fieldId) const;
281289

282290
/////////////////////////////////////////////////////////////////////////////
283291
/// \brief Get all column types present in the RNTuple being inspected.

tree/ntupleutil/v7/src/RNTupleInspector.cxx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ROOT::Experimental::RNTupleInspector::CollectFieldTreeInfo(ROOT::DescriptorId_t
127127
}
128128

129129
std::vector<ROOT::DescriptorId_t>
130-
ROOT::Experimental::RNTupleInspector::GetColumnsByFieldId(ROOT::DescriptorId_t fieldId) const
130+
ROOT::Experimental::RNTupleInspector::GetColumnIdsRecursive(ROOT::DescriptorId_t fieldId) const
131131
{
132132
std::vector<ROOT::DescriptorId_t> colIds;
133133
std::deque<ROOT::DescriptorId_t> fieldIdQueue{fieldId};
@@ -152,6 +152,18 @@ ROOT::Experimental::RNTupleInspector::GetColumnsByFieldId(ROOT::DescriptorId_t f
152152
return colIds;
153153
}
154154

155+
std::vector<ROOT::DescriptorId_t> ROOT::Experimental::RNTupleInspector::GetColumnIds(ROOT::DescriptorId_t fieldId) const
156+
{
157+
std::vector<ROOT::DescriptorId_t> colIds;
158+
for (const auto &col : fDescriptor.GetColumnIterable(fieldId)) {
159+
if (col.IsAliasColumn()) {
160+
continue;
161+
}
162+
colIds.emplace_back(col.GetPhysicalId());
163+
}
164+
return colIds;
165+
}
166+
155167
std::unique_ptr<ROOT::Experimental::RNTupleInspector>
156168
ROOT::Experimental::RNTupleInspector::Create(const ROOT::RNTuple &sourceNTuple)
157169
{
@@ -203,8 +215,7 @@ size_t ROOT::Experimental::RNTupleInspector::GetColumnCountByType(ROOT::ENTupleC
203215
return typeCount;
204216
}
205217

206-
std::vector<ROOT::DescriptorId_t>
207-
ROOT::Experimental::RNTupleInspector::GetColumnsByType(ROOT::ENTupleColumnType colType)
218+
std::vector<ROOT::DescriptorId_t> ROOT::Experimental::RNTupleInspector::GetColumnIds(ROOT::ENTupleColumnType colType)
208219
{
209220
std::vector<ROOT::DescriptorId_t> colIds;
210221

@@ -419,7 +430,7 @@ ROOT::Experimental::RNTupleInspector::GetPageSizeDistribution(std::initializer_l
419430
}
420431

421432
for (const auto colType : colTypeVec) {
422-
auto colIds = GetColumnsByType(colType);
433+
auto colIds = GetColumnIds(colType);
423434

424435
if (colIds.empty())
425436
continue;

tree/ntupleutil/v7/test/ntuple_inspector.cxx

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ TEST(RNTupleInspector, ColumnTypeCount)
358358
EXPECT_EQ(3, inspector->GetColumnCountByType(ENTupleColumnType::kSplitInt32));
359359
}
360360

361-
TEST(RNTupleInspector, ColumnsByType)
361+
TEST(RNTupleInspector, GetColumnIdsByType)
362362
{
363-
FileRaii fileGuard("test_ntuple_inspector_columns_by_type.root");
363+
FileRaii fileGuard("test_ntuple_inspector_column_ids.root");
364364
{
365365
auto model = RNTupleModel::Create();
366366
auto nFldInt1 = model->MakeField<std::int64_t>("int1");
@@ -374,24 +374,83 @@ TEST(RNTupleInspector, ColumnsByType)
374374
}
375375

376376
auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
377-
378-
EXPECT_EQ(2U, inspector->GetColumnsByType(ENTupleColumnType::kSplitInt64).size());
379-
for (const auto colId : inspector->GetColumnsByType(ENTupleColumnType::kSplitInt64)) {
377+
EXPECT_EQ(2U, inspector->GetColumnIds(ENTupleColumnType::kSplitInt64).size());
378+
for (const auto colId : inspector->GetColumnIds(ENTupleColumnType::kSplitInt64)) {
380379
EXPECT_EQ(ENTupleColumnType::kSplitInt64, inspector->GetColumnInspector(colId).GetType());
381380
}
382381

383-
EXPECT_EQ(2U, inspector->GetColumnsByType(ENTupleColumnType::kSplitReal32).size());
384-
for (const auto colId : inspector->GetColumnsByType(ENTupleColumnType::kSplitReal32)) {
382+
EXPECT_EQ(2U, inspector->GetColumnIds(ENTupleColumnType::kSplitReal32).size());
383+
for (const auto colId : inspector->GetColumnIds(ENTupleColumnType::kSplitReal32)) {
385384
EXPECT_EQ(ENTupleColumnType::kSplitReal32, inspector->GetColumnInspector(colId).GetType());
386385
}
387386

388-
EXPECT_EQ(1U, inspector->GetColumnsByType(ENTupleColumnType::kSplitIndex64).size());
389-
EXPECT_EQ(1U, inspector->GetColumnsByType(ENTupleColumnType::kSplitIndex64).size());
390-
for (const auto colId : inspector->GetColumnsByType(ENTupleColumnType::kSplitIndex64)) {
387+
EXPECT_EQ(1U, inspector->GetColumnIds(ENTupleColumnType::kSplitIndex64).size());
388+
for (const auto colId : inspector->GetColumnIds(ENTupleColumnType::kSplitIndex64)) {
391389
EXPECT_EQ(ENTupleColumnType::kSplitIndex64, inspector->GetColumnInspector(colId).GetType());
392390
}
393391

394-
EXPECT_EQ(0U, inspector->GetColumnsByType(ENTupleColumnType::kSplitReal64).size());
392+
EXPECT_EQ(0U, inspector->GetColumnIds(ENTupleColumnType::kSplitReal64).size());
393+
}
394+
395+
TEST(RNTupleInspector, GetColumnIdsRecursive)
396+
{
397+
FileRaii fileGuard("test_ntuple_inspector_column_ids_recursive.root");
398+
{
399+
auto model = RNTupleModel::Create();
400+
auto nFldInt1 = model->MakeField<std::int64_t>("int1");
401+
auto nFldInt2 = model->MakeField<std::int64_t>("int2");
402+
auto nFldFloat = model->MakeField<float>("float");
403+
auto nFldFloatVec = model->MakeField<std::vector<float>>("floatVec");
404+
405+
auto writeOptions = RNTupleWriteOptions();
406+
writeOptions.SetCompression(505);
407+
auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath(), writeOptions);
408+
}
409+
410+
auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
411+
412+
EXPECT_EQ(1U, inspector->GetColumnIdsRecursive(0).size());
413+
EXPECT_EQ(1U, inspector->GetColumnIdsRecursive(1).size());
414+
for (const auto colId : inspector->GetColumnIdsRecursive(0)) {
415+
EXPECT_EQ(ENTupleColumnType::kSplitInt64, inspector->GetColumnInspector(colId).GetType());
416+
}
417+
418+
EXPECT_EQ(1U, inspector->GetColumnIdsRecursive(2).size());
419+
for (const auto colId : inspector->GetColumnIdsRecursive(2)) {
420+
EXPECT_EQ(ENTupleColumnType::kSplitReal32, inspector->GetColumnInspector(colId).GetType());
421+
}
422+
423+
EXPECT_EQ(2U, inspector->GetColumnIdsRecursive(3).size());
424+
}
425+
426+
TEST(RNTupleInspector, GetColumnIds)
427+
{
428+
FileRaii fileGuard("test_ntuple_inspector_column_ids_recursive.root");
429+
{
430+
auto model = RNTupleModel::Create();
431+
auto nFldInt1 = model->MakeField<std::int64_t>("int1");
432+
auto nFldInt2 = model->MakeField<std::int64_t>("int2");
433+
auto nFldFloat = model->MakeField<float>("float");
434+
auto nFldFloatVec = model->MakeField<std::vector<float>>("floatVec");
435+
436+
auto writeOptions = RNTupleWriteOptions();
437+
writeOptions.SetCompression(505);
438+
auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath(), writeOptions);
439+
}
440+
441+
auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
442+
443+
EXPECT_EQ(1U, inspector->GetColumnIds(0).size());
444+
EXPECT_EQ(1U, inspector->GetColumnIds(1).size());
445+
for (const auto colId : inspector->GetColumnIds(0)) {
446+
EXPECT_EQ(ENTupleColumnType::kSplitInt64, inspector->GetColumnInspector(colId).GetType());
447+
}
448+
449+
EXPECT_EQ(1U, inspector->GetColumnIds(2).size());
450+
for (const auto colId : inspector->GetColumnIds(2)) {
451+
EXPECT_EQ(ENTupleColumnType::kSplitReal32, inspector->GetColumnInspector(colId).GetType());
452+
}
453+
EXPECT_EQ(1U, inspector->GetColumnIds(3).size());
395454
}
396455

397456
TEST(RNTupleInspector, ColumnTypes)
@@ -566,7 +625,7 @@ TEST(RNTupleInspector, PageSizeDistribution)
566625

567626
auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
568627

569-
int intColId = inspector->GetColumnsByType(ENTupleColumnType::kSplitInt64)[0];
628+
int intColId = inspector->GetColumnIds(ENTupleColumnType::kSplitInt64)[0];
570629
auto intPageSizeHisto = inspector->GetPageSizeDistribution(intColId);
571630
EXPECT_STREQ("pageSizeHist", intPageSizeHisto->GetName());
572631
EXPECT_STREQ(Form("Page size distribution for column with ID %d", intColId), intPageSizeHisto->GetTitle());
@@ -586,7 +645,7 @@ TEST(RNTupleInspector, PageSizeDistribution)
586645
EXPECT_EQ(100, floatPageSizeHisto->GetNbinsX());
587646
// Make sure that all page sizes are included in the histogram
588647
int nFloatPages = 0;
589-
for (const auto colId : inspector->GetColumnsByType(ENTupleColumnType::kSplitReal32)) {
648+
for (const auto colId : inspector->GetColumnIds(ENTupleColumnType::kSplitReal32)) {
590649
nFloatPages += inspector->GetColumnInspector(colId).GetNPages();
591650
}
592651
EXPECT_EQ(nFloatPages, floatPageSizeHisto->Integral());
@@ -634,7 +693,7 @@ TEST(RNTupleInspector, PageSizeDistribution)
634693
EXPECT_EQ(0, emptyTypeHisto->Integral());
635694

636695
// Requesting a histogram for a column without pages in the given RNTuple should give an empty histogram
637-
auto doubleColumns = inspector->GetColumnsByType(ENTupleColumnType::kSplitReal64);
696+
auto doubleColumns = inspector->GetColumnIds(ENTupleColumnType::kSplitReal64);
638697
ASSERT_EQ(1, doubleColumns.size());
639698
auto emptyColumnHisto = inspector->GetPageSizeDistribution({doubleColumns[0]});
640699
EXPECT_EQ(0, emptyColumnHisto->Integral());

0 commit comments

Comments
 (0)