Skip to content
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

[tree] Respect TChain's entryList when GetMinimum/Maximum v2 #17790

Open
wants to merge 2 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
68 changes: 52 additions & 16 deletions tree/tree/src/TChain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1168,33 +1168,69 @@ TObjArray* TChain::GetListOfLeaves()

Double_t TChain::GetMaximum(const char* columname)
{
Double_t theMax = -DBL_MAX;
for (Int_t file = 0; file < fNtrees; file++) {
Long64_t first = fTreeOffset[file];
LoadTree(first);
Double_t curmax = fTree->GetMaximum(columname);
if (curmax > theMax) {
theMax = curmax;
Double_t cmax = -DBL_MAX;
TLeaf *leaf = nullptr;
TBranch *branch = nullptr;
Int_t treenumber = -1;
for (Long64_t i = 0; i < fEntries; ++i) {
Long64_t entryNumber = this->GetEntryNumber(i);
if (entryNumber < 0)
break;
Long64_t localEntryNumber = this->LoadTree(entryNumber);
if (localEntryNumber < 0)
break;
if (treenumber != this->GetTreeNumber()) {
leaf = this->GetLeaf(columname);
if (leaf)
branch = leaf->GetBranch();
}
treenumber = this->GetTreeNumber();
if (!branch)
continue;
branch->GetEntry(localEntryNumber);
for (Int_t j = 0; j < leaf->GetLen(); ++j) {
Double_t val = leaf->GetValue(j);
if (val > cmax) {
cmax = val;
}
}
}
return theMax;
return cmax;
}

////////////////////////////////////////////////////////////////////////////////
/// Return minimum of column with name columname.

Double_t TChain::GetMinimum(const char* columname)
{
Double_t theMin = DBL_MAX;
for (Int_t file = 0; file < fNtrees; file++) {
Long64_t first = fTreeOffset[file];
LoadTree(first);
Double_t curmin = fTree->GetMinimum(columname);
if (curmin < theMin) {
theMin = curmin;
Double_t cmin = DBL_MAX;
TLeaf *leaf = nullptr;
TBranch *branch = nullptr;
Int_t treenumber = -1;
for (Long64_t i = 0; i < fEntries; ++i) {
Long64_t entryNumber = this->GetEntryNumber(i);
if (entryNumber < 0)
break;
Long64_t localEntryNumber = this->LoadTree(entryNumber);
if (localEntryNumber < 0)
break;
if (treenumber != this->GetTreeNumber()) {
leaf = this->GetLeaf(columname);
if (leaf)
branch = leaf->GetBranch();
}
treenumber = this->GetTreeNumber();
if (!branch)
continue;
branch->GetEntry(localEntryNumber);
for (Int_t j = 0; j < leaf->GetLen(); ++j) {
Double_t val = leaf->GetValue(j);
if (val < cmin) {
cmin = val;
}
}
}
return theMin;
return cmin;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
49 changes: 48 additions & 1 deletion tree/tree/test/TChainRegressions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <TFile.h>
#include <TSystem.h>
#include <TTree.h>

#include <TEntryList.h>
#include <TDirectory.h>

#include "gtest/gtest.h"

class TTreeCache;
Expand Down Expand Up @@ -30,3 +32,48 @@ TEST(TChain, GetReadCacheBug)

gSystem->Unlink(filename);
}

// ROOT-7097, ROOT-8505
TEST(TChain, GetMinMaxEntryList)
{
std::unique_ptr<TFile> file1(TFile::Open("t1_7067.root", "RECREATE"));
TTree t1("t", "");
int value;
t1.Branch("value", &value);
value = 0;
t1.Fill();
value = 1;
t1.Fill();
value = 2;
t1.Fill();
value = 3;
t1.Fill();
file1->Write();
file1->Close();

std::unique_ptr<TFile> file2(TFile::Open("t2_7067.root", "RECREATE"));
TTree t2("t", "");
// int value;
t2.Branch("value", &value);
value = 10;
t2.Fill();
value = 11;
t2.Fill();
value = 12;
t2.Fill();
value = 13;
t2.Fill();
file2->Write();
file2->Close();

TChain ch("t");
ch.AddFile("t1_7067.root");
ch.AddFile("t2_7067.root");
EXPECT_FLOAT_EQ(ch.GetMinimum("value"), 0.);
EXPECT_FLOAT_EQ(ch.GetMaximum("value"), 13.);
ch.Draw(">>myList", "value<11 && value >1", "entrylist");
TEntryList *myList = static_cast<TEntryList *>(gDirectory->Get("myList"));
ch.SetEntryList(myList);
EXPECT_FLOAT_EQ(ch.GetMinimum("value"), 2.);
EXPECT_FLOAT_EQ(ch.GetMaximum("value"), 10.);
}
Loading