Skip to content
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
6 changes: 6 additions & 0 deletions tree/tree/inc/TTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ class TTree : public TNamed, public TAttLine, public TAttFill, public TAttMarker
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype,
bool isptr, bool suppressMissingBranchError);

TBranch *FindBranchFromSelf(const char *branchName);
TBranch *FindBranchFromFriends(const char *branchName);

TLeaf *GetLeafFromSelf(const char *branchName, const char *leafName);
TLeaf *GetLeafFromFriends(const char *branchName, const char *leafName);

class TFriendLock {
// Helper class to prevent infinite recursion in the
// usage of TTree Friends. Implemented in TTree.cxx.
Expand Down
150 changes: 100 additions & 50 deletions tree/tree/src/TChain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1139,69 +1139,119 @@ TObjArray* TChain::GetListOfLeaves()

Double_t TChain::GetMaximum(const char* columname)
{
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;
constexpr auto errVal{std::numeric_limits<Double_t>::lowest()};

// If the requested column is in this TTree, compute the maximum value directly
if (auto *leaf = GetLeafFromSelf(nullptr, columname)) {
// Ensure the TTree cursor is brought back to the current entry after computing the value
struct CurrentEntryRAII {

Long64_t fCurrentEntry;
TTree &fTree;

CurrentEntryRAII(TTree &tree) : fCurrentEntry(tree.GetReadEntry()), fTree(tree) {}

~CurrentEntryRAII() { fTree.GetEntry(fCurrentEntry); }
} raii{*this};

TBranch *branch = nullptr;
Int_t treenumber = -1;
double cmax{errVal};
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 = GetLeafFromSelf(nullptr, columname);
if (leaf)
branch = leaf->GetBranch();
}
if (!branch)
continue;
treenumber = this->GetTreeNumber();
branch->GetEntry(localEntryNumber);
for (Int_t j = 0; j < leaf->GetLen(); ++j) {
Double_t val = leaf->GetValue(j);
if (val > cmax) {
cmax = val;
}
}
}
return cmax;
}
return cmax;

// If there are any friends, look for the requested column name. If it is
// found in a friend, dispatch the calculation to the friend itself.
if (fFriends)
for (auto *frEl : TRangeDynCast<TFriendElement>(fFriends))
if (auto *tree = frEl->GetTree())
if (tree->GetLeaf(columname))
return tree->GetMaximum(columname);

return errVal;
}

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

Double_t TChain::GetMinimum(const char* columname)
{
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;
constexpr auto errVal{std::numeric_limits<Double_t>::max()};

// If the requested column is in this TTree, compute the minimum value directly
if (auto *leaf = GetLeafFromSelf(nullptr, columname)) {
// Ensure the TTree cursor is brought back to the current entry after computing the value
struct CurrentEntryRAII {

Long64_t fCurrentEntry;
TTree &fTree;

CurrentEntryRAII(TTree &tree) : fCurrentEntry(tree.GetReadEntry()), fTree(tree) {}

~CurrentEntryRAII() { fTree.GetEntry(fCurrentEntry); }
} raii{*this};

TBranch *branch = nullptr;
Int_t treenumber = -1;
double cmin{errVal};
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 = GetLeafFromSelf(nullptr, columname);
if (leaf)
branch = leaf->GetBranch();
}
if (!branch)
continue;
treenumber = this->GetTreeNumber();
branch->GetEntry(localEntryNumber);
for (Int_t j = 0; j < leaf->GetLen(); ++j) {
Double_t val = leaf->GetValue(j);
if (val < cmin) {
cmin = val;
}
}
}
return cmin;
}
return cmin;

// If there are any friends, look for the requested column name. If it is
// found in a friend, dispatch the calculation to the friend itself.
if (fFriends)
for (auto *frEl : TRangeDynCast<TFriendElement>(fFriends))
if (auto *tree = frEl->GetTree())
if (tree->GetLeaf(columname))
return tree->GetMinimum(columname);

return errVal;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading
Loading