Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:20

0001 #include "FWTTreeCache.h"
0002 
0003 #include "TChain.h"
0004 #include "TTree.h"
0005 #include "TEventList.h"
0006 
0007 #include <climits>
0008 
0009 FWTTreeCache::FWTTreeCache() : TTreeCache() {}
0010 
0011 FWTTreeCache::FWTTreeCache(TTree *tree, Int_t buffersize) : TTreeCache(tree, buffersize) {}
0012 
0013 FWTTreeCache::~FWTTreeCache() {}
0014 
0015 //==============================================================================
0016 
0017 bool FWTTreeCache::s_logging = false;
0018 bool FWTTreeCache::s_prefetching = false;
0019 int FWTTreeCache::s_default_size = 50 * 1024 * 1024;
0020 
0021 void FWTTreeCache::LoggingOn() { s_logging = true; }
0022 void FWTTreeCache::LoggingOff() { s_logging = false; }
0023 bool FWTTreeCache::IsLogging() { return s_logging; }
0024 
0025 void FWTTreeCache::PrefetchingOn() { s_prefetching = true; }
0026 void FWTTreeCache::PrefetchingOff() { s_prefetching = false; }
0027 bool FWTTreeCache::IsPrefetching() { return s_prefetching; }
0028 
0029 void FWTTreeCache::SetDefaultCacheSize(int def_size) { s_default_size = def_size; }
0030 int FWTTreeCache::GetDefaultCacheSize() { return s_default_size; }
0031 
0032 //==============================================================================
0033 
0034 Int_t FWTTreeCache::AddBranchTopLevel(const char *bname) {
0035   if (bname == nullptr || bname[0] == 0) {
0036     printf("FWTTreeCache::AddBranchTopLevel Invalid branch name <%s>\n", bname == nullptr ? "nullptr" : "empty string");
0037     return -1;
0038   }
0039 
0040   Int_t ret = 0;
0041   if (!is_branch_in_cache(bname)) {
0042     if (s_logging)
0043       printf("FWTTreeCache::AddBranchTopLevel '%s' -- adding\n", bname);
0044     {
0045       LearnGuard _lg(this);
0046       ret = AddBranch(bname, true);
0047     }
0048     if (ret == 0)
0049       m_branch_set.insert(bname);
0050   } else {
0051     if (s_logging)
0052       printf("FWTTreeCache::AddBranchTopLevel '%s' -- already in cache\n", bname);
0053   }
0054 
0055   return ret;
0056 }
0057 
0058 Int_t FWTTreeCache::DropBranchTopLevel(const char *bname) {
0059   if (bname == nullptr || bname[0] == 0) {
0060     printf("FWTTreeCache::AddBranchTopLevel Invalid branch name");
0061     return -1;
0062   }
0063 
0064   Int_t ret = 0;
0065   if (is_branch_in_cache(bname)) {
0066     if (s_logging)
0067       printf("FWTTreeCache::DropBranchTopLevel '%s' -- dropping\n", bname);
0068     m_branch_set.erase(bname);
0069     LearnGuard _lg(this);
0070     ret = DropBranch(bname, true);
0071   } else {
0072     if (s_logging)
0073       printf("FWTTreeCache::DropBranchTopLevel '%s' -- not in cache\n", bname);
0074   }
0075   return ret;
0076 }
0077 
0078 void FWTTreeCache::BranchAccessCallIn(const TBranch *b) {
0079   if (s_logging)
0080     printf("FWTTreeCache::BranchAccessCallIn '%s'\n", b->GetName());
0081 
0082   AddBranchTopLevel(b->GetName());
0083 }
0084 
0085 //==============================================================================
0086 
0087 Int_t FWTTreeCache::AddBranch(TBranch *b, Bool_t subbranches) {
0088   if (s_logging && !m_silent_low_level)
0089     printf("FWTTreeCache::AddBranch by ptr '%s', subbp=%d\n", b->GetName(), subbranches);
0090   return TTreeCache::AddBranch(b, subbranches);
0091 }
0092 
0093 Int_t FWTTreeCache::AddBranch(const char *branch, Bool_t subbranches) {
0094   if (s_logging)
0095     printf("FWTTreeCache::AddBranch by name '%s', subbp=%d\n", branch, subbranches);
0096   if (strcmp(branch, "*") == 0)
0097     m_silent_low_level = true;
0098   return TTreeCache::AddBranch(branch, subbranches);
0099 }
0100 
0101 Int_t FWTTreeCache::DropBranch(TBranch *b, Bool_t subbranches) {
0102   if (s_logging && !m_silent_low_level)
0103     printf("FWTTreeCache::DropBranch by ptr '%s', subbp=%d\n", b->GetName(), subbranches);
0104   return TTreeCache::DropBranch(b, subbranches);
0105 }
0106 
0107 Int_t FWTTreeCache::DropBranch(const char *branch, Bool_t subbranches) {
0108   if (s_logging)
0109     printf("FWTTreeCache::DropBranch by name '%s', subbp=%d\n", branch, subbranches);
0110   Int_t ret = TTreeCache::DropBranch(branch, subbranches);
0111   if (strcmp(branch, "*") == 0)
0112     m_silent_low_level = false;
0113   return ret;
0114 }