@@ -224,10 +224,10 @@ namespace edm {
224224 void RootTree::setCacheSize (unsigned int cacheSize) {
225225 cacheSize_ = cacheSize;
226226 tree_->SetCacheSize (static_cast <Long64_t>(cacheSize));
227- treeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead ()));
227+ treeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead (tree_ )));
228228 if (treeCache_)
229229 treeCache_->SetEnablePrefetching (enablePrefetching_);
230- filePtr_->SetCacheRead (nullptr );
230+ filePtr_->SetCacheRead (nullptr , tree_ );
231231 rawTreeCache_.reset ();
232232 }
233233
@@ -245,7 +245,7 @@ namespace edm {
245245 }
246246
247247 void RootTree::setEntryNumber (EntryNumber theEntryNumber) {
248- filePtr_->SetCacheRead (treeCache_.get ());
248+ filePtr_->SetCacheRead (treeCache_.get (), tree_ );
249249
250250 // Detect a backward skip. If the skip is sufficiently large, we roll the dice and reset the treeCache.
251251 // This will cause some amount of over-reading: we pre-fetch all the events in some prior cluster.
@@ -283,7 +283,7 @@ namespace edm {
283283
284284 entryNumber_ = theEntryNumber;
285285 tree_->LoadTree (entryNumber_);
286- filePtr_->SetCacheRead (nullptr );
286+ filePtr_->SetCacheRead (nullptr , tree_ );
287287 if (treeCache_ && trainNow_ && entryNumber_ >= 0 ) {
288288 startTraining ();
289289 trainNow_ = false ;
@@ -337,7 +337,7 @@ namespace edm {
337337 // ROOT will automatically expand the cache to fit one cluster; hence, we use
338338 // 5 MB as the cache size below
339339 tree_->SetCacheSize (static_cast <Long64_t>(5 * 1024 * 1024 ));
340- rawTriggerTreeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead ()));
340+ rawTriggerTreeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead (tree_ )));
341341 if (rawTriggerTreeCache_)
342342 rawTriggerTreeCache_->SetEnablePrefetching (false );
343343 TObjArray* branches = tree_->GetListOfBranches ();
@@ -355,7 +355,7 @@ namespace edm {
355355 }
356356 performedSwitchOver_ = false ;
357357 rawTriggerTreeCache_->StopLearningPhase ();
358- filePtr_->SetCacheRead (nullptr );
358+ filePtr_->SetCacheRead (nullptr , tree_ );
359359
360360 return rawTriggerTreeCache_.get ();
361361 } else if (!performedSwitchOver_ and entryNumber_ < rawTriggerSwitchOverEntry_) {
@@ -370,7 +370,7 @@ namespace edm {
370370
371371 // Train the triggerCache
372372 tree_->SetCacheSize (static_cast <Long64_t>(5 * 1024 * 1024 ));
373- triggerTreeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead ()));
373+ triggerTreeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead (tree_ )));
374374 triggerTreeCache_->SetEnablePrefetching (false );
375375 triggerTreeCache_->SetLearnEntries (0 );
376376 triggerTreeCache_->SetEntryRange (entryNumber, tree_->GetEntries ());
@@ -380,7 +380,7 @@ namespace edm {
380380 triggerTreeCache_->AddBranch (*it, kTRUE );
381381 }
382382 triggerTreeCache_->StopLearningPhase ();
383- filePtr_->SetCacheRead (nullptr );
383+ filePtr_->SetCacheRead (nullptr , tree_ );
384384 }
385385 return triggerTreeCache_.get ();
386386 }
@@ -412,34 +412,34 @@ namespace edm {
412412 }
413413
414414 void RootTree::getEntryForAllBranches () const {
415- filePtr_->SetCacheRead (rawTreeCache_.get ());
415+ filePtr_->SetCacheRead (rawTreeCache_.get (), tree_ );
416416 auto ptr = filePtr_.get ();
417- auto cleanup = [ptr](TTreeCache* cache) { ptr->SetCacheRead (nullptr ); };
417+ auto cleanup = [ptr, tree = tree_ ](TTreeCache* cache) { ptr->SetCacheRead (nullptr , tree ); };
418418 std::unique_ptr<TTreeCache, decltype (cleanup)> cacheGuard (rawTreeCache_.get (), cleanup);
419419 tree_->GetEntry (entryNumber_);
420420 }
421421
422422 void RootTree::getEntry (TBranch* branch, EntryNumber entryNumber) const {
423423 try {
424424 TTreeCache* cache = selectCache (branch, entryNumber);
425- filePtr_->SetCacheRead (cache);
425+ filePtr_->SetCacheRead (cache, tree_ );
426426 branch->GetEntry (entryNumber);
427- filePtr_->SetCacheRead (nullptr );
427+ filePtr_->SetCacheRead (nullptr , tree_ );
428428 } catch (cms::Exception const & e) {
429429 // We make sure the treeCache_ is detached from the file,
430430 // so that ROOT does not also delete it.
431- filePtr_->SetCacheRead (nullptr );
431+ filePtr_->SetCacheRead (nullptr , tree_ );
432432 Exception t (errors::FileReadError, " " , e);
433433 t.addContext (std::string (" Reading branch " ) + branch->GetName ());
434434 throw t;
435435 } catch (std::exception const & e) {
436- filePtr_->SetCacheRead (nullptr );
436+ filePtr_->SetCacheRead (nullptr , tree_ );
437437 Exception t (errors::FileReadError);
438438 t << e.what ();
439439 t.addContext (std::string (" Reading branch " ) + branch->GetName ());
440440 throw t;
441441 } catch (...) {
442- filePtr_->SetCacheRead (nullptr );
442+ filePtr_->SetCacheRead (nullptr , tree_ );
443443 Exception t (errors::FileReadError);
444444 t << " An exception of unknown type was thrown." ;
445445 t.addContext (std::string (" Reading branch " ) + branch->GetName ());
@@ -471,9 +471,8 @@ namespace edm {
471471 assert (!rawTreeCache_);
472472 treeCache_->SetLearnEntries (learningEntries_);
473473 tree_->SetCacheSize (static_cast <Long64_t>(cacheSize_));
474- rawTreeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead ()));
474+ rawTreeCache_.reset (dynamic_cast <TTreeCache*>(filePtr_->GetCacheRead (tree_ )));
475475 rawTreeCache_->SetEnablePrefetching (false );
476- filePtr_->SetCacheRead (nullptr );
477476 rawTreeCache_->SetLearnEntries (0 );
478477 if (promptRead_) {
479478 switchOverEntry_ = entries_;
@@ -491,6 +490,8 @@ namespace edm {
491490 rawTreeCache_->SetEntryRange (rawStart, rawEnd);
492491 rawTreeCache_->AddBranch (" *" , kTRUE );
493492 rawTreeCache_->StopLearningPhase ();
493+ filePtr_->SetCacheRead (nullptr , tree_);
494+
494495 treeCache_->StartLearningPhase ();
495496 treeCache_->SetEntryRange (treeStart, tree_->GetEntries ());
496497 // Make sure that 'branchListIndexes' branch exist in input file
@@ -501,12 +502,13 @@ namespace edm {
501502 trainedSet_.clear ();
502503 triggerSet_.clear ();
503504 assert (treeCache_->GetTree () == tree_);
505+ filePtr_->SetCacheRead (nullptr , tree_);
504506 }
505507
506508 void RootTree::stopTraining () {
507- filePtr_->SetCacheRead (treeCache_.get ());
509+ filePtr_->SetCacheRead (treeCache_.get (), tree_ );
508510 treeCache_->StopLearningPhase ();
509- filePtr_->SetCacheRead (nullptr );
511+ filePtr_->SetCacheRead (nullptr , tree_ );
510512 rawTreeCache_.reset ();
511513 }
512514
@@ -518,7 +520,7 @@ namespace edm {
518520 // We own the treeCache_.
519521 // We make sure the treeCache_ is detached from the file,
520522 // so that ROOT does not also delete it.
521- filePtr_->SetCacheRead (nullptr );
523+ filePtr_->SetCacheRead (nullptr , tree_ );
522524 // We *must* delete the TTreeCache here because the TFilePrefetch object
523525 // references the TFile. If TFile is closed, before the TTreeCache is
524526 // deleted, the TFilePrefetch may continue to do TFile operations, causing
@@ -537,7 +539,7 @@ namespace edm {
537539 }
538540 tree_->LoadTree (0 );
539541 assert (treeCache_);
540- filePtr_->SetCacheRead (treeCache_.get ());
542+ filePtr_->SetCacheRead (treeCache_.get (), tree_ );
541543 treeCache_->StartLearningPhase ();
542544 treeCache_->SetEntryRange (0 , tree_->GetEntries ());
543545 treeCache_->AddBranch (branchNames, kTRUE );
@@ -546,7 +548,7 @@ namespace edm {
546548 // We own the treeCache_.
547549 // We make sure the treeCache_ is detached from the file,
548550 // so that ROOT does not also delete it.
549- filePtr_->SetCacheRead (nullptr );
551+ filePtr_->SetCacheRead (nullptr , tree_ );
550552
551553 if (branchType_ == InEvent) {
552554 // Must also manually add things to the trained set.
@@ -594,7 +596,7 @@ namespace edm {
594596 char const * branchNames) {
595597 tree->LoadTree (0 );
596598 tree->SetCacheSize (cacheSize);
597- std::unique_ptr<TTreeCache> treeCache (dynamic_cast <TTreeCache*>(file.GetCacheRead ()));
599+ std::unique_ptr<TTreeCache> treeCache (dynamic_cast <TTreeCache*>(file.GetCacheRead (tree )));
598600 if (nullptr != treeCache.get ()) {
599601 treeCache->StartLearningPhase ();
600602 treeCache->SetEntryRange (0 , tree->GetEntries ());
@@ -604,7 +606,7 @@ namespace edm {
604606 // We own the treeCache_.
605607 // We make sure the treeCache_ is detached from the file,
606608 // so that ROOT does not also delete it.
607- file.SetCacheRead (nullptr );
609+ file.SetCacheRead (nullptr , tree );
608610 return treeCache;
609611 }
610612 } // namespace roottree
0 commit comments