CMS 3D CMS Logo

FWTTreeCache.cc
Go to the documentation of this file.
1 #include "FWTTreeCache.h"
2 
3 #include "TChain.h"
4 #include "TTree.h"
5 #include "TEventList.h"
6 
7 #include <climits>
8 
10  TTreeCache()
11 {}
12 
13 FWTTreeCache::FWTTreeCache(TTree *tree, Int_t buffersize) :
14  TTreeCache(tree, buffersize)
15 {}
16 
18 {}
19 
20 //==============================================================================
21 
22 bool FWTTreeCache::s_logging = false;
23 bool FWTTreeCache::s_prefetching = false;
24 int FWTTreeCache::s_default_size = 50 * 1024 * 1024;
25 
29 
33 
34 void FWTTreeCache::SetDefaultCacheSize(int def_size) { s_default_size = def_size; }
36 
37 //==============================================================================
38 
39 Int_t FWTTreeCache::AddBranchTopLevel (const char* bname)
40 {
41  if (bname == nullptr || bname[0] == 0)
42  {
43  printf("FWTTreeCache::AddBranchTopLevel Invalid branch name <%s>\n",
44  bname == nullptr ? "nullptr" : "empty string");
45  return -1;
46  }
47 
48  Int_t ret = 0;
49  if ( ! is_branch_in_cache(bname))
50  {
51  if (s_logging)
52  printf("FWTTreeCache::AddBranchTopLevel '%s' -- adding\n", bname);
53  { LearnGuard _lg(this);
54  ret = AddBranch(bname, true);
55  }
56  if (ret == 0)
57  m_branch_set.insert(bname);
58  }
59  else
60  {
61  if (s_logging)
62  printf("FWTTreeCache::AddBranchTopLevel '%s' -- already in cache\n", bname);
63  }
64 
65  return ret;
66 }
67 
68 Int_t FWTTreeCache::DropBranchTopLevel(const char* bname)
69 {
70  if (bname == nullptr || bname[0] == 0)
71  {
72  printf("FWTTreeCache::AddBranchTopLevel Invalid branch name");
73  return -1;
74  }
75 
76  Int_t ret = 0;
77  if (is_branch_in_cache(bname))
78  {
79  if (s_logging)
80  printf("FWTTreeCache::DropBranchTopLevel '%s' -- dropping\n", bname);
81  m_branch_set.erase(bname);
82  LearnGuard _lg(this);
83  ret = DropBranch(bname, true);
84  }
85  else
86  {
87  if (s_logging)
88  printf("FWTTreeCache::DropBranchTopLevel '%s' -- not in cache\n", bname);
89  }
90  return ret;
91 }
92 
93 void FWTTreeCache::BranchAccessCallIn(const TBranch *b)
94 {
95  if (s_logging)
96  printf("FWTTreeCache::BranchAccessCallIn '%s'\n", b->GetName());
97 
98  AddBranchTopLevel(b->GetName());
99 }
100 
101 //==============================================================================
102 
103 Int_t FWTTreeCache::AddBranch(TBranch *b, Bool_t subbranches)
104 {
105  if (s_logging && ! m_silent_low_level)
106  printf("FWTTreeCache::AddBranch by ptr '%s', subbp=%d\n", b->GetName(), subbranches);
107  return TTreeCache::AddBranch(b, subbranches);
108 }
109 
110 Int_t FWTTreeCache::AddBranch(const char *branch, Bool_t subbranches)
111 {
112  if (s_logging)
113  printf("FWTTreeCache::AddBranch by name '%s', subbp=%d\n", branch, subbranches);
114  if (strcmp(branch,"*") == 0)
115  m_silent_low_level = true;
116  return TTreeCache::AddBranch(branch, subbranches);
117 }
118 
119 Int_t FWTTreeCache::DropBranch(TBranch *b, Bool_t subbranches)
120 {
121  if (s_logging && ! m_silent_low_level)
122  printf("FWTTreeCache::DropBranch by ptr '%s', subbp=%d\n", b->GetName(), subbranches);
123  return TTreeCache::DropBranch(b, subbranches);
124 }
125 
126 Int_t FWTTreeCache::DropBranch(const char *branch, Bool_t subbranches)
127 {
128  if (s_logging)
129  printf("FWTTreeCache::DropBranch by name '%s', subbp=%d\n", branch, subbranches);
130  Int_t ret = TTreeCache::DropBranch(branch, subbranches);
131  if (strcmp(branch,"*") == 0)
132  m_silent_low_level = false;
133  return ret;
134 }
static void PrefetchingOn()
Definition: FWTTreeCache.cc:30
static void LoggingOff()
Definition: FWTTreeCache.cc:27
~FWTTreeCache() override
Definition: FWTTreeCache.cc:17
static bool s_logging
Definition: FWTTreeCache.h:15
Int_t AddBranchTopLevel(const char *bname)
Definition: FWTTreeCache.cc:39
static void PrefetchingOff()
Definition: FWTTreeCache.cc:31
static bool IsLogging()
Definition: FWTTreeCache.cc:28
static bool IsPrefetching()
Definition: FWTTreeCache.cc:32
static int s_default_size
Definition: FWTTreeCache.h:14
static int GetDefaultCacheSize()
Definition: FWTTreeCache.cc:35
Int_t AddBranch(TBranch *b, Bool_t subbranches=kFALSE) override
Int_t DropBranch(TBranch *b, Bool_t subbranches=kFALSE) override
void BranchAccessCallIn(const TBranch *b)
Definition: FWTTreeCache.cc:93
static bool s_prefetching
Definition: FWTTreeCache.h:16
bool m_silent_low_level
Definition: FWTTreeCache.h:12
std::set< std::string > m_branch_set
Definition: FWTTreeCache.h:11
double b
Definition: hdecay.h:120
Definition: tree.py:1
Int_t DropBranchTopLevel(const char *bname)
Definition: FWTTreeCache.cc:68
static void LoggingOn()
Definition: FWTTreeCache.cc:26
static void SetDefaultCacheSize(int def_size)
Definition: FWTTreeCache.cc:34
bool is_branch_in_cache(const char *name)
Definition: FWTTreeCache.h:19