Skip to content
Snippets Groups Projects
Commit 54f9d581 authored by Jakob Blomer's avatar Jakob Blomer
Browse files

[ntuple] improve view iteration interface

parent 7eead68c
No related branches found
No related tags found
No related merge requests found
...@@ -133,7 +133,7 @@ public: ...@@ -133,7 +133,7 @@ public:
} }
} }
RNTupleGlobalRange GetViewRange() { return RNTupleGlobalRange(0, GetNEntries()); } RNTupleGlobalRange GetEntryRange() { return RNTupleGlobalRange(0, GetNEntries()); }
/// Provides access to an individual field that can contain either a scalar value or a collection, e.g. /// Provides access to an individual field that can contain either a scalar value or a collection, e.g.
/// GetView<double>("particles.pt") or GetView<std::vector<double>>("particle"). It can as well be the index /// GetView<double>("particles.pt") or GetView<std::vector<double>>("particle"). It can as well be the index
......
...@@ -291,14 +291,14 @@ public: ...@@ -291,14 +291,14 @@ public:
RNTupleViewCollection& operator=(RNTupleViewCollection&& other) = default; RNTupleViewCollection& operator=(RNTupleViewCollection&& other) = default;
~RNTupleViewCollection() = default; ~RNTupleViewCollection() = default;
RNTupleClusterRange GetViewRange(NTupleSize_t globalIndex) { RNTupleClusterRange GetCollectionRange(NTupleSize_t globalIndex) {
ClusterSize_t size; ClusterSize_t size;
RClusterIndex collectionStart; RClusterIndex collectionStart;
fField.GetCollectionInfo(globalIndex, &collectionStart, &size); fField.GetCollectionInfo(globalIndex, &collectionStart, &size);
return RNTupleClusterRange(collectionStart.GetClusterId(), collectionStart.GetIndex(), return RNTupleClusterRange(collectionStart.GetClusterId(), collectionStart.GetIndex(),
collectionStart.GetIndex() + size); collectionStart.GetIndex() + size);
} }
RNTupleClusterRange GetViewRange(const RClusterIndex &clusterIndex) { RNTupleClusterRange GetCollectionRange(const RClusterIndex &clusterIndex) {
ClusterSize_t size; ClusterSize_t size;
RClusterIndex collectionStart; RClusterIndex collectionStart;
fField.GetCollectionInfo(clusterIndex, &collectionStart, &size); fField.GetCollectionInfo(clusterIndex, &collectionStart, &size);
......
...@@ -152,7 +152,7 @@ TEST(RNTuple, Multi) ...@@ -152,7 +152,7 @@ TEST(RNTuple, Multi)
RNTupleReader ntupleFirst(std::make_unique<RPageSourceFile>("first", fileGuard.GetPath(), RNTupleReadOptions())); RNTupleReader ntupleFirst(std::make_unique<RPageSourceFile>("first", fileGuard.GetPath(), RNTupleReadOptions()));
auto viewPt = ntupleFirst.GetView<float>("pt"); auto viewPt = ntupleFirst.GetView<float>("pt");
int n = 0; int n = 0;
for (auto i : ntupleFirst.GetViewRange()) { for (auto i : ntupleFirst.GetEntryRange()) {
EXPECT_EQ(42.0, viewPt(i)); EXPECT_EQ(42.0, viewPt(i));
n++; n++;
} }
...@@ -161,7 +161,7 @@ TEST(RNTuple, Multi) ...@@ -161,7 +161,7 @@ TEST(RNTuple, Multi)
RNTupleReader ntupleSecond(std::make_unique<RPageSourceFile>("second", fileGuard.GetPath(), RNTupleReadOptions())); RNTupleReader ntupleSecond(std::make_unique<RPageSourceFile>("second", fileGuard.GetPath(), RNTupleReadOptions()));
auto viewE = ntupleSecond.GetView<float>("E"); auto viewE = ntupleSecond.GetView<float>("E");
n = 0; n = 0;
for (auto i : ntupleSecond.GetViewRange()) { for (auto i : ntupleSecond.GetEntryRange()) {
EXPECT_EQ(1.0, viewE(i)); EXPECT_EQ(1.0, viewE(i));
n++; n++;
} }
...@@ -255,7 +255,7 @@ TEST(RNTuple, ClassVector) ...@@ -255,7 +255,7 @@ TEST(RNTuple, ClassVector)
auto viewKlass = viewKlassVec.GetView<CustomStruct>("CustomStruct"); auto viewKlass = viewKlassVec.GetView<CustomStruct>("CustomStruct");
auto viewKlassA = viewKlassVec.GetView<float>("CustomStruct.a"); auto viewKlassA = viewKlassVec.GetView<float>("CustomStruct.a");
for (auto entryId : ntuple.GetViewRange()) { for (auto entryId : ntuple.GetEntryRange()) {
EXPECT_EQ(42.0, viewKlass(entryId).a); EXPECT_EQ(42.0, viewKlass(entryId).a);
EXPECT_EQ(2.0, viewKlass(entryId).v1[0]); EXPECT_EQ(2.0, viewKlass(entryId).v1[0]);
EXPECT_EQ(42.0, viewKlassA(entryId)); EXPECT_EQ(42.0, viewKlassA(entryId));
...@@ -494,7 +494,7 @@ TEST(RNTuple, View) ...@@ -494,7 +494,7 @@ TEST(RNTuple, View)
RNTupleReader ntuple(std::make_unique<RPageSourceFile>("myNTuple", fileGuard.GetPath(), RNTupleReadOptions())); RNTupleReader ntuple(std::make_unique<RPageSourceFile>("myNTuple", fileGuard.GetPath(), RNTupleReadOptions()));
auto viewPt = ntuple.GetView<float>("pt"); auto viewPt = ntuple.GetView<float>("pt");
int n = 0; int n = 0;
for (auto i : ntuple.GetViewRange()) { for (auto i : ntuple.GetEntryRange()) {
EXPECT_EQ(42.0, viewPt(i)); EXPECT_EQ(42.0, viewPt(i));
n++; n++;
} }
...@@ -502,7 +502,7 @@ TEST(RNTuple, View) ...@@ -502,7 +502,7 @@ TEST(RNTuple, View)
auto viewJets = ntuple.GetView<std::vector<float>>("jets"); auto viewJets = ntuple.GetView<std::vector<float>>("jets");
n = 0; n = 0;
for (auto i : ntuple.GetViewRange()) { for (auto i : ntuple.GetEntryRange()) {
if (i == 0) { if (i == 0) {
EXPECT_EQ(2U, viewJets(i).size()); EXPECT_EQ(2U, viewJets(i).size());
EXPECT_EQ(1.0, viewJets(i)[0]); EXPECT_EQ(1.0, viewJets(i)[0]);
...@@ -567,16 +567,16 @@ TEST(RNTuple, Composable) ...@@ -567,16 +567,16 @@ TEST(RNTuple, Composable)
auto viewHitY = viewHits.GetView<float>("y"); auto viewHitY = viewHits.GetView<float>("y");
int nEv = 0; int nEv = 0;
for (auto e : ntuple->GetViewRange()) { for (auto e : ntuple->GetEntryRange()) {
EXPECT_EQ(float(nEv), viewPt(e)); EXPECT_EQ(float(nEv), viewPt(e));
EXPECT_EQ(3U, viewTracks(e)); EXPECT_EQ(3U, viewTracks(e));
int nTr = 0; int nTr = 0;
for (auto t : viewTracks.GetViewRange(e)) { for (auto t : viewTracks.GetCollectionRange(e)) {
EXPECT_EQ(nEv * nTr, viewTrackEnergy(t)); EXPECT_EQ(nEv * nTr, viewTrackEnergy(t));
EXPECT_EQ(2.0, viewHits(t)); EXPECT_EQ(2.0, viewHits(t));
for (auto h : viewHits.GetViewRange(t)) { for (auto h : viewHits.GetCollectionRange(t)) {
EXPECT_EQ(4.0, viewHitX(h)); EXPECT_EQ(4.0, viewHitX(h));
EXPECT_EQ(8.0, viewHitY(h)); EXPECT_EQ(8.0, viewHitY(h));
} }
...@@ -891,7 +891,7 @@ TEST(RNTuple, LargeFile) ...@@ -891,7 +891,7 @@ TEST(RNTuple, LargeFile)
auto rdEnergy = ntuple->GetView<double>("energy"); auto rdEnergy = ntuple->GetView<double>("energy");
double chksumRead = 0.0; double chksumRead = 0.0;
for (auto i : ntuple->GetViewRange()) { for (auto i : ntuple->GetEntryRange()) {
chksumRead += rdEnergy(i); chksumRead += rdEnergy(i);
} }
......
...@@ -106,7 +106,7 @@ void ntpl003_lhcbOpenData() ...@@ -106,7 +106,7 @@ void ntpl003_lhcbOpenData()
TH1F h("h", "B Flight Distance", 200, 0, 140); TH1F h("h", "B Flight Distance", 200, 0, 140);
h.SetFillColor(48); h.SetFillColor(48);
for (auto i : ntuple->GetViewRange()) { for (auto i : ntuple->GetEntryRange()) {
// Note that we do not load an entry in this loop, i.e. we avoid the memory copy of loading the data into // Note that we do not load an entry in this loop, i.e. we avoid the memory copy of loading the data into
// the memory location given by the entry // the memory location given by the entry
h.Fill(viewFlightDistance(i)); h.Fill(viewFlightDistance(i));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment