Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:31:02

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    Long64_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 // clang++ <v20 (-Wshadow) complains about shadowing TSystem.h global enum ESendRecvOptions. Let's silence warning:
0064 #if defined(__clang__) && __clang_major__ < 20
0065 #pragma clang diagnostic push
0066 #pragma clang diagnostic ignored "-Wshadow"
0067 #endif
0068       kDefault             = 0,
0069 #if defined(__clang__) && __clang_major__ < 20
0070 #pragma clang diagnostic pop
0071 #endif
0072       kSortBasketsByBranch = 1,
0073       kSortBasketsByOffset = 2,
0074       kSortBasketsByEntry  = 3
0075    };
0076 
0077    class CompareSeek {
0078       TTreeCloner *fObject;
0079    public:
0080       CompareSeek(TTreeCloner *obj) : fObject(obj) {}
0081       bool operator()(UInt_t i1, UInt_t i2);
0082    };
0083 
0084    class CompareEntry {
0085       TTreeCloner *fObject;
0086    public:
0087       CompareEntry(TTreeCloner *obj) : fObject(obj) {}
0088       bool operator()(UInt_t i1, UInt_t i2);
0089    };
0090 
0091    friend class CompareSeek;
0092    friend class CompareEntry;
0093 
0094    void ImportClusterRanges();
0095    void CreateCache();
0096    UInt_t FillCache(UInt_t from);
0097    void RestoreCache();
0098 
0099 public:
0100    enum EClonerOptions {
0101 // clang++ <v20 (-Wshadow) complains about shadowing GuiTypes.h global variable kNone. Let's silence warning:
0102 #if defined(__clang__) && __clang_major__ < 20
0103 #pragma clang diagnostic push
0104 #pragma clang diagnostic ignored "-Wshadow"
0105 #endif
0106       kNone       = 0,
0107 #if defined(__clang__) && __clang_major__ < 20
0108 #pragma clang diagnostic pop
0109 #endif
0110       kNoWarnings = BIT(1),
0111       kIgnoreMissingTopLevel = BIT(2),
0112       kNoFileCache = BIT(3)
0113    };
0114 
0115 private:
0116    TTreeCloner(const TTreeCloner&) = delete;
0117    TTreeCloner &operator=(const TTreeCloner&) = delete;
0118 
0119    TTreeCloner(TTree *from, TTree *to, TDirectory *newdirectory, Option_t *method, UInt_t options = kNone);
0120 
0121 public:
0122 
0123    TTreeCloner(TTree *from, TTree *to, Option_t *method, UInt_t options = kNone);
0124    TTreeCloner(TTree *from, TDirectory *newdirectory, Option_t *method, UInt_t options = kNone);
0125    virtual ~TTreeCloner();
0126 
0127    void   CloseOutWriteBaskets();
0128    UInt_t CollectBranches(TBranch *from, TBranch *to);
0129    UInt_t CollectBranches(TObjArray *from, TObjArray *to);
0130    UInt_t CollectBranches();
0131    void   CollectBaskets();
0132    void   CopyMemoryBaskets();
0133    void   CopyStreamerInfos();
0134    void   CopyProcessIds();
0135    const char *GetWarning() const { return fWarningMsg; }
0136    bool   IsInPlace() const { return fFromTree == fToTree; }
0137    bool   Exec();
0138    bool   IsValid() { return fIsValid; }
0139    bool   NeedConversion() { return fNeedConversion; }
0140    void   SetCacheSize(Long64_t size);
0141    void   SortBaskets();
0142    void   WriteBaskets();
0143 
0144    ClassDef(TTreeCloner,0); // helper used for the fast cloning of TTrees.
0145 };
0146 
0147 #endif