@@ -10,6 +10,8 @@ Holder for an input TFile.
1010#include " FWCore/Utilities/interface/propagate_const.h"
1111
1212#include " TFile.h"
13+ #include " TTree.h"
14+ #include " TTreeCache.h"
1315
1416#include < map>
1517#include < string>
@@ -46,8 +48,33 @@ namespace edm {
4648 static void reportReadBranch (InputType inputType, std::string const & branchname);
4749
4850 TObject* Get (char const * name) { return file_->Get (name); }
49- TFileCacheRead* GetCacheRead () const { return file_->GetCacheRead (); }
50- void SetCacheRead (TFileCacheRead* tfcr) { file_->SetCacheRead (tfcr, nullptr , TFile::kDoNotDisconnect ); }
51+ std::unique_ptr<TTreeCache> createCacheWithSize (TTree& iTree, unsigned int cacheSize) {
52+ iTree.SetCacheSize (static_cast <Long64_t>(cacheSize));
53+ std::unique_ptr<TTreeCache> newCache (dynamic_cast <TTreeCache*>(file_->GetCacheRead (&iTree)));
54+ file_->SetCacheRead (nullptr , &iTree, TFile::kDoNotDisconnect );
55+ return newCache;
56+ }
57+
58+ class CacheGuard {
59+ public:
60+ CacheGuard (TFile* file, TObject* tree, TFileCacheRead* tfcr) : file_(file), tree_(tree) {
61+ file_->SetCacheRead (tfcr, tree_, TFile::kDoNotDisconnect );
62+ }
63+ CacheGuard () = delete ;
64+ CacheGuard (CacheGuard const &) = delete ;
65+ CacheGuard& operator =(CacheGuard const &) = delete ;
66+ CacheGuard (CacheGuard&&) = delete ;
67+ CacheGuard& operator =(CacheGuard&&) = delete ;
68+ ~CacheGuard () { file_->SetCacheRead (nullptr , tree_, TFile::kDoNotDisconnect ); }
69+
70+ private:
71+ TFile* file_;
72+ TObject* tree_;
73+ };
74+ [[nodiscard]] CacheGuard setCacheReadTemporarily (TFileCacheRead* tfcr, TObject* iTree) {
75+ return CacheGuard (file_.get (), iTree, tfcr);
76+ }
77+ void clearCacheRead (TObject* iTree) { file_->SetCacheRead (nullptr , iTree, TFile::kDoNotDisconnect ); }
5178 void logFileAction (char const * msg, char const * fileName) const ;
5279
5380 private:
0 commit comments