// @(#)root/tree:$Id$
// Author: Axel Naumann, 2010-08-02

/*************************************************************************
 * Copyright (C) 1995-2013, 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_TTreeReader
#define ROOT_TTreeReader


////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TTreeReader                                                            //
//                                                                        //
// A simple interface for reading trees or chains.                        //
//                                                                        //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

#ifndef ROOT_THashTable
#include "THashTable.h"
#endif
#ifndef ROOT_TTree
#include "TTree.h"
#endif
#ifndef ROOT_TTreeReaderUtils
#include "TTreeReaderUtils.h"
#endif

#include <deque>

class TDictionary;
class TDirectory;
class TFileCollection;

namespace ROOT {
   class TBranchProxyDirector;
}

class TTreeReader: public TObject {
public:

   enum EEntryStatus {
      kEntryValid = 0, // data read okay
      kEntryNotLoaded, // no entry has been loaded yet
      kEntryNoTree, // the tree does not exist
      kEntryNotFound, // the tree entry number does not exist
      kEntryChainSetupError, // problem in accessing a chain element, e.g. file without the tree
      kEntryChainFileError, // problem in opening a chain's file
      kEntryDictionaryError, // problem reading dictionary info from tree
   };

   TTreeReader():
      fDirectory(0),
      fEntryStatus(kEntryNoTree),
      fDirector(0)
   {}

   TTreeReader(TTree* tree);
   TTreeReader(const char* keyname, TDirectory* dir = NULL );
   TTreeReader(const char* /*keyname*/, TFileCollection* /*files*/) { Error("TTreeReader()", "Not Implemented!");};

   ~TTreeReader();

   void SetTree(TTree* tree);
   void SetTree(const char* /*keyname*/, TDirectory* /*dir = NULL*/ ) { Error("SetTree()", "Not Implemented!");};
   void SetChain(const char* /*keyname*/, TFileCollection* /*files*/ ) { Error("SetChain()", "Not Implemented!");};

   Bool_t IsChain() const { return TestBit(kBitIsChain); }

   Bool_t Next() { return SetEntry(GetCurrentEntry() + 1) == kEntryValid; }
   EEntryStatus SetEntry(Long64_t entry) { return SetEntryBase(entry, kFALSE); }
   EEntryStatus SetLocalEntry(Long64_t entry) { return SetEntryBase(entry, kTRUE); }

   EEntryStatus GetEntryStatus() const { return fEntryStatus; }

   TTree* GetTree() const { return fTree; }
   Long64_t GetEntries(Bool_t force) const { return fTree ? (force ? fTree->GetEntries() : fTree->GetEntriesFast() ) : -1; }
   Long64_t GetCurrentEntry() const;

protected:
   void Initialize();
   ROOT::TNamedBranchProxy* FindProxy(const char* branchname) const {
      return (ROOT::TNamedBranchProxy*) fProxies.FindObject(branchname); }
   TCollection* GetProxies() { return &fProxies; }

   void RegisterValueReader(ROOT::TTreeReaderValueBase* reader);
   void DeregisterValueReader(ROOT::TTreeReaderValueBase* reader);

   EEntryStatus SetEntryBase(Long64_t entry, Bool_t local);

private:

   enum EPropertyBits {
      kBitIsChain = BIT(14) // our tree is a chain
   };

   TTree* fTree; // tree that's read
   TDirectory* fDirectory; // directory (or current file for chains)
   EEntryStatus fEntryStatus; // status of most recent read request
   ROOT::TBranchProxyDirector* fDirector; // proxying director, owned
   std::deque<ROOT::TTreeReaderValueBase*> fValues; // readers that use our director
   THashTable   fProxies; //attached ROOT::TNamedBranchProxies; owned

   friend class ROOT::TTreeReaderValueBase;
   friend class ROOT::TTreeReaderArrayBase;

   ClassDef(TTreeReader, 0); // A simple interface to read trees
};

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