Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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,
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 TestState(Int_t basketNumber, EStates what) const
61 {
62 if (basketNumber < fBasketPedestal)
63 return false;
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 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 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 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 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 false;
116 }
117 }
118 return true;
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;
137 fInfo.ResetAllBits();
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
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2510
bool HasBeenUsed(Int_t basketNumber) const
Return true if the basket has been marked as 'used'.
void SetUsed(Int_t basketNumber)
Mark if the basket has been marked as 'used'.
bool IsInCache(Int_t basketNumber) const
Return true if the basket is currently in the cache.
void Veto(Int_t basketNumber)
Mark if the basket should be vetoed in the next round.
bool AllUsed() const
Return true if all the baskets that are marked loaded are also mark as used.
void Print(const char *owner, Long64_t *entries) const
Print the info we have for the baskets.
bool IsVetoed(Int_t basketNumber) const
Return true if the basket is currently vetoed.
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 TestState(Int_t basketNumber, EStates what) const
Return true if the basket has been marked as having the 'what' state.
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
A TTree is a list of TBranches.
Definition TBranch.h:93
static const char * what
Definition stlLoader.cc:5