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
30class TBranch;
31
32namespace ROOT {
33namespace Internal {
34
36
37 enum EStates {
39 kUsed = 1,
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
74public:
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.
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 info 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
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
long long Long64_t
Definition: RtypesCore.h:80
const Bool_t kTRUE
Definition: RtypesCore.h:100
void Printf(const char *fmt,...)
Bool_t HasBeenUsed(Int_t basketNumber) const
Return true if the basket has been marked as 'used'.
Bool_t AllUsed() const
Return true if all the baskets that are marked loaded are also mark as used.
Bool_t IsVetoed(Int_t basketNumber) const
Return true if the basket is currently vetoed.
void SetUsed(Int_t basketNumber)
Mark if the basket has been marked as 'used'.
void Veto(Int_t basketNumber)
Mark if the basket should be vetoed in the next round.
void Print(const char *owner, Long64_t *entries) const
Print the info we have for the baskets.
Bool_t TestState(Int_t basketNumber, EStates what) const
Return true if the basket has been marked as having the 'what' state.
void SetState(Int_t basketNumber, EStates what)
Mark if the basket has been marked has the 'what' state.
void UpdatePedestal(Int_t basketNumber)
Update the pedestal to be less or equal to basketNumber, shift the bits if needed.
Bool_t IsInCache(Int_t basketNumber) const
Return true if the basket is currently in the cache.
void GetUnused(std::vector< Int_t > &unused)
Return a set of unused basket, let's not re-read them.
void SetIsInCache(Int_t basketNumber)
Mark if the basket is currently in the cache.
Container of bits.
Definition: TBits.h:26
void ResetAllBits(Bool_t value=kFALSE)
Reset all bits to 0 (false).
Definition: TBits.cxx:481
UInt_t GetNbits() const
Definition: TBits.h:134
Bool_t TestBitNumber(UInt_t bitnumber) const
Definition: TBits.h:222
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition: TBits.h:206
A TTree is a list of TBranches.
Definition: TBranch.h:89
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static const char * what
Definition: stlLoader.cc:6