Logo ROOT   6.12/07
Reference Guide
TTreeCloner.cxx
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 /** \class TTreeCloner
13 \ingroup tree
14 
15 Class implementing or helping the various TTree cloning method
16 */
17 
18 #include "TBasket.h"
19 #include "TBranch.h"
20 #include "TBranchClones.h"
21 #include "TBranchElement.h"
22 #include "TStreamerInfo.h"
23 #include "TBranchRef.h"
24 #include "TError.h"
25 #include "TProcessID.h"
26 #include "TMath.h"
27 #include "TTree.h"
28 #include "TTreeCloner.h"
29 #include "TFile.h"
30 #include "TLeafB.h"
31 #include "TLeafI.h"
32 #include "TLeafL.h"
33 #include "TLeafS.h"
34 #include "TLeafO.h"
35 #include "TLeafC.h"
36 #include "TFileCacheRead.h"
37 
38 #include <algorithm>
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 
43 {
44  if (fObject->fBasketSeek[i1] == fObject->fBasketSeek[i2]) {
45  if (fObject->fBasketEntry[i1] == fObject->fBasketEntry[i2]) {
46  return i1 < i2;
47  }
48  return fObject->fBasketEntry[i1] < fObject->fBasketEntry[i2];
49  }
50  return fObject->fBasketSeek[i1] < fObject->fBasketSeek[i2];
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 
56 {
57  if (fObject->fBasketEntry[i1] == fObject->fBasketEntry[i2]) {
58  return i1 < i2;
59  }
60  return fObject->fBasketEntry[i1] < fObject->fBasketEntry[i2];
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Constructor. This object would transfer the data from
65 /// 'from' to 'to' using the method indicated in method.
66 ///
67 /// The value of the parameter 'method' determines in which
68 /// order the branches' baskets are written to the output file.
69 ///
70 /// When a TTree is filled the data is stored in the individual
71 /// branches' basket. Each basket is written individually to
72 /// the disk as soon as it is full. In consequence the baskets
73 /// of branches that contain 'large' data chunk are written to
74 /// the disk more often.
75 ///
76 /// There is currently 3 supported sorting order:
77 ///
78 /// SortBasketsByOffset (the default)
79 /// SortBasketsByBranch
80 /// SortBasketsByEntry
81 ///
82 /// When using SortBasketsByOffset the baskets are written in
83 /// the output file in the same order as in the original file
84 /// (i.e. the basket are sorted on their offset in the original
85 /// file; Usually this also means that the baskets are sorted
86 /// on the index/number of the _last_ entry they contain)
87 ///
88 /// When using SortBasketsByBranch all the baskets of each
89 /// individual branches are stored contiguously. This tends to
90 /// optimize reading speed when reading a small number (1->5) of
91 /// branches, since all their baskets will be clustered together
92 /// instead of being spread across the file. However it might
93 /// decrease the performance when reading more branches (or the full
94 /// entry).
95 ///
96 /// When using SortBasketsByEntry the baskets with the lowest
97 /// starting entry are written first. (i.e. the baskets are
98 /// sorted on the index/number of the first entry they contain).
99 /// This means that on the file the baskets will be in the order
100 /// in which they will be needed when reading the whole tree
101 /// sequentially.
102 
103 TTreeCloner::TTreeCloner(TTree *from, TTree *to, Option_t *method, UInt_t options) :
104  fWarningMsg(),
105  fIsValid(kTRUE),
107  fOptions(options),
108  fFromTree(from),
109  fToTree(to),
110  fMethod(method),
111  fFromBranches( from ? from->GetListOfLeaves()->GetEntries()+1 : 0),
112  fToBranches( to ? to->GetListOfLeaves()->GetEntries()+1 : 0),
119  fPidOffset(0),
121  fToStartEntries(0),
122  fCacheSize(0LL),
123  fFileCache(nullptr),
124  fPrevCache(nullptr)
125 {
126  TString opt(method);
127  opt.ToLower();
128  if (opt.Contains("sortbasketsbybranch")) {
129  //::Info("TTreeCloner::TTreeCloner","use: kSortBasketsByBranch");
131  } else if (opt.Contains("sortbasketsbyentry")) {
132  //::Info("TTreeCloner::TTreeCloner","use: kSortBasketsByEntry");
134  } else {
135  //::Info("TTreeCloner::TTreeCloner","use: kSortBasketsByOffset");
137  }
139 
140  if (fFromTree == nullptr) {
141  if (to)
142  fWarningMsg.Form("An input TTree is required (cloning to %s).",
143  to->GetName());
144  else
145  fWarningMsg.Form("An input and output TTree are required.");
146  if (!(fOptions & kNoWarnings)) {
147  Warning("TTreeCloner::TTreeCloner", "%s", fWarningMsg.Data());
148  }
149  fIsValid = kFALSE;
150  }
151  if (fToTree == nullptr) {
152  fWarningMsg.Form("An output TTree is required (cloning %s).",
153  from ? from->GetName() : "no tree");
154  if (!(fOptions & kNoWarnings)) {
155  Warning("TTreeCloner::TTreeCloner", "%s", fWarningMsg.Data());
156  }
157  fIsValid = kFALSE;
158  } else if (fToTree->GetDirectory() == nullptr) {
159  fWarningMsg.Form("The output TTree (%s) must be associated with a directory.",
160  fToTree->GetName());
161  if (!(fOptions & kNoWarnings)) {
162  Warning("TTreeCloner::TTreeCloner", "%s", fWarningMsg.Data());
163  }
164  fIsValid = kFALSE;
165  } else if (fToTree->GetCurrentFile() == nullptr) {
166  fWarningMsg.Form("The output TTree (%s) must be associated with a directory (%s) that is in a file.",
168  if (!(fOptions & kNoWarnings)) {
169  Warning("TTreeCloner::TTreeCloner", "%s", fWarningMsg.Data());
170  }
171  fIsValid = kFALSE;
172  } else if (! fToTree->GetDirectory()->IsWritable()) {
174  fWarningMsg.Form("The output TTree (%s) must be associated with a writable file (%s).",
176  } else {
177  fWarningMsg.Form("The output TTree (%s) must be associated with a writable directory (%s in %s).",
179  }
180  if (!(fOptions & kNoWarnings)) {
181  Warning("TTreeCloner::TTreeCloner", "%s", fWarningMsg.Data());
182  }
183  fIsValid = kFALSE;
184  }
185 
186  if (fIsValid && (!(fOptions & kNoFileCache))) {
188  }
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Execute the cloning.
193 
195 {
196  if (!IsValid()) {
197  return kFALSE;
198  }
199  CreateCache();
202  CopyProcessIds();
204  CollectBaskets();
205  SortBaskets();
206  WriteBaskets();
208  RestoreCache();
209 
210  return kTRUE;
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// TTreeCloner destructor
215 
217 {
218  // The file cache was restored to its previous value at the end of Exec,
219  // we can safely delete our cache.
220  delete fFileCache;
221  delete [] fBasketBranchNum;
222  delete [] fBasketNum;
223  delete [] fBasketSeek;
224  delete [] fBasketEntry;
225  delete [] fBasketIndex;
226 }
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Before we can start adding new basket, we need to flush to
230 /// disk the partially filled baskets (the WriteBasket)
231 
233 {
234  for(Int_t i=0; i<fToBranches.GetEntries(); ++i) {
236  to->FlushOneBasket(to->GetWriteBasket());
237  }
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Fill the array of branches, adding the branch 'from' and 'to',
242 /// and matching the sub-branches of the 'from' and 'to' branches.
243 /// Returns the total number of baskets in all the from branch and
244 /// it sub-branches.
245 
247  // Since this is called from the constructor, this can not be a virtual function
248 
249  UInt_t numBaskets = 0;
250  if (from->InheritsFrom(TBranchClones::Class())) {
251  TBranchClones *fromclones = (TBranchClones*) from;
252  TBranchClones *toclones = (TBranchClones*) to;
253  numBaskets += CollectBranches(fromclones->fBranchCount, toclones->fBranchCount);
254 
255  } else if (from->InheritsFrom(TBranchElement::Class())) {
256  Int_t nb = from->GetListOfLeaves()->GetEntries();
257  Int_t fnb = to->GetListOfLeaves()->GetEntries();
258  if (nb != fnb && (nb == 0 || fnb == 0)) {
259  // We might be in the case where one branch is split
260  // while the other is not split. We must reject this match.
261  fWarningMsg.Form("The export branch and the import branch do not have the same split level. (The branch name is %s.)",
262  from->GetName());
263  if (!(fOptions & kNoWarnings)) {
264  Warning("TTreeCloner::CollectBranches", "%s", fWarningMsg.Data());
265  }
267  fIsValid = kFALSE;
268  return 0;
269  }
270  if (((TBranchElement*) from)->GetStreamerType() != ((TBranchElement*) to)->GetStreamerType()) {
271  fWarningMsg.Form("The export branch and the import branch do not have the same streamer type. (The branch name is %s.)",
272  from->GetName());
273  if (!(fOptions & kNoWarnings)) {
274  Warning("TTreeCloner::CollectBranches", "%s", fWarningMsg.Data());
275  }
276  fIsValid = kFALSE;
277  return 0;
278  }
279  TBranchElement *fromelem = (TBranchElement*) from;
280  TBranchElement *toelem = (TBranchElement*) to;
281  if (fromelem->fMaximum > toelem->fMaximum) toelem->fMaximum = fromelem->fMaximum;
282  } else {
283 
284  Int_t nb = from->GetListOfLeaves()->GetEntries();
285  Int_t fnb = to->GetListOfLeaves()->GetEntries();
286  if (nb != fnb) {
287  fWarningMsg.Form("The export branch and the import branch (%s) do not have the same number of leaves (%d vs %d)",
288  from->GetName(), fnb, nb);
289  if (!(fOptions & kNoWarnings)) {
290  Error("TTreeCloner::CollectBranches", "%s", fWarningMsg.Data());
291  }
292  fIsValid = kFALSE;
293  return 0;
294  }
295  for (Int_t i=0;i<nb;i++) {
296 
297  TLeaf *fromleaf = (TLeaf*)from->GetListOfLeaves()->At(i);
298  TLeaf *toleaf = (TLeaf*)to->GetListOfLeaves()->At(i);
299  if (toleaf->IsA() != fromleaf->IsA() ) {
300  // The data type do not match, we can not do a fast merge.
301  fWarningMsg.Form("The export leaf and the import leaf (%s.%s) do not have the data type (%s vs %s)",
302  from->GetName(),fromleaf->GetName(),fromleaf->GetTypeName(),toleaf->GetTypeName());
303  if (! (fOptions & kNoWarnings) ) {
304  Warning("TTreeCloner::CollectBranches", "%s", fWarningMsg.Data());
305  }
306  fIsValid = kFALSE;
308  return 0;
309  }
310  toleaf->IncludeRange( fromleaf );
311  }
312 
313  }
314 
315  fFromBranches.AddLast(from);
316  if (!from->TestBit(TBranch::kDoNotUseBufferMap)) {
317  // Make sure that we reset the Buffer's map if needed.
319  }
320  fToBranches.AddLast(to);
321 
322  numBaskets += from->GetWriteBasket();
323  numBaskets += CollectBranches(from->GetListOfBranches(),to->GetListOfBranches());
324 
325  return numBaskets;
326 }
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 /// Fill the array of branches, matching the branches of the 'from' and 'to' arrays.
330 /// Returns the total number of baskets in all the branches.
331 
333 {
334  // Since this is called from the constructor, this can not be a virtual function
335 
336  Int_t fnb = from->GetEntries();
337  Int_t tnb = to->GetEntries();
338  if (!fnb || !tnb) {
339  return 0;
340  }
341 
342  UInt_t numBasket = 0;
343  Int_t fi = 0;
344  Int_t ti = 0;
345  while (ti < tnb) {
346  TBranch* fb = (TBranch*) from->UncheckedAt(fi);
347  TBranch* tb = (TBranch*) to->UncheckedAt(ti);
348  Int_t firstfi = fi;
349  while (strcmp(fb->GetName(), tb->GetName())) {
350  ++fi;
351  if (fi >= fnb) {
352  // continue at the beginning
353  fi = 0;
354  }
355  if (fi==firstfi) {
356  // We tried all the branches and there is not match.
357  fb = 0;
358  break;
359  }
360  fb = (TBranch*) from->UncheckedAt(fi);
361  }
362  if (fb) {
363  numBasket += CollectBranches(fb, tb);
364  ++fi;
365  if (fi >= fnb) {
366  fi = 0;
367  }
368  } else {
369  if (tb->GetMother()==tb) {
370  // Top level branch.
371  if (!(fOptions & kIgnoreMissingTopLevel)) {
372  fWarningMsg.Form("One of the export top level branches (%s) is not present in the import TTree.",
373  tb->GetName());
374  if (!(fOptions & kNoWarnings)) {
375  Error("TTreeCloner::CollectBranches", "%s", fWarningMsg.Data());
376  }
377  fIsValid = kFALSE;
378  }
379  } else {
380  fWarningMsg.Form("One of the export sub-branches (%s) is not present in the import TTree.",
381  tb->GetName());
382  if (!(fOptions & kNoWarnings)) {
383  Error("TTreeCloner::CollectBranches", "%s", fWarningMsg.Data());
384  }
385  fIsValid = kFALSE;
386  }
387  }
388  ++ti;
389  }
390  return numBasket;
391 }
392 
393 ////////////////////////////////////////////////////////////////////////////////
394 /// Fill the array of branches, matching the branches of the 'from' and 'to' TTrees
395 /// Returns the total number of baskets in all the branches.
396 
398 {
399  // Since this is called from the constructor, this can not be a virtual function
400 
401  if (!fFromTree || !fToTree) {
402  return 0;
403  }
406 
407  if (fFromTree->GetBranchRef()) {
408  fToTree->BranchRef();
410  }
411  return numBasket;
412 }
413 
414 ////////////////////////////////////////////////////////////////////////////////
415 /// Collect the information about the on-file basket that need
416 /// to be copied.
417 
419 {
421 
422  for(UInt_t i=0,bi=0; i<len; ++i) {
424  for(Int_t b=0; b<from->GetWriteBasket(); ++b,++bi) {
425  fBasketBranchNum[bi] = i;
426  fBasketNum[bi] = b;
427  fBasketSeek[bi] = from->GetBasketSeek(b);
428  //fprintf(stderr,"For %s %d %lld\n",from->GetName(),bi,fBasketSeek[bi]);
429  fBasketEntry[bi] = from->GetBasketEntry()[b];
430  fBasketIndex[bi] = bi;
431  }
432  }
433 }
434 
435 ////////////////////////////////////////////////////////////////////////////////
436 /// Make sure that all the needed TStreamerInfo are
437 /// present in the output file
438 
440 {
441  TFile *fromFile = fFromTree->GetDirectory()->GetFile();
442  TFile *toFile = fToTree->GetDirectory()->GetFile();
443  TList *l = fromFile->GetStreamerInfoList();
444  TIter next(l);
445  TStreamerInfo *oldInfo;
446  while ( (oldInfo = (TStreamerInfo*)next()) ) {
447  if (oldInfo->IsA() != TStreamerInfo::Class()) {
448  continue;
449  }
450  TStreamerInfo *curInfo = 0;
451  TClass *cl = TClass::GetClass(oldInfo->GetName());
452 
453  if (!cl->IsLoaded() || cl->GetNew()) {
454  // Insure that the TStreamerInfo is loaded
455  curInfo = (TStreamerInfo*)cl->GetStreamerInfo(oldInfo->GetClassVersion());
456  if (oldInfo->GetClassVersion()==1) {
457  // We may have a Foreign class let's look using the
458  // checksum:
459  TStreamerInfo *matchInfo = (TStreamerInfo*)cl->FindStreamerInfo(oldInfo->GetCheckSum());
460  if (matchInfo) {
461  curInfo = matchInfo;
462  }
463  }
464  curInfo->ForceWriteInfo(toFile);
465  } else {
466  // If there is no default constructor the GetStreamerInfo
467  // will not work. It also means (hopefully) that an
468  // inheriting class has a streamerInfo in the list (which
469  // will induces the setting of this streamerInfo)
470 
471  oldInfo->ForceWriteInfo(toFile);
472  }
473  }
474  delete l;
475 }
476 
477 ////////////////////////////////////////////////////////////////////////////////
478 /// Transfer the basket from the input file to the output file
479 
481 {
482  TBasket *basket = 0;
483  for(Int_t i=0; i<fToBranches.GetEntries(); ++i) {
484  TBranch *from = (TBranch*)fFromBranches.UncheckedAt( i );
485  TBranch *to = (TBranch*)fToBranches.UncheckedAt( i );
486 
487  basket = from->GetListOfBaskets()->GetEntries() ? from->GetBasket(from->GetWriteBasket()) : 0;
488  if (basket) {
489  basket = (TBasket*)basket->Clone();
490  basket->SetBranch(to);
491  to->AddBasket(*basket, kFALSE, fToStartEntries+from->GetBasketEntry()[from->GetWriteBasket()]);
492  } else {
494  }
495  // In older files, if the branch is a TBranchElement non-terminal 'object' branch, it's basket will contain 0
496  // events, in newer file in the same case, the write basket will be missing.
497  if (from->GetEntries()!=0 && from->GetWriteBasket()==0 && (basket==0 || basket->GetNevBuf()==0)) {
498  to->SetEntries(to->GetEntries()+from->GetEntries());
499  }
500  }
501 }
502 
503 ////////////////////////////////////////////////////////////////////////////////
504 /// Make sure that all the needed TStreamerInfo are
505 /// present in the output file
506 
508 {
509  // NOTE: We actually need to merge the ProcessId somehow :(
510 
511  TFile *fromfile = fFromTree->GetDirectory()->GetFile();
512  TFile *tofile = fToTree->GetDirectory()->GetFile();
513 
514  fPidOffset = tofile->GetNProcessIDs();
515 
516  TIter next(fromfile->GetListOfKeys());
517  TKey *key;
518  TDirectory::TContext cur(fromfile);
519  while ((key = (TKey*)next())) {
520  if (!strcmp(key->GetClassName(),"TProcessID")) {
521  TProcessID *pid = (TProcessID*)key->ReadObjectAny(0);
522  if (!pid) continue;
523 
524  //UShort_t out = TProcessID::WriteProcessID(id,tofile);
525  UShort_t out = 0;
526  TObjArray *pids = tofile->GetListOfProcessIDs();
527  Int_t npids = tofile->GetNProcessIDs();
528  Bool_t wasIn = kFALSE;
529  for (Int_t i=0;i<npids;i++) {
530  if (pids->At(i) == pid) {out = (UShort_t)i; wasIn = kTRUE; break;}
531  }
532 
533  if (!wasIn) {
534  TDirectory *dirsav = gDirectory;
535  tofile->cd();
536  tofile->SetBit(TFile::kHasReferences);
537  pids->AddAtAndExpand(pid,npids);
538  pid->IncrementCount();
539  char name[32];
540  snprintf(name,32,"ProcessID%d",npids);
541  pid->Write(name);
542  tofile->IncrementProcessIDs();
543  if (gDebug > 0) {
544  Info("WriteProcessID", "name=%s, file=%s", name, tofile->GetName());
545  }
546  if (dirsav) dirsav->cd();
547  out = (UShort_t)npids;
548  }
549  if (out<fPidOffset) {
550  Error("CopyProcessIDs","Copied %s from %s might already exist!\n",
551  pid->GetName(),fromfile->GetName());
552  }
553  }
554  }
555 }
556 
557 ////////////////////////////////////////////////////////////////////////////////
558 /// Create a TFileCacheRead if it was requested.
559 
561 {
562  if (fCacheSize && fFromTree->GetCurrentFile()) {
564  auto prev = f->GetCacheRead(fFromTree);
565  if (fFileCache && prev == fFileCache) {
566  return;
567  }
568  fPrevCache = prev;
569  // Remove the previous cache if any.
570  if (prev) f->SetCacheRead(nullptr, fFromTree);
571  // The constructor attach the new cache.
573  }
574 }
575 
576 ////////////////////////////////////////////////////////////////////////////////
577 /// Restore the TFileCacheRead to its previous value.
578 
580  if (IsValid() && fFileCache && fFromTree->GetCurrentFile()) {
582  f->SetCacheRead(nullptr,fFromTree); // Remove our file cache.
584  }
585 }
586 
587 ////////////////////////////////////////////////////////////////////////////////
588 /// Set the entries and import the cluster range of the
589 
591 {
592  // First undo, the external call to SetEntries
593  // We could improve the interface to optional tell the TTreeCloner that the
594  // SetEntries was not done.
596 
598 
599  // This is only updated by TTree::Fill upon seeing a Flush event in TTree::Fill
600  // So we need to propagate (this has also the advantage of turning on the
601  // history recording feature of SetAutoFlush for the next iteration)
603 
605 }
606 
607 ////////////////////////////////////////////////////////////////////////////////
608 /// Set the TFile cache size to be used.
609 /// Note that the default is to use the same size as the default TTreeCache for
610 /// the input tree.
611 /// \param size Size of the cache. Zero disable the use of the cache.
612 
614 {
615  fCacheSize = size;
616  if (IsValid() && fFileCache) {
617  if (fCacheSize == 0 || fCacheSize != fFileCache->GetBufferSize()) {
619  f->SetCacheRead(nullptr,fFromTree);
620  delete fFileCache;
621  fFileCache = nullptr;
622  }
623  }
624  // Note if the TFile cache is needed, it will be created at the
625  // beginning of Exec.
626 }
627 
628 ////////////////////////////////////////////////////////////////////////////////
629 /// Sort the basket according to the user request.
630 
632 {
633  // Currently this sort __has to__ preserve the order
634  // of basket for each individual branch.
635 
636  switch (fCloneMethod) {
638  // nothing to do, it is already sorted.
639  break;
640  case kSortBasketsByEntry: {
641  for(UInt_t i = 0; i < fMaxBaskets; ++i) { fBasketIndex[i] = i; }
642  std::sort(fBasketIndex, fBasketIndex+fMaxBaskets, CompareEntry( this) );
643  break;
644  }
646  default: {
647  for(UInt_t i = 0; i < fMaxBaskets; ++i) { fBasketIndex[i] = i; }
648  std::sort(fBasketIndex, fBasketIndex+fMaxBaskets, CompareSeek( this) );
649  break;
650  }
651  }
652 }
653 
654 ////////////////////////////////////////////////////////////////////////////////
655 /// Fill the file cache with the next set of basket.
656 ///
657 /// \param from index of the first lement of fFromBranches to start caching
658 /// \return The index of first element of fFromBranches that is not in the cache
660 {
661  if (!fFileCache) return 0;
662  // Reset the cache
663  fFileCache->Prefetch(0, 0);
664  Long64_t size = 0;
665  for (UInt_t j = from; j < fMaxBaskets; ++j) {
667 
668 
669  Int_t index = fBasketNum[ fBasketIndex[j] ];
670  Long64_t pos = frombr->GetBasketSeek(index);
671  Int_t len = frombr->GetBasketBytes()[index];
672  if (pos && len) {
673  size += len;
674  if (size > fFileCache->GetBufferSize()) {
675  return j;
676  }
677  fFileCache->Prefetch(pos,len);
678  }
679  }
680  return fMaxBaskets;
681 }
682 
683 ////////////////////////////////////////////////////////////////////////////////
684 /// Transfer the basket from the input file to the output file
685 
687 {
688  TBasket *basket = new TBasket();
689  for(UInt_t j = 0, notCached = 0; j<fMaxBaskets; ++j) {
692 
693  TFile *tofile = to->GetFile(0);
694  TFile *fromfile = from->GetFile(0);
695 
696  Int_t index = fBasketNum[ fBasketIndex[j] ];
697 
698  Long64_t pos = from->GetBasketSeek(index);
699  if (pos!=0) {
700  if (fFileCache && j >= notCached) {
701  notCached = FillCache(notCached);
702  }
703  if (from->GetBasketBytes()[index] == 0) {
704  from->GetBasketBytes()[index] = basket->ReadBasketBytes(pos, fromfile);
705  }
706  Int_t len = from->GetBasketBytes()[index];
707 
708  basket->LoadBasketBuffers(pos,len,fromfile,fFromTree);
710  basket->CopyTo(tofile);
711  to->AddBasket(*basket,kTRUE,fToStartEntries + from->GetBasketEntry()[index]);
712  } else {
713  TBasket *frombasket = from->GetBasket( index );
714  if (frombasket && frombasket->GetNevBuf()>0) {
715  TBasket *tobasket = (TBasket*)frombasket->Clone();
716  tobasket->SetBranch(to);
717  to->AddBasket(*tobasket, kFALSE, fToStartEntries+from->GetBasketEntry()[index]);
718  to->FlushOneBasket(to->GetWriteBasket());
719  }
720  }
721  }
722  delete basket;
723 }
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:43
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
TTreeCloner(const TTreeCloner &)=delete
Int_t ReadBasketBytes(Long64_t pos, TFile *file)
Read basket buffers in memory and cleanup.
Definition: TBasket.cxx:686
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:785
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:32
UInt_t * fBasketIndex
[fMaxBaskets] ordered list of basket indices to be written.
Definition: TTreeCloner.h:56
An array of TObjects.
Definition: TObjArray.h:37
Long64_t * GetBasketEntry() const
Definition: TBranch.h:165
void ImportClusterRanges()
Set the entries and import the cluster range of the.
void RestoreCache()
Restore the TFileCacheRead to its previous value.
Long64_t * fBasketEntry
[fMaxBaskets] list of basket start entries.
Definition: TTreeCloner.h:55
long long Long64_t
Definition: RtypesCore.h:69
friend class CompareEntry
Definition: TTreeCloner.h:89
TObjArray * GetListOfBaskets()
Definition: TBranch.h:193
Int_t FlushOneBasket(UInt_t which)
If we have a write basket in memory and it contains some entries and has not yet been written to disk...
Definition: TBranch.cxx:1133
A cache when reading files over the network.
const char Option_t
Definition: RtypesCore.h:62
void WriteBaskets()
Transfer the basket from the input file to the output file.
virtual void SetCacheRead(TFileCacheRead *cache, TObject *tree=0, ECacheAction action=kDisconnect)
Set a pointer to the read cache.
Definition: TFile.cxx:2242
unsigned short UShort_t
Definition: RtypesCore.h:36
virtual const char * GetTypeName() const
Definition: TLeaf.h:82
Long64_t fToStartEntries
Number of entries in the target tree before any addition.
Definition: TTreeCloner.h:61
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist...
Definition: TClass.cxx:4420
TObjArray * GetListOfProcessIDs() const
Definition: TFile.h:207
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
void ForceWriteInfo(TFile *file, Bool_t force=kFALSE)
Recursively mark streamer infos for writing to a file.
Basic string class.
Definition: TString.h:125
TBranch * fBranchCount
Branch with clones count.
Definition: TBranchClones.h:37
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
virtual void Prefetch(Long64_t pos, Int_t len)
Add block of length len at position pos in the list of blocks to be prefetched.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
ROOT::NewFunc_t GetNew() const
TObject * At(Int_t idx) const
Definition: TObjArray.h:165
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
void SetBranch(TBranch *branch)
Definition: TBasket.h:129
virtual TObjArray * GetListOfBranches()
Definition: TTree.h:407
UInt_t fMaxBaskets
Definition: TTreeCloner.h:50
Int_t * GetBasketBytes() const
Definition: TBranch.h:164
void ImportClusterRanges(TTree *fromtree)
Appends the cluster range information stored in &#39;fromtree&#39; to this tree, including the value of fAuto...
Definition: TTree.cxx:6039
void Class()
Definition: Class.C:29
virtual Bool_t IncludeRange(TLeaf *)
Definition: TLeaf.h:89
virtual Bool_t IsWritable() const
Definition: TDirectory.h:163
Int_t fMaximum
Maximum entries for a TClonesArray or variable array.
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process&#39;s memory.
Definition: TClass.cxx:5642
void CloseOutWriteBaskets()
Before we can start adding new basket, we need to flush to disk the partially filled baskets (the Wri...
void Info(const char *location, const char *msgfmt,...)
Long64_t fFlushedBytes
Number of auto-flushed bytes.
Definition: TTree.h:80
TObjArray * GetListOfBranches()
Definition: TBranch.h:194
TBasket * GetBasket(Int_t basket)
Return pointer to basket basketnumber in this Branch.
Definition: TBranch.cxx:1174
void SortBaskets()
Sort the basket according to the user request.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:69
TFileCacheRead * fPrevCache
Cache that set before the TTreeCloner ctor for the &#39;from&#39; TTree if any.
Definition: TTreeCloner.h:65
void Error(const char *location, const char *msgfmt,...)
virtual TFile * GetFile() const
Definition: TDirectory.h:147
Bool_t IsValid()
Definition: TTreeCloner.h:121
virtual TTree * GetTree() const
Definition: TTree.h:434
virtual void IncrementProcessIDs()
Definition: TFile.h:228
A doubly linked list.
Definition: TList.h:44
TTree * fFromTree
Definition: TTreeCloner.h:44
virtual void AddLastBasket(Long64_t startEntry)
Add the start entry of the write basket (not yet created)
Definition: TBranch.cxx:581
virtual void IncrementPidOffset(UShort_t offset)
Increment fPidOffset by &#39;offset&#39;.
Definition: TKey.cxx:634
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:234
TVirtualStreamerInfo * FindStreamerInfo(TObjArray *arr, UInt_t checksum) const
Find the TVirtualStreamerInfo in the StreamerInfos corresponding to checksum.
Definition: TClass.cxx:6737
UInt_t GetCheckSum() const
virtual void SetEntries(Long64_t entries)
Set the number of entries in this branch.
Definition: TBranch.cxx:2396
void CopyProcessIds()
Make sure that all the needed TStreamerInfo are present in the output file.
void CopyStreamerInfos()
Make sure that all the needed TStreamerInfo are present in the output file.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Int_t GetWriteBasket() const
Definition: TBranch.h:186
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2343
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:283
unsigned int UInt_t
Definition: RtypesCore.h:42
TFile * GetCurrentFile() const
Return pointer to the current file.
Definition: TTree.cxx:5172
Manages buffers for branches of a Tree.
Definition: TBasket.h:34
TObjArray fToBranches
Definition: TTreeCloner.h:48
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual TList * GetStreamerInfoList()
Read the list of TStreamerInfo objects written to this file.
Definition: TFile.cxx:1341
TTreeCloner * fObject
Definition: TTreeCloner.h:75
virtual TBranchRef * GetBranchRef() const
Definition: TTree.h:369
friend class CompareSeek
Definition: TTreeCloner.h:88
void Warning(const char *location, const char *msgfmt,...)
Bool_t operator()(UInt_t i1, UInt_t i2)
Definition: TTreeCloner.cxx:55
A Branch for the case of an object.
virtual Long64_t GetBasketSeek(Int_t basket) const
Return address of basket in the file.
Definition: TBranch.cxx:1244
void CreateCache()
Create a TFileCacheRead if it was requested.
const Bool_t kFALSE
Definition: RtypesCore.h:88
UInt_t CollectBranches()
Fill the array of branches, matching the branches of the &#39;from&#39; and &#39;to&#39; TTrees Returns the total num...
Bool_t Exec()
Execute the cloning.
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:89
UInt_t * fBasketNum
[fMaxBaskets] index of the basket within the branch.
Definition: TTreeCloner.h:52
Long64_t GetCacheAutoSize(Bool_t withDefault=kFALSE) const
Used for automatic sizing of the cache.
Definition: TTree.cxx:5111
Bool_t operator()(UInt_t i1, UInt_t i2)
Definition: TTreeCloner.cxx:42
Describe directory structure in memory.
Definition: TDirectory.h:34
TDirectory * GetDirectory() const
Definition: TTree.h:381
virtual Int_t GetBufferSize() const
UInt_t fOptions
Definition: TTreeCloner.h:43
UInt_t FillCache(UInt_t from)
Fill the file cache with the next set of basket.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:570
UShort_t fPidOffset
Offset to be added to the copied key/basket.
Definition: TTreeCloner.h:58
TObjArray * GetListOfLeaves()
Definition: TBranch.h:195
TFileCacheRead * fFileCache
File Cache used to reduce the number of individual reads.
Definition: TTreeCloner.h:64
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2887
virtual Long64_t GetEntries() const
Definition: TTree.h:382
UInt_t fCloneMethod
Indicates which cloning method was selected.
Definition: TTreeCloner.h:60
void SetCacheSize(Int_t size)
Set the TFile cache size to be used.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
virtual TBranch * BranchRef()
Build the optional branch supporting the TRefTable.
Definition: TTree.cxx:2188
UInt_t * fBasketBranchNum
[fMaxBaskets] Index of the branch(es) of the basket.
Definition: TTreeCloner.h:51
Int_t GetClassVersion() const
Long64_t GetEntries() const
Definition: TBranch.h:199
Int_t GetNevBuf() const
Definition: TBasket.h:117
Class implementing or helping the various TTree cloning method.
Definition: TTreeCloner.h:38
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:497
A Branch for the case of an array of clone objects.
Definition: TBranchClones.h:29
auto * l
Definition: textangle.C:4
virtual TList * GetListOfKeys() const
virtual Int_t GetNProcessIDs() const
Definition: TFile.h:210
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual void AddBasket(TBasket &b, Bool_t ondisk, Long64_t startEntry)
Add the basket to this branch.
Definition: TBranch.cxx:515
#define snprintf
Definition: civetweb.c:822
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:522
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
Bool_t fNeedConversion
True if the fast merge is not possible but a slow merge might possible.
Definition: TTreeCloner.h:42
TFileCacheRead * GetCacheRead(TObject *tree=0) const
Return a pointer to the current read cache.
Definition: TFile.cxx:1214
virtual void AddLast(TObject *obj)
Add object in the next empty slot in the array.
Definition: TObjArray.cxx:177
A TTree object has a header with a name and a title.
Definition: TTree.h:70
#define gDirectory
Definition: TDirectory.h:213
TString fWarningMsg
Text of the error message lead to an &#39;invalid&#39; state.
Definition: TTreeCloner.h:39
Long64_t CopyTo(TFile *to)
Copy the basket of this branch onto the file to.
Definition: TBasket.cxx:136
void ResetBit(UInt_t f)
Definition: TObject.h:171
TTree * fToTree
Definition: TTreeCloner.h:45
virtual TFile * GetFile(Int_t mode=0)
Return pointer to the file where branch buffers reside, returns 0 in case branch buffers reside in th...
Definition: TBranch.cxx:1492
virtual Long64_t SetEntries(Long64_t n=-1)
Change number of entries in the tree.
Definition: TTree.cxx:8509
A TTree is a list of TBranches.
Definition: TBranch.h:59
Long64_t * fBasketSeek
[fMaxBaskets] list of basket position to be read.
Definition: TTreeCloner.h:54
Option_t * fMethod
Definition: TTreeCloner.h:46
virtual ~TTreeCloner()
TTreeCloner destructor.
void CopyMemoryBaskets()
Transfer the basket from the input file to the output file.
const Bool_t kTRUE
Definition: RtypesCore.h:87
void CollectBaskets()
Collect the information about the on-file basket that need to be copied.
TBranch * GetMother() const
Get our top-level parent branch in the tree.
Definition: TBranch.cxx:1709
char name[80]
Definition: TGX11.cxx:109
Int_t fCacheSize
Requested size of the file cache.
Definition: TTreeCloner.h:63
TObjArray fFromBranches
Definition: TTreeCloner.h:47
Int_t LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree=0)
Load basket buffers in memory without unziping.
Definition: TBasket.cxx:235
Bool_t fIsValid
Definition: TTreeCloner.h:41
const char * Data() const
Definition: TString.h:345