Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TBranchCacheInfo.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/tree:$Id$
0002 // Author: Philippe Canal, 2018
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TBranchCacheInfo
0013 #define ROOT_TBranchCacheInfo
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TBranchCacheInfo                                                     //
0018 //                                                                      //
0019 // Hold info about which basket are in the cache and if they            //
0020 // have been retrieved from the cache.                                  //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "Rtypes.h"
0025 #include "TBits.h"
0026 #include "TString.h" // for Printf
0027 
0028 #include <vector>
0029 
0030 class TBranch;
0031 
0032 namespace ROOT {
0033 namespace Internal {
0034 
0035 class TBranchCacheInfo {
0036 
0037    enum EStates {
0038       kLoaded = 0,
0039       kUsed = 1,
0040       kVetoed = 2,
0041       kSize = 3
0042    };
0043 
0044    Int_t fBasketPedestal{-1}; // Lowest basket we have information for.  Its data is in bits [0-3[.
0045    TBits fInfo;               // kSize bits per baskets (loaded, used, vetoed)
0046 
0047    /// Update the pedestal to be less or equal to basketNumber, shift the bits if needed.
0048    void UpdatePedestal(Int_t basketNumber)
0049    {
0050       if (fBasketPedestal == -1) {
0051          fBasketPedestal = basketNumber;
0052       } else if (basketNumber < fBasketPedestal) {
0053          auto delta = fBasketPedestal - basketNumber;
0054          fBasketPedestal = basketNumber;
0055          fInfo <<= (delta * kSize);
0056       }
0057    }
0058 
0059    /// Return true if the basket has been marked as having the 'what' state.
0060    bool TestState(Int_t basketNumber, EStates what) const
0061    {
0062       if (basketNumber < fBasketPedestal)
0063          return false;
0064       return fInfo.TestBitNumber(kSize * (basketNumber - fBasketPedestal) + what);
0065    }
0066 
0067    /// Mark if the basket has been marked has the 'what' state.
0068    void SetState(Int_t basketNumber, EStates what)
0069    {
0070       if (fBasketPedestal <= basketNumber)
0071          fInfo.SetBitNumber(kSize * (basketNumber - fBasketPedestal) + what, true);
0072    }
0073 
0074 public:
0075    /// Return true if the basket has been marked as 'used'
0076    bool HasBeenUsed(Int_t basketNumber) const { return TestState(basketNumber, kUsed); }
0077 
0078    /// Mark if the basket has been marked as 'used'
0079    void SetUsed(Int_t basketNumber)
0080    {
0081       UpdatePedestal(basketNumber);
0082       SetState(basketNumber, kUsed);
0083    }
0084 
0085    /// Return true if the basket is currently in the cache.
0086    bool IsInCache(Int_t basketNumber) const { return TestState(basketNumber, kLoaded); }
0087 
0088    /// Mark if the basket is currently in the cache.
0089    void SetIsInCache(Int_t basketNumber)
0090    {
0091       UpdatePedestal(basketNumber);
0092       SetState(basketNumber, kLoaded);
0093    }
0094 
0095    /// Mark if the basket should be vetoed in the next round.
0096    /// This happens when the basket was loaded in the previous round
0097    /// and was not used and is overlapping to the next round/cluster
0098    void Veto(Int_t basketNumber)
0099    {
0100       UpdatePedestal(basketNumber);
0101       SetState(basketNumber, kVetoed);
0102    }
0103 
0104    /// Return true if the basket is currently vetoed.
0105    bool IsVetoed(Int_t basketNumber) const { return TestState(basketNumber, kVetoed); }
0106 
0107    /// Return true if all the baskets that are marked loaded are also
0108    /// mark as used.
0109    bool AllUsed() const
0110    {
0111       auto len = fInfo.GetNbits() / kSize + 1;
0112       for (UInt_t b = 0; b < len; ++b) {
0113          if (fInfo[kSize * b + kLoaded] && !fInfo[kSize * b + kUsed]) {
0114             // Not loaded or (loaded and used)
0115             return false;
0116          }
0117       }
0118       return true;
0119    }
0120 
0121    /// Return a set of unused basket, let's not re-read them.
0122    void GetUnused(std::vector<Int_t> &unused)
0123    {
0124       unused.clear();
0125       auto len = fInfo.GetNbits() / kSize + 1;
0126       for (UInt_t b = 0; b < len; ++b) {
0127          if (fInfo[kSize * b + kLoaded] && !fInfo[kSize * b + kUsed]) {
0128             unused.push_back(fBasketPedestal + b);
0129          }
0130       }
0131    }
0132 
0133    /// Reset all info.
0134    void Reset()
0135    {
0136       fBasketPedestal = -1;
0137       fInfo.ResetAllBits();
0138    }
0139 
0140    /// Print the info we have for the baskets.
0141    void Print(const char *owner, Long64_t *entries) const
0142    {
0143       if (!owner || !entries)
0144          return;
0145       auto len = fInfo.GetNbits() / kSize + 1;
0146       if (fBasketPedestal >= 0)
0147          for (UInt_t b = 0; b < len; ++b) {
0148             Printf("Branch %s : basket %d loaded=%d used=%d start entry=%lld", owner, b + fBasketPedestal,
0149                    (bool)fInfo[kSize * b + kLoaded], (bool)fInfo[kSize * b + kUsed], entries[fBasketPedestal + b]);
0150          }
0151    }
0152 };
0153 
0154 } // Internal
0155 } // ROOT
0156 
0157 #endif // ROOT_TBranchCacheInfo