ROOT logo
// @(#)root/tree:$Id$
// Author: Philippe Canal 07/11/2005

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TTreeCloner
#define ROOT_TTreeCloner

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TTreeCloner                                                          //
//                                                                      //
// Class implementing or helping  the various TTree cloning method      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif

#include <vector>

#ifdef R__OLDHPACC
namespace std {
   using ::string;
   using ::vector;
}
#endif

class TBranch;
class TTree;

class TTreeCloner {
   TString    fWarningMsg;       //Text of the error message lead to an 'invalid' state

   Bool_t     fIsValid;
   Bool_t     fNeedConversion;   //True if the fast merge is not possible but a slow merge might possible.
   UInt_t     fOptions;
   TTree     *fFromTree;
   TTree     *fToTree;
   Option_t  *fMethod;
   TObjArray  fFromBranches;
   TObjArray  fToBranches;

   UInt_t     fMaxBaskets;
   UInt_t    *fBasketBranchNum;  //[fMaxBaskets] Index of the branch(es) of the basket.
   UInt_t    *fBasketNum;        //[fMaxBaskets] index of the basket within the branch.

   Long64_t  *fBasketSeek;       //[fMaxBaskets] list of basket position to be read.
   Long64_t  *fBasketEntry;      //[fMaxBaskets] list of basket start entries.
   UInt_t    *fBasketIndex;      //[fMaxBaskets] ordered list of basket indices to be written.

   UShort_t   fPidOffset;        //Offset to be added to the copied key/basket.

   UInt_t     fCloneMethod;      //Indicates which cloning method was selected.
   Long64_t   fToStartEntries;   //Number of entries in the target tree before any addition.

   enum ECloneMethod {
      kDefault             = 0,
      kSortBasketsByBranch = 1,
      kSortBasketsByOffset = 2,
      kSortBasketsByEntry  = 3
   };

   class CompareSeek {
      TTreeCloner *fObject;
   public:
      CompareSeek(TTreeCloner *obj) : fObject(obj) {}
      Bool_t operator()(UInt_t i1, UInt_t i2);
   };

   class CompareEntry {
      TTreeCloner *fObject;
   public:
      CompareEntry(TTreeCloner *obj) : fObject(obj) {}
      Bool_t operator()(UInt_t i1, UInt_t i2);
   };

   friend class CompareSeek;
   friend class CompareEntry;
   
   void ImportClusterRanges();

private:
   TTreeCloner(const TTreeCloner&);            // Not implemented.
   TTreeCloner &operator=(const TTreeCloner&); // Not implemented.

public:
   enum EClonerOptions {
      kNone       = 0,
      kNoWarnings = BIT(1),
      kIgnoreMissingTopLevel = BIT(2)
   };

   TTreeCloner(TTree *from, TTree *to, Option_t *method, UInt_t options = kNone);
   virtual ~TTreeCloner();

   void   CloseOutWriteBaskets();
   UInt_t CollectBranches(TBranch *from, TBranch *to);
   UInt_t CollectBranches(TObjArray *from, TObjArray *to);
   UInt_t CollectBranches();
   void   CollectBaskets();
   void   CopyMemoryBaskets();
   void   CopyStreamerInfos();
   void   CopyProcessIds();
   const char *GetWarning() const { return fWarningMsg; }
   Bool_t Exec();
   Bool_t IsValid() { return fIsValid; }
   Bool_t NeedConversion() { return fNeedConversion; }
   void   SortBaskets();
   void   WriteBaskets();

   ClassDef(TTreeCloner,0); // helper used for the fast cloning of TTrees.
};

#endif
 TTreeCloner.h:1
 TTreeCloner.h:2
 TTreeCloner.h:3
 TTreeCloner.h:4
 TTreeCloner.h:5
 TTreeCloner.h:6
 TTreeCloner.h:7
 TTreeCloner.h:8
 TTreeCloner.h:9
 TTreeCloner.h:10
 TTreeCloner.h:11
 TTreeCloner.h:12
 TTreeCloner.h:13
 TTreeCloner.h:14
 TTreeCloner.h:15
 TTreeCloner.h:16
 TTreeCloner.h:17
 TTreeCloner.h:18
 TTreeCloner.h:19
 TTreeCloner.h:20
 TTreeCloner.h:21
 TTreeCloner.h:22
 TTreeCloner.h:23
 TTreeCloner.h:24
 TTreeCloner.h:25
 TTreeCloner.h:26
 TTreeCloner.h:27
 TTreeCloner.h:28
 TTreeCloner.h:29
 TTreeCloner.h:30
 TTreeCloner.h:31
 TTreeCloner.h:32
 TTreeCloner.h:33
 TTreeCloner.h:34
 TTreeCloner.h:35
 TTreeCloner.h:36
 TTreeCloner.h:37
 TTreeCloner.h:38
 TTreeCloner.h:39
 TTreeCloner.h:40
 TTreeCloner.h:41
 TTreeCloner.h:42
 TTreeCloner.h:43
 TTreeCloner.h:44
 TTreeCloner.h:45
 TTreeCloner.h:46
 TTreeCloner.h:47
 TTreeCloner.h:48
 TTreeCloner.h:49
 TTreeCloner.h:50
 TTreeCloner.h:51
 TTreeCloner.h:52
 TTreeCloner.h:53
 TTreeCloner.h:54
 TTreeCloner.h:55
 TTreeCloner.h:56
 TTreeCloner.h:57
 TTreeCloner.h:58
 TTreeCloner.h:59
 TTreeCloner.h:60
 TTreeCloner.h:61
 TTreeCloner.h:62
 TTreeCloner.h:63
 TTreeCloner.h:64
 TTreeCloner.h:65
 TTreeCloner.h:66
 TTreeCloner.h:67
 TTreeCloner.h:68
 TTreeCloner.h:69
 TTreeCloner.h:70
 TTreeCloner.h:71
 TTreeCloner.h:72
 TTreeCloner.h:73
 TTreeCloner.h:74
 TTreeCloner.h:75
 TTreeCloner.h:76
 TTreeCloner.h:77
 TTreeCloner.h:78
 TTreeCloner.h:79
 TTreeCloner.h:80
 TTreeCloner.h:81
 TTreeCloner.h:82
 TTreeCloner.h:83
 TTreeCloner.h:84
 TTreeCloner.h:85
 TTreeCloner.h:86
 TTreeCloner.h:87
 TTreeCloner.h:88
 TTreeCloner.h:89
 TTreeCloner.h:90
 TTreeCloner.h:91
 TTreeCloner.h:92
 TTreeCloner.h:93
 TTreeCloner.h:94
 TTreeCloner.h:95
 TTreeCloner.h:96
 TTreeCloner.h:97
 TTreeCloner.h:98
 TTreeCloner.h:99
 TTreeCloner.h:100
 TTreeCloner.h:101
 TTreeCloner.h:102
 TTreeCloner.h:103
 TTreeCloner.h:104
 TTreeCloner.h:105
 TTreeCloner.h:106
 TTreeCloner.h:107
 TTreeCloner.h:108
 TTreeCloner.h:109
 TTreeCloner.h:110
 TTreeCloner.h:111
 TTreeCloner.h:112
 TTreeCloner.h:113
 TTreeCloner.h:114
 TTreeCloner.h:115
 TTreeCloner.h:116
 TTreeCloner.h:117
 TTreeCloner.h:118
 TTreeCloner.h:119
 TTreeCloner.h:120
 TTreeCloner.h:121
 TTreeCloner.h:122