Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TTreeCloner.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Philippe Canal 07/11/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TTreeCloner
13 #define ROOT_TTreeCloner
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TTreeCloner //
18 // //
19 // Class implementing or helping the various TTree cloning method //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TObjArray.h"
24 
25 #include <vector>
26 
27 #ifdef R__OLDHPACC
28 namespace std {
29  using ::string;
30  using ::vector;
31 }
32 #endif
33 
34 class TBranch;
35 class TTree;
36 class TFileCacheRead;
37 
38 class TTreeCloner {
39  TString fWarningMsg; ///< Text of the error message lead to an 'invalid' state
40 
41  Bool_t fIsValid;
42  Bool_t fNeedConversion; ///< True if the fast merge is not possible but a slow merge might possible.
43  UInt_t fOptions;
44  TTree *fFromTree;
45  TTree *fToTree;
46  Option_t *fMethod;
47  TObjArray fFromBranches;
48  TObjArray fToBranches;
49 
50  UInt_t fMaxBaskets;
51  UInt_t *fBasketBranchNum; ///<[fMaxBaskets] Index of the branch(es) of the basket.
52  UInt_t *fBasketNum; ///<[fMaxBaskets] index of the basket within the branch.
53 
54  Long64_t *fBasketSeek; ///<[fMaxBaskets] list of basket position to be read.
55  Long64_t *fBasketEntry; ///<[fMaxBaskets] list of basket start entries.
56  UInt_t *fBasketIndex; ///<[fMaxBaskets] ordered list of basket indices to be written.
57 
58  UShort_t fPidOffset; ///< Offset to be added to the copied key/basket.
59 
60  UInt_t fCloneMethod; ///< Indicates which cloning method was selected.
61  Long64_t fToStartEntries; ///< Number of entries in the target tree before any addition.
62 
63  Int_t fCacheSize; ///< Requested size of the file cache
64  TFileCacheRead *fFileCache; ///< File Cache used to reduce the number of individual reads
65  TFileCacheRead *fPrevCache; ///< Cache that set before the TTreeCloner ctor for the 'from' TTree if any.
66 
67  enum ECloneMethod {
68  kDefault = 0,
69  kSortBasketsByBranch = 1,
70  kSortBasketsByOffset = 2,
71  kSortBasketsByEntry = 3
72  };
73 
74  class CompareSeek {
75  TTreeCloner *fObject;
76  public:
77  CompareSeek(TTreeCloner *obj) : fObject(obj) {}
78  Bool_t operator()(UInt_t i1, UInt_t i2);
79  };
80 
81  class CompareEntry {
82  TTreeCloner *fObject;
83  public:
84  CompareEntry(TTreeCloner *obj) : fObject(obj) {}
85  Bool_t operator()(UInt_t i1, UInt_t i2);
86  };
87 
88  friend class CompareSeek;
89  friend class CompareEntry;
90 
91  void ImportClusterRanges();
92  void CreateCache();
93  UInt_t FillCache(UInt_t from);
94  void RestoreCache();
95 
96 private:
97  TTreeCloner(const TTreeCloner&) = delete;
98  TTreeCloner &operator=(const TTreeCloner&) = delete;
99 
100 public:
101  enum EClonerOptions {
102  kNone = 0,
103  kNoWarnings = BIT(1),
104  kIgnoreMissingTopLevel = BIT(2),
105  kNoFileCache = BIT(3)
106  };
107 
108  TTreeCloner(TTree *from, TTree *to, Option_t *method, UInt_t options = kNone);
109  virtual ~TTreeCloner();
110 
111  void CloseOutWriteBaskets();
112  UInt_t CollectBranches(TBranch *from, TBranch *to);
113  UInt_t CollectBranches(TObjArray *from, TObjArray *to);
114  UInt_t CollectBranches();
115  void CollectBaskets();
116  void CopyMemoryBaskets();
117  void CopyStreamerInfos();
118  void CopyProcessIds();
119  const char *GetWarning() const { return fWarningMsg; }
120  Bool_t Exec();
121  Bool_t IsValid() { return fIsValid; }
122  Bool_t NeedConversion() { return fNeedConversion; }
123  void SetCacheSize(Int_t size);
124  void SortBaskets();
125  void WriteBaskets();
126 
127  ClassDef(TTreeCloner,0); // helper used for the fast cloning of TTrees.
128 };
129 
130 #endif