Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TBasket.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: Rene Brun   19/01/96
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, 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_TBasket
0013 #define ROOT_TBasket
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TBasket                                                              //
0018 //                                                                      //
0019 // The TBasket objects are created at run time to collect TTree entries //
0020 // in buffers. When a Basket is full, it is written to the file.        //
0021 // The Basket is kept in memory if there is enough space.               //
0022 //  (see the fMaxVirtualsize of TTree).                                 //
0023 //                                                                      //
0024 // The Basket class derives from TKey.                                  //
0025 //////////////////////////////////////////////////////////////////////////
0026 
0027 
0028 #include "TKey.h"
0029 
0030 class TFile;
0031 class TTree;
0032 class TBranch;
0033 
0034 class TBasket : public TKey {
0035 friend class TBranch;
0036 
0037 private:
0038    TBasket(const TBasket&);            ///< TBasket objects are not copiable.
0039    TBasket& operator=(const TBasket&); ///< TBasket objects are not copiable.
0040 
0041    // Internal corner cases for ReadBasketBuffers
0042    Int_t ReadBasketBuffersUnzip(char*, Int_t, bool, TFile*);
0043    Int_t ReadBasketBuffersUncompressedCase();
0044 
0045    // Helper for managing the compressed buffer.
0046    void InitializeCompressedBuffer(Int_t len, TFile* file);
0047 
0048    // Handles special logic around deleting / reseting the entry offset pointer.
0049    void ResetEntryOffset();
0050 
0051    // Get entry offset as result of a calculation.
0052    Int_t *GetCalculatedEntryOffset();
0053 
0054    // Returns true if the underlying TLeaf can regenerate the entry offsets for us.
0055    bool CanGenerateOffsetArray();
0056 
0057    // Manage buffer ownership.
0058    void   DisownBuffer();
0059    void   AdoptBuffer(TBuffer *user_buffer);
0060 
0061 protected:
0062    Int_t       fBufferSize{0};                    ///< fBuffer length in bytes
0063    Int_t       fNevBufSize{0};                    ///< Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
0064    Int_t       fNevBuf{0};                        ///< Number of entries in basket
0065    Int_t       fLast{0};                          ///< Pointer to last used byte in basket
0066    bool        fHeaderOnly{false};               ///< True when only the basket header must be read/written
0067    UChar_t     fIOBits{0};                        ///<!IO feature flags.  Serialized in custom portion of streamer to avoid forward compat issues unless needed.
0068    bool        fOwnsCompressedBuffer{false};     ///<! Whether or not we own the compressed buffer.
0069    bool        fReadEntryOffset{false};          ///<!Set to true if offset array was read from a file.
0070    Int_t      *fDisplacement{nullptr};            ///<![fNevBuf] Displacement of entries in fBuffer(TKey)
0071    Int_t      *fEntryOffset{nullptr};             ///<[fNevBuf] Offset of entries in fBuffer(TKey); generated at runtime.  Special value
0072                                                   /// of `-1` indicates that the offset generation MUST be performed on first read.
0073    TBranch    *fBranch{nullptr};                  ///<Pointer to the basket support branch
0074    TBuffer    *fCompressedBufferRef{nullptr};     ///<! Compressed buffer.
0075    Int_t       fLastWriteBufferSize[3] = {0,0,0}; ///<! Size of the buffer last three buffers we wrote it to disk
0076    bool        fResetAllocation{false};           ///<! True if last reset re-allocated the memory
0077    UChar_t     fNextBufferSizeRecord{0};          ///<! Index into fLastWriteBufferSize of the last buffer written to disk
0078 #ifdef R__TRACK_BASKET_ALLOC_TIME
0079    ULong64_t   fResetAllocationTime{0};           ///<! Time spent reallocating baskets in microseconds during last Reset operation.
0080 #endif
0081 
0082    virtual void    ReadResetBuffer(Int_t basketnumber);
0083 
0084 public:
0085    // The IO bits flag is to provide improved forward-compatibility detection.
0086    // Any new non-forward compatibility flags related serialization should be
0087    // added here.  When a new flag is added, set it in the kSupported field;
0088    //
0089    // The values and names of this (and EUnsupportedIOBits) enum need not be aligned
0090    // with the values of the various TIOFeatures enums, as there's a clean separation
0091    // between these two interfaces.  Practically, it is reasonable to keep them as aligned
0092    // as possible in order to avoid confusion.
0093    //
0094    // If (fIOBits & ~kSupported) is non-zero -- i.e., an unknown IO flag is set
0095    // in the fIOBits -- then the zombie flag will be set for this object.
0096    //
0097    enum class EIOBits : Char_t {
0098       // The following to bits are reserved for now; when supported, set
0099       // kSupported = kGenerateOffsetMap | kBasketClassMap
0100       kGenerateOffsetMap = BIT(0),
0101       // kBasketClassMap = BIT(1),
0102       kSupported = kGenerateOffsetMap
0103    };
0104    // This enum covers IOBits that are known to this ROOT release but
0105    // not supported; provides a mechanism for us to have experimental
0106    // changes that are not going go into a supported release.
0107    //
0108    // (kUnsupported | kSupported) should result in the '|' of all IOBits.
0109    enum class EUnsupportedIOBits : Char_t { kUnsupported = 0 };
0110    // The number of known, defined IOBits.
0111    static constexpr int kIOBitCount = 1;
0112 
0113    TBasket();
0114    TBasket(TDirectory *motherDir);
0115    TBasket(const char *name, const char *title, TBranch *branch);
0116    ~TBasket() override;
0117 
0118    virtual void    AdjustSize(Int_t newsize);
0119    virtual void    DeleteEntryOffset();
0120    virtual Int_t   DropBuffers();
0121    TBranch        *GetBranch() const {return fBranch;}
0122            Int_t   GetBufferSize() const {return fBufferSize;}
0123            Int_t  *GetDisplacement() const {return fDisplacement;}
0124            Int_t *GetEntryOffset()
0125            {
0126               return R__likely(fEntryOffset != reinterpret_cast<Int_t *>(-1)) ? fEntryOffset : GetCalculatedEntryOffset();
0127            }
0128            Int_t   GetEntryPointer(Int_t Entry);
0129            Int_t   GetNevBuf() const {return fNevBuf;}
0130            Int_t   GetNevBufSize() const {return fNevBufSize;}
0131            Int_t   GetLast() const {return fLast;}
0132    virtual void    MoveEntries(Int_t dentries);
0133    virtual void    PrepareBasket(Long64_t /* entry */) {};
0134            Int_t   ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file);
0135            Int_t   ReadBasketBytes(Long64_t pos, TFile *file);
0136    virtual void    WriteReset();
0137 
0138 // Time spent reseting basket sizes (typically, at event cluster boundaries), in microseconds
0139 #ifdef R__TRACK_BASKET_ALLOC_TIME
0140    ULong64_t       GetResetAllocationTime() const { return fResetAllocationTime; }
0141 #endif
0142    // Count of resets performed of basket size.
0143    bool            GetResetAllocationCount() const { return fResetAllocation; }
0144 
0145    Int_t           LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree = nullptr);
0146    Long64_t        CopyTo(TFile *to);
0147 
0148            void    SetBranch(TBranch *branch) { fBranch = branch; }
0149            void    SetNevBufSize(Int_t n) { fNevBufSize=n; }
0150    virtual void    SetReadMode();
0151    virtual void    SetWriteMode();
0152    inline  void    Update(Int_t newlast) { Update(newlast,newlast); };
0153    virtual void    Update(Int_t newlast, Int_t skipped);
0154    virtual Int_t   WriteBuffer();
0155 
0156    ClassDefOverride(TBasket, 3); // the TBranch buffers
0157 };
0158 
0159 #endif