Logo ROOT  
Reference Guide
TBranchCacheInfo.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Philippe Canal, 2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TBranchCacheInfo
13 #define ROOT_TBranchCacheInfo
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TBranchCacheInfo //
18 // //
19 // Hold info about which basket are in the cache and if they //
20 // have been retrieved from the cache. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "Rtypes.h"
25 #include "TBits.h"
26 #include "TString.h" // for Printf
27 
28 #include <vector>
29 
30 class TBranch;
31 
32 namespace ROOT {
33 namespace Internal {
34 
36 
37  enum EStates {
38  kLoaded = 0,
39  kUsed = 1,
40  kVetoed = 2,
41  kSize = 3
42  };
43 
44  Int_t fBasketPedestal{-1}; // Lowest basket we have information for. Its data is in bits [0-3[.
45  TBits fInfo; // kSize bits per baskets (loaded, used, vetoed)
46 
47  // Update the pedestal to be less or equal to basketNumber, shift the bits if needed.
48  void UpdatePedestal(Int_t basketNumber)
49  {
50  if (fBasketPedestal == -1) {
51  fBasketPedestal = basketNumber;
52  } else if (basketNumber < fBasketPedestal) {
53  auto delta = fBasketPedestal - basketNumber;
54  fBasketPedestal = basketNumber;
55  fInfo <<= (delta * kSize);
56  }
57  }
58 
59  // Return true if the basket has been marked as having the 'what' state.
60  Bool_t TestState(Int_t basketNumber, EStates what) const
61  {
62  if (basketNumber < fBasketPedestal)
63  return kFALSE;
64  return fInfo.TestBitNumber(kSize * (basketNumber - fBasketPedestal) + what);
65  }
66 
67  // Mark if the basket has been marked has the 'what' state.
68  void SetState(Int_t basketNumber, EStates what)
69  {
70  if (fBasketPedestal <= basketNumber)
71  fInfo.SetBitNumber(kSize * (basketNumber - fBasketPedestal) + what, true);
72  }
73 
74 public:
75  // Return true if the basket has been marked as 'used'
76  Bool_t HasBeenUsed(Int_t basketNumber) const { return TestState(basketNumber, kUsed); }
77 
78  // Mark if the basket has been marked as 'used'
79  void SetUsed(Int_t basketNumber)
80  {
81  UpdatePedestal(basketNumber);
82  SetState(basketNumber, kUsed);
83  }
84 
85  // Return true if the basket is currently in the cache.
86  Bool_t IsInCache(Int_t basketNumber) const { return TestState(basketNumber, kLoaded); }
87 
88  // Mark if the basket is currently in the cache.
89  void SetIsInCache(Int_t basketNumber)
90  {
91  UpdatePedestal(basketNumber);
92  SetState(basketNumber, kLoaded);
93  }
94 
95  // Mark if the basket should be vetoed in the next round.
96  // This happens when the basket was loaded in the previous round
97  // and was not used and is overlapping to the next round/cluster
98  void Veto(Int_t basketNumber)
99  {
100  UpdatePedestal(basketNumber);
101  SetState(basketNumber, kVetoed);
102  }
103 
104  // Return true if the basket is currently vetoed.
105  Bool_t IsVetoed(Int_t basketNumber) const { return TestState(basketNumber, kVetoed); }
106 
107  // Return true if all the baskets that are marked loaded are also
108  // mark as used.
109  Bool_t AllUsed() const
110  {
111  auto len = fInfo.GetNbits() / kSize + 1;
112  for (UInt_t b = 0; b < len; ++b) {
113  if (fInfo[kSize * b + kLoaded] && !fInfo[kSize * b + kUsed]) {
114  // Not loaded or (loaded and used)
115  return kFALSE;
116  }
117  }
118  return kTRUE;
119  }
120 
121  // Return a set of unused basket, let's not re-read them.
122  void GetUnused(std::vector<Int_t> &unused)
123  {
124  unused.clear();
125  auto len = fInfo.GetNbits() / kSize + 1;
126  for (UInt_t b = 0; b < len; ++b) {
127  if (fInfo[kSize * b + kLoaded] && !fInfo[kSize * b + kUsed]) {
128  unused.push_back(fBasketPedestal + b);
129  }
130  }
131  }
132 
133  // Reset all info.
134  void Reset()
135  {
136  fBasketPedestal = -1;
138  }
139 
140  // Print the infor we have for the baskets.
141  void Print(const char *owner, Long64_t *entries) const
142  {
143  if (!owner || !entries)
144  return;
145  auto len = fInfo.GetNbits() / kSize + 1;
146  if (fBasketPedestal >= 0)
147  for (UInt_t b = 0; b < len; ++b) {
148  Printf("Branch %s : basket %d loaded=%d used=%d start entry=%lld", owner, b + fBasketPedestal,
149  (bool)fInfo[kSize * b + kLoaded], (bool)fInfo[kSize * b + kUsed], entries[fBasketPedestal + b]);
150  }
151  }
152 };
153 
154 } // Internal
155 } // ROOT
156 
157 #endif // ROOT_TBranchCacheInfo
ROOT::Internal::TBranchCacheInfo::Reset
void Reset()
Definition: TBranchCacheInfo.h:134
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
ROOT::Internal::TBranchCacheInfo::AllUsed
Bool_t AllUsed() const
Definition: TBranchCacheInfo.h:109
TBits::GetNbits
UInt_t GetNbits() const
Definition: TBits.h:133
ROOT::Internal::TBranchCacheInfo::IsVetoed
Bool_t IsVetoed(Int_t basketNumber) const
Definition: TBranchCacheInfo.h:105
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
ROOT::Internal::TBranchCacheInfo::SetState
void SetState(Int_t basketNumber, EStates what)
Definition: TBranchCacheInfo.h:68
ROOT::Internal::TBranchCacheInfo::Veto
void Veto(Int_t basketNumber)
Definition: TBranchCacheInfo.h:98
TBits::ResetAllBits
void ResetAllBits(Bool_t value=kFALSE)
Reset all bits to 0 (false).
Definition: TBits.cxx:481
ROOT::Internal::TBranchCacheInfo::Print
void Print(const char *owner, Long64_t *entries) const
Definition: TBranchCacheInfo.h:141
TBits::TestBitNumber
Bool_t TestBitNumber(UInt_t bitnumber) const
Definition: TBits.h:221
TBits
Container of bits.
Definition: TBits.h:26
ROOT::Internal::TBranchCacheInfo::kUsed
@ kUsed
Definition: TBranchCacheInfo.h:39
b
#define b(i)
Definition: RSha256.hxx:100
TString.h
bool
ROOT::Internal::TBranchCacheInfo
Definition: TBranchCacheInfo.h:35
TBranch
A TTree is a list of TBranches.
Definition: TBranch.h:89
ROOT::Internal::TBranchCacheInfo::HasBeenUsed
Bool_t HasBeenUsed(Int_t basketNumber) const
Definition: TBranchCacheInfo.h:76
ROOT::Internal::TBranchCacheInfo::TestState
Bool_t TestState(Int_t basketNumber, EStates what) const
Definition: TBranchCacheInfo.h:60
ROOT::Internal::TBranchCacheInfo::SetUsed
void SetUsed(Int_t basketNumber)
Definition: TBranchCacheInfo.h:79
ROOT::Internal::TBranchCacheInfo::fInfo
TBits fInfo
Definition: TBranchCacheInfo.h:45
ROOT::Internal::TBranchCacheInfo::IsInCache
Bool_t IsInCache(Int_t basketNumber) const
Definition: TBranchCacheInfo.h:86
ROOT::Internal::TBranchCacheInfo::UpdatePedestal
void UpdatePedestal(Int_t basketNumber)
Definition: TBranchCacheInfo.h:48
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
what
static const char * what
Definition: stlLoader.cc:6
ROOT::Internal::TBranchCacheInfo::kLoaded
@ kLoaded
Definition: TBranchCacheInfo.h:38
unsigned int
Printf
void Printf(const char *fmt,...)
ROOT::Internal::TBranchCacheInfo::GetUnused
void GetUnused(std::vector< Int_t > &unused)
Definition: TBranchCacheInfo.h:122
ROOT::Internal::TBranchCacheInfo::kSize
@ kSize
Definition: TBranchCacheInfo.h:41
ROOT::Internal::TBranchCacheInfo::fBasketPedestal
Int_t fBasketPedestal
Definition: TBranchCacheInfo.h:44
TBits.h
TBits::SetBitNumber
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition: TBits.h:205
ROOT::Internal::TBranchCacheInfo::SetIsInCache
void SetIsInCache(Int_t basketNumber)
Definition: TBranchCacheInfo.h:89
ROOT::Internal::TBranchCacheInfo::EStates
EStates
Definition: TBranchCacheInfo.h:37
Rtypes.h
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Internal::TBranchCacheInfo::kVetoed
@ kVetoed
Definition: TBranchCacheInfo.h:40
int