Skip to content

[tree] avoid resetting index in entry list copy constructor #19039

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tree/tree/src/TEntryList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ TEntryList::TEntryList(const TEntryList &elist) : TNamed(elist)
fFileName = elist.fFileName;
fStringHash = elist.fStringHash;
fTreeNumber = elist.fTreeNumber;
fLastIndexQueried = -1;
fLastIndexReturned = 0;
fLastIndexQueried = elist.fLastIndexQueried;
fLastIndexReturned = elist.fLastIndexReturned;
Comment on lines +290 to +291
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit surprising changing for the usual starting point to the previously visited entry fixes the problem. Those 2 data members are meant to be accelerator and so the default value should have been fine. ... What is the mechanism leading to the failure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it was an empirical fix. Without this, the returned value is PreviousVisitedEntry + 1, so 16 even if Index is -1
It seems as if the variable index is -1 but the entry pointer is still at 15.

fN = elist.fN;
fShift = elist.fShift;
fLists = nullptr;
Expand Down
59 changes: 59 additions & 0 deletions tree/tree/test/entrylist_addsublist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "TFile.h"
#include "TSystem.h"
#include "TTree.h"
#include "TChain.h"

#include "gtest/gtest.h"

Expand Down Expand Up @@ -66,3 +67,61 @@ TEST(TEntryList, addSubList) {
gSystem->Unlink(filename1);
gSystem->Unlink(filename2);
}

TEST(TEntryList, copySubList)
{
auto filename1{"entrylist_copysublist_tree1.root"};
auto filename2{"entrylist_copysublist_tree2.root"};
auto treename{"t"};
int x = 0;
for (auto filename : {filename1, filename2}) {
TFile f(filename, "RECREATE");
TTree t(treename, treename);
t.Branch("x", &x);
t.Fill();
++x;
t.Fill();
++x;
f.Write();
f.Close();
}
{
TEntryList l1("l1", "l1", treename, filename1);
l1.Enter(0);
l1.Enter(1);
TEntryList l2("l2", "l2", treename, filename2);
l2.Enter(1);
TEntryList l;
l.Add(&l1);
l.Add(&l2);
TChain c(treename);
for (auto filename : {filename1, filename2})
c.Add(filename);
c.SetEntryList(&l);

int treenum;
auto value = l.GetEntryAndTree(0, treenum);
EXPECT_EQ(value, 0);
EXPECT_EQ(treenum, 0);
value = l.GetEntryAndTree(1, treenum);
EXPECT_EQ(value, 1);
EXPECT_EQ(treenum, 0);
value = l.GetEntryAndTree(2, treenum);
EXPECT_EQ(value, 1);
EXPECT_EQ(treenum, 1);

TEntryList lcopy(l);
value = lcopy.GetEntryAndTree(0, treenum);
EXPECT_EQ(value, 0);
EXPECT_EQ(treenum, 0);
value = lcopy.GetEntryAndTree(1, treenum);
EXPECT_EQ(value, 1);
EXPECT_EQ(treenum, 0);
value = lcopy.GetEntryAndTree(2, treenum);
EXPECT_EQ(value, 1);
EXPECT_EQ(treenum, 1);
}

for (auto filename : {filename1, filename2})
gSystem->Unlink(filename);
}
Loading