Skip to content

Commit 709119f

Browse files
[ntuple] Add GetColumnIds methods in Inspector
GetColumnsByFieldId -> GetColumnIdsRecursive, GetColumnsByType -> GetColumnIds
1 parent 9b42f54 commit 709119f

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ 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;
281281

282282
/////////////////////////////////////////////////////////////////////////////
283283
/// \brief Get all column types present in the RNTuple being inspected.

tree/ntupleutil/v7/src/RNTupleInspector.cxx

Lines changed: 3 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};
@@ -203,8 +203,7 @@ size_t ROOT::Experimental::RNTupleInspector::GetColumnCountByType(ROOT::ENTupleC
203203
return typeCount;
204204
}
205205

206-
std::vector<ROOT::DescriptorId_t>
207-
ROOT::Experimental::RNTupleInspector::GetColumnsByType(ROOT::ENTupleColumnType colType)
206+
std::vector<ROOT::DescriptorId_t> ROOT::Experimental::RNTupleInspector::GetColumnIds(ROOT::ENTupleColumnType colType)
208207
{
209208
std::vector<ROOT::DescriptorId_t> colIds;
210209

@@ -419,7 +418,7 @@ ROOT::Experimental::RNTupleInspector::GetPageSizeDistribution(std::initializer_l
419418
}
420419

421420
for (const auto colType : colTypeVec) {
422-
auto colIds = GetColumnsByType(colType);
421+
auto colIds = GetColumnIds(colType);
423422

424423
if (colIds.empty())
425424
continue;

tree/ntupleutil/v7/test/ntuple_inspector.cxx

Lines changed: 43 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,53 @@ 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());
395424
}
396425

397426
TEST(RNTupleInspector, ColumnTypes)
@@ -566,7 +595,7 @@ TEST(RNTupleInspector, PageSizeDistribution)
566595

567596
auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
568597

569-
int intColId = inspector->GetColumnsByType(ENTupleColumnType::kSplitInt64)[0];
598+
int intColId = inspector->GetColumnIds(ENTupleColumnType::kSplitInt64)[0];
570599
auto intPageSizeHisto = inspector->GetPageSizeDistribution(intColId);
571600
EXPECT_STREQ("pageSizeHist", intPageSizeHisto->GetName());
572601
EXPECT_STREQ(Form("Page size distribution for column with ID %d", intColId), intPageSizeHisto->GetTitle());
@@ -586,7 +615,7 @@ TEST(RNTupleInspector, PageSizeDistribution)
586615
EXPECT_EQ(100, floatPageSizeHisto->GetNbinsX());
587616
// Make sure that all page sizes are included in the histogram
588617
int nFloatPages = 0;
589-
for (const auto colId : inspector->GetColumnsByType(ENTupleColumnType::kSplitReal32)) {
618+
for (const auto colId : inspector->GetColumnIds(ENTupleColumnType::kSplitReal32)) {
590619
nFloatPages += inspector->GetColumnInspector(colId).GetNPages();
591620
}
592621
EXPECT_EQ(nFloatPages, floatPageSizeHisto->Integral());
@@ -634,7 +663,7 @@ TEST(RNTupleInspector, PageSizeDistribution)
634663
EXPECT_EQ(0, emptyTypeHisto->Integral());
635664

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

0 commit comments

Comments
 (0)