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