ROOT logo
// @(#)root/treeplayer:$Id: TChainIndex.h 20882 2007-11-19 11:31:26Z rdm $
// Author: Marek Biskup  07/06/2005

/*************************************************************************
 * Copyright (C) 1995-2004, 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_TChainIndex
#define ROOT_TChainIndex


//////////////////////////////////////////////////////////////////////////
//
// TChainIndex
//
// A Chain Index with majorname and minorname.
// It uses tree indices of all the trees in the chain instead of building
// a new index.
// The index values from the first tree should be less then 
// all the index values from the second tree, and so on.
// If a tree in the chain doesn't have an index the index will be created
// and kept inside this chain index.
// 
//////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TVirtualIndex
#include "TVirtualIndex.h"
#endif

#include <vector>

class TTreeFormula;
class TChain;

class TChainIndex : public TVirtualIndex {

public:
   class TChainIndexEntry {
      // holds a description of indices of trees in the chain. 
   public:
      TChainIndexEntry() : fMinIndexValue(0), fMaxIndexValue(0), fTreeIndex(0) {}

      Long64_t    fMinIndexValue;           // the minimum value of the index
      Long64_t    fMaxIndexValue;           // the maximum value of the index
      TVirtualIndex* fTreeIndex;            // the tree index in case it was created in the constructor,
                                            // otherwise 0
   };
protected:

   TString        fMajorName;               // Index major name
   TString        fMinorName;               // Index minor name
   TTreeFormula  *fMajorFormulaParent;      //! Pointer to major TreeFormula in Parent tree (if any)
   TTreeFormula  *fMinorFormulaParent;      //! Pointer to minor TreeFormula in Parent tree (if any)
   std::vector<TChainIndexEntry> fEntries; // descriptions of indices of trees in the chain.

   std::pair<TVirtualIndex*, Int_t> GetSubTreeIndex(Int_t major, Int_t minor) const;
   void ReleaseSubTreeIndex(TVirtualIndex* index, Int_t treeNo) const;
   void DeleteIndices();

public:
   TChainIndex();
   TChainIndex(const TTree *T, const char *majorname, const char *minorname);
   virtual               ~TChainIndex();
   virtual void           Append(const TVirtualIndex *, Bool_t delaySort = kFALSE);
   virtual Int_t          GetEntryNumberFriend(const TTree *T);
   virtual Long64_t       GetEntryNumberWithIndex(Int_t major, Int_t minor) const;
   virtual Long64_t       GetEntryNumberWithBestIndex(Int_t major, Int_t minor) const;
   const char            *GetMajorName()    const {return fMajorName.Data();}
   const char            *GetMinorName()    const {return fMinorName.Data();}
   virtual Long64_t       GetN()            const {return fEntries.size();}
   virtual TTreeFormula  *GetMajorFormulaParent(const TTree *T);
   virtual TTreeFormula  *GetMinorFormulaParent(const TTree *T);
   virtual void           UpdateFormulaLeaves(const TTree *parent);
   virtual void           SetTree(const TTree *T);

   ClassDef(TChainIndex,1)  //A Tree Index with majorname and minorname.
};

#endif

 TChainIndex.h:1
 TChainIndex.h:2
 TChainIndex.h:3
 TChainIndex.h:4
 TChainIndex.h:5
 TChainIndex.h:6
 TChainIndex.h:7
 TChainIndex.h:8
 TChainIndex.h:9
 TChainIndex.h:10
 TChainIndex.h:11
 TChainIndex.h:12
 TChainIndex.h:13
 TChainIndex.h:14
 TChainIndex.h:15
 TChainIndex.h:16
 TChainIndex.h:17
 TChainIndex.h:18
 TChainIndex.h:19
 TChainIndex.h:20
 TChainIndex.h:21
 TChainIndex.h:22
 TChainIndex.h:23
 TChainIndex.h:24
 TChainIndex.h:25
 TChainIndex.h:26
 TChainIndex.h:27
 TChainIndex.h:28
 TChainIndex.h:29
 TChainIndex.h:30
 TChainIndex.h:31
 TChainIndex.h:32
 TChainIndex.h:33
 TChainIndex.h:34
 TChainIndex.h:35
 TChainIndex.h:36
 TChainIndex.h:37
 TChainIndex.h:38
 TChainIndex.h:39
 TChainIndex.h:40
 TChainIndex.h:41
 TChainIndex.h:42
 TChainIndex.h:43
 TChainIndex.h:44
 TChainIndex.h:45
 TChainIndex.h:46
 TChainIndex.h:47
 TChainIndex.h:48
 TChainIndex.h:49
 TChainIndex.h:50
 TChainIndex.h:51
 TChainIndex.h:52
 TChainIndex.h:53
 TChainIndex.h:54
 TChainIndex.h:55
 TChainIndex.h:56
 TChainIndex.h:57
 TChainIndex.h:58
 TChainIndex.h:59
 TChainIndex.h:60
 TChainIndex.h:61
 TChainIndex.h:62
 TChainIndex.h:63
 TChainIndex.h:64
 TChainIndex.h:65
 TChainIndex.h:66
 TChainIndex.h:67
 TChainIndex.h:68
 TChainIndex.h:69
 TChainIndex.h:70
 TChainIndex.h:71
 TChainIndex.h:72
 TChainIndex.h:73
 TChainIndex.h:74
 TChainIndex.h:75
 TChainIndex.h:76
 TChainIndex.h:77
 TChainIndex.h:78
 TChainIndex.h:79
 TChainIndex.h:80
 TChainIndex.h:81
 TChainIndex.h:82
 TChainIndex.h:83
 TChainIndex.h:84
 TChainIndex.h:85