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

TTreeCache::FillBuffer Updates #2787

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion io/io/inc/TFile.h
Expand Up @@ -204,7 +204,7 @@ class TFile : public TDirectoryFile {
Long64_t GetArchiveOffset() const { return fArchiveOffset; }
Int_t GetBestBuffer() const;
virtual Int_t GetBytesToPrefetch() const;
TFileCacheRead *GetCacheRead(TObject* tree = 0) const;
TFileCacheRead *GetCacheRead(const TObject* tree = 0) const;
TFileCacheWrite *GetCacheWrite() const;
TArrayC *GetClassIndex() const { return fClassIndex; }
Int_t GetCompressionAlgorithm() const;
Expand Down
2 changes: 1 addition & 1 deletion io/io/src/TFile.cxx
Expand Up @@ -1213,7 +1213,7 @@ void TFile::ResetErrno() const
////////////////////////////////////////////////////////////////////////////////
/// Return a pointer to the current read cache.

TFileCacheRead *TFile::GetCacheRead(TObject* tree) const
TFileCacheRead *TFile::GetCacheRead(const TObject* tree) const
{
if (!tree) {
if (!fCacheRead && fCacheReadMap->GetSize() == 1) {
Expand Down
3 changes: 2 additions & 1 deletion tree/tree/inc/TTree.h
Expand Up @@ -159,7 +159,6 @@ class TTree : public TNamed, public TAttLine, public TAttFill, public TAttMarker

Long64_t GetCacheAutoSize(Bool_t withDefault = kFALSE) const;
char GetNewlineValue(std::istream &inputStream);
TTreeCache *GetReadCache(TFile *file, Bool_t create = kFALSE);
void ImportClusterRanges(TTree *fromtree);
void MoveReadCache(TFile *src, TDirectory *dir);
Int_t SetCacheSizeAux(Bool_t autocache = kTRUE, Long64_t cacheSize = 0);
Expand Down Expand Up @@ -426,6 +425,8 @@ class TTree : public TNamed, public TAttLine, public TAttFill, public TAttMarker
TVirtualTreePlayer *GetPlayer();
virtual Int_t GetPacketSize() const { return fPacketSize; }
virtual TVirtualPerfStats *GetPerfStats() const { return fPerfStats; }
TTreeCache *GetReadCache(TFile *file) const;
TTreeCache *GetReadCache(TFile *file, Bool_t create);
virtual Long64_t GetReadEntry() const { return fReadEntry; }
virtual Long64_t GetReadEvent() const { return fReadEntry; }
virtual Int_t GetScanField() const { return fScanField; }
Expand Down
4 changes: 2 additions & 2 deletions tree/tree/src/TBasket.cxx
Expand Up @@ -251,7 +251,7 @@ Int_t TBasket::LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tr
fBufferRef->SetParent(file);
char *buffer = fBufferRef->Buffer();
file->Seek(pos);
TFileCacheRead *pf = file->GetCacheRead(tree);
TFileCacheRead *pf = tree->GetReadCache(file);
if (pf) {
TVirtualPerfStats* temp = gPerfStats;
if (tree->GetPerfStats()) gPerfStats = tree->GetPerfStats();
Expand Down Expand Up @@ -465,7 +465,7 @@ Int_t TBasket::ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file)
TFileCacheRead *pf = nullptr;
{
R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
pf = file->GetCacheRead(fBranch->GetTree());
pf = fBranch->GetTree()->GetReadCache(file);
}
if (pf) {
Int_t res = -1;
Expand Down
2 changes: 1 addition & 1 deletion tree/tree/src/TBranch.cxx
Expand Up @@ -1208,7 +1208,7 @@ TBasket* TBranch::GetBasket(Int_t basketnumber)
//add branch to cache (if any)
{
R__LOCKGUARD_IMT(gROOTMutex); // Lock for parallel TTree I/O
TFileCacheRead *pf = file->GetCacheRead(fTree);
TFileCacheRead *pf = fTree->GetReadCache(file);
if (pf){
if (pf->IsLearning()) pf->AddBranch(this);
if (fSkipZip) pf->SetSkipZip();
Expand Down
9 changes: 5 additions & 4 deletions tree/tree/src/TChain.cxx
Expand Up @@ -191,8 +191,9 @@ TChain::~TChain()
fFiles = 0;

//first delete cache if exists
if (fFile && fFile->GetCacheRead(fTree)) {
delete fFile->GetCacheRead(fTree);
auto tc = fFile ? fTree->GetReadCache(fFile) : nullptr;
if (tc) {
delete tc;
fFile->SetCacheRead(0, fTree);
}

Expand Down Expand Up @@ -1421,10 +1422,10 @@ Long64_t TChain::LoadTree(Long64_t entry)
// to see if a TTree is already loaded.
// However, this prevent using the following to reuse
// the TTreeCache object.
tpf = (TTreeCache*) fFile->GetCacheRead(fTree);
tpf = fTree->GetReadCache(fFile);
if (tpf) {
tpf->ResetCache();
}
}

fFile->SetCacheRead(0, fTree);
// If the tree has clones, copy them into the chain
Expand Down
21 changes: 16 additions & 5 deletions tree/tree/src/TTree.cxx
Expand Up @@ -591,7 +591,7 @@ Long64_t TTree::TClusterIterator::GetEstimatedClusterSize()
// Humm ... let's double check on the file.
TFile *file = fTree->GetCurrentFile();
if (file) {
TFileCacheRead *cache = file->GetCacheRead(fTree);
TFileCacheRead *cache = fTree->GetReadCache(file);
if (cache) {
cacheSize = cache->GetBufferSize();
}
Expand Down Expand Up @@ -6030,15 +6030,26 @@ TVirtualTreePlayer* TTree::GetPlayer()
return fPlayer;
}

////////////////////////////////////////////////////////////////////////////////
/// Find and return the TTreeCache registered with the file and which may
/// contain branches for us.

TTreeCache *TTree::GetReadCache(TFile *file) const
{
TTreeCache *pe = dynamic_cast<TTreeCache*>(file->GetCacheRead(this));
if (pe && pe->GetTree() != this)
pe = nullptr;
return pe;
}

////////////////////////////////////////////////////////////////////////////////
/// Find and return the TTreeCache registered with the file and which may
/// contain branches for us. If create is true and there is no cache
/// a new cache is created with default size.

TTreeCache *TTree::GetReadCache(TFile *file, Bool_t create /* = kFALSE */ )
TTreeCache *TTree::GetReadCache(TFile *file, Bool_t create)
{
TTreeCache *pe = dynamic_cast<TTreeCache*>(file->GetCacheRead(this));
if (pe && pe->GetTree() != this) pe = 0;
TTreeCache *pe = GetReadCache(file);
if (create && !pe) {
if (fCacheDoAutoInit)
SetCacheSizeAux(kTRUE, -1);
Expand Down Expand Up @@ -7033,7 +7044,7 @@ void TTree::PrintCacheStats(Option_t* option) const
{
TFile *f = GetCurrentFile();
if (!f) return;
TTreeCache *tc = (TTreeCache*)f->GetCacheRead(const_cast<TTree*>(this));
TTreeCache *tc = GetReadCache(f);
if (tc) tc->Print(option);
}

Expand Down
11 changes: 9 additions & 2 deletions tree/tree/src/TTreeCache.cxx
Expand Up @@ -1060,6 +1060,9 @@ Bool_t TTreeCache::FillBuffer()
Long64_t entry = tree->GetReadEntry();
Long64_t fEntryCurrentMax = 0;

if (entry < fEntryMin || fEntryMax < entry)
return kFALSE;

if (fEnablePrefetching) { // Prefetching mode
if (fIsLearning) { // Learning mode
if (fEntryNext >= 0 && entry >= fEntryNext) {
Expand Down Expand Up @@ -1220,7 +1223,7 @@ Bool_t TTreeCache::FillBuffer()
if (fCurrentClusterStart != -1 || fNextClusterStart != -1) {
if (!(fEntryCurrent < fCurrentClusterStart || fEntryCurrent >= fNextClusterStart)) {
Error("FillBuffer", "Inconsistency: fCurrentClusterStart=%lld fEntryCurrent=%lld fNextClusterStart=%lld "
"but fCurrentEntry should not be in between the two",
"but fEntryCurrent should not be in between the two",
fCurrentClusterStart, fEntryCurrent, fNextClusterStart);
}
}
Expand Down Expand Up @@ -1519,7 +1522,7 @@ Bool_t TTreeCache::FillBuffer()
b->fCacheInfo.SetIsInCache(j);

if (showMore || gDebug > 6)
Info("FillBuffer", "*** Registering branch %d basket %d", i, j);
Info("FillBuffer", "*** Registering branch %d basket %d %s", i, j, b->GetName());

if (!cursor[i].fLoadedOnce) {
cursor[i].fLoadedOnce = kTRUE;
Expand Down Expand Up @@ -2179,6 +2182,8 @@ void TTreeCache::LearnPrefill()
Long64_t emaxOld = fEntryMax;
Long64_t ecurrentOld = fEntryCurrent;
Long64_t enextOld = fEntryNext;
auto currentClusterStartOld = fCurrentClusterStart;
auto nextClusterStartOld = fNextClusterStart;

fEntryMin = fEntryCurrent;
fEntryMax = fEntryNext;
Expand All @@ -2200,4 +2205,6 @@ void TTreeCache::LearnPrefill()
fEntryMax = emaxOld;
fEntryCurrent = ecurrentOld;
fEntryNext = enextOld;
fCurrentClusterStart = currentClusterStartOld;
fNextClusterStart = nextClusterStartOld;
}
3 changes: 2 additions & 1 deletion tree/tree/src/TTreeCloner.cxx
Expand Up @@ -34,6 +34,7 @@ Class implementing or helping the various TTree cloning method
#include "TLeafO.h"
#include "TLeafC.h"
#include "TFileCacheRead.h"
#include "TTreeCache.h"

#include <algorithm>

Expand Down Expand Up @@ -561,7 +562,7 @@ void TTreeCloner::CreateCache()
{
if (fCacheSize && fFromTree->GetCurrentFile()) {
TFile *f = fFromTree->GetCurrentFile();
auto prev = f->GetCacheRead(fFromTree);
auto prev = fFromTree->GetReadCache(f);
if (fFileCache && prev == fFileCache) {
return;
}
Expand Down