Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:30

0001 // @(#)root/tree:$Id$
0002 // Author: Philippe Canal 07/11/2005
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_TTreeCloner
0013 #define ROOT_TTreeCloner
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TTreeCloner                                                          //
0018 //                                                                      //
0019 // Class implementing or helping  the various TTree cloning method      //
0020 //                                                                      //
0021 //////////////////////////////////////////////////////////////////////////
0022 
0023 #include "TObjArray.h"
0024 
0025 class TBranch;
0026 class TTree;
0027 class TFile;
0028 class TFileCacheRead;
0029 class TDirectory;
0030 
0031 class TTreeCloner {
0032    TString    fWarningMsg;       ///< Text of the error message lead to an 'invalid' state
0033 
0034    bool       fIsValid;
0035    bool       fNeedConversion;   ///< True if the fast merge is not possible but a slow merge might possible.
0036    UInt_t     fOptions;
0037    TTree     *fFromTree;
0038    TTree     *fToTree;
0039    TDirectory*fToDirectory;
0040    TFile     *fToFile;
0041    Option_t  *fMethod;
0042    TObjArray  fFromBranches;
0043    TObjArray  fToBranches;
0044 
0045    UInt_t     fMaxBaskets;
0046    UInt_t    *fBasketBranchNum;  ///<[fMaxBaskets] Index of the branch(es) of the basket.
0047    UInt_t    *fBasketNum;        ///<[fMaxBaskets] index of the basket within the branch.
0048 
0049    Long64_t  *fBasketSeek;       ///<[fMaxBaskets] list of basket position to be read.
0050    Long64_t  *fBasketEntry;      ///<[fMaxBaskets] list of basket start entries.
0051    UInt_t    *fBasketIndex;      ///<[fMaxBaskets] ordered list of basket indices to be written.
0052 
0053    UShort_t   fPidOffset;        ///< Offset to be added to the copied key/basket.
0054 
0055    UInt_t     fCloneMethod;      ///< Indicates which cloning method was selected.
0056    Long64_t   fToStartEntries;   ///< Number of entries in the target tree before any addition.
0057 
0058    Int_t           fCacheSize;   ///< Requested size of the file cache
0059    TFileCacheRead *fFileCache;   ///< File Cache used to reduce the number of individual reads
0060    TFileCacheRead *fPrevCache;   ///< Cache that set before the TTreeCloner ctor for the 'from' TTree if any.
0061 
0062    enum ECloneMethod {
0063       kDefault             = 0,
0064       kSortBasketsByBranch = 1,
0065       kSortBasketsByOffset = 2,
0066       kSortBasketsByEntry  = 3
0067    };
0068 
0069    class CompareSeek {
0070       TTreeCloner *fObject;
0071    public:
0072       CompareSeek(TTreeCloner *obj) : fObject(obj) {}
0073       bool operator()(UInt_t i1, UInt_t i2);
0074    };
0075 
0076    class CompareEntry {
0077       TTreeCloner *fObject;
0078    public:
0079       CompareEntry(TTreeCloner *obj) : fObject(obj) {}
0080       bool operator()(UInt_t i1, UInt_t i2);
0081    };
0082 
0083    friend class CompareSeek;
0084    friend class CompareEntry;
0085 
0086    void ImportClusterRanges();
0087    void CreateCache();
0088    UInt_t FillCache(UInt_t from);
0089    void RestoreCache();
0090 
0091 private:
0092    TTreeCloner(const TTreeCloner&) = delete;
0093    TTreeCloner &operator=(const TTreeCloner&) = delete;
0094 
0095    TTreeCloner(TTree *from, TTree *to, TDirectory *newdirectory, Option_t *method, UInt_t options = kNone);
0096 
0097 public:
0098    enum EClonerOptions {
0099       kNone       = 0,
0100       kNoWarnings = BIT(1),
0101       kIgnoreMissingTopLevel = BIT(2),
0102       kNoFileCache = BIT(3)
0103    };
0104 
0105    TTreeCloner(TTree *from, TTree *to, Option_t *method, UInt_t options = kNone);
0106    TTreeCloner(TTree *from, TDirectory *newdirectory, Option_t *method, UInt_t options = kNone);
0107    virtual ~TTreeCloner();
0108 
0109    void   CloseOutWriteBaskets();
0110    UInt_t CollectBranches(TBranch *from, TBranch *to);
0111    UInt_t CollectBranches(TObjArray *from, TObjArray *to);
0112    UInt_t CollectBranches();
0113    void   CollectBaskets();
0114    void   CopyMemoryBaskets();
0115    void   CopyStreamerInfos();
0116    void   CopyProcessIds();
0117    const char *GetWarning() const { return fWarningMsg; }
0118    bool   IsInPlace() const { return fFromTree == fToTree; }
0119    bool   Exec();
0120    bool   IsValid() { return fIsValid; }
0121    bool   NeedConversion() { return fNeedConversion; }
0122    void   SetCacheSize(Int_t size);
0123    void   SortBaskets();
0124    void   WriteBaskets();
0125 
0126    ClassDef(TTreeCloner,0); // helper used for the fast cloning of TTrees.
0127 };
0128 
0129 #endif