// @(#)root/tree:$Id$
// Author: Rene Brun   12/01/96

/*************************************************************************
 * 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_TTreeSQL
#define ROOT_TTreeSQL

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TTreeSQL                                                             //
//                                                                      //
// A TTree object is a list of TBranch.                                 //
//   To Create a TTree object one must:                                 //
//    - Create the TTree header via the TTree constructor               //
//    - Call the TBranch constructor for every branch.                  //
//                                                                      //
//   To Fill this object, use member function Fill with no parameters.  //
//     The Fill function loops on all defined TBranch.                  //
//                                                                      //
// TTreeSQL is the TTree implementation interfacing with an SQL         //
// database                                                             //
//                                                                      //
//////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TTree
#include "TTree.h"
#endif

#include <vector>

class TSQLServer;
class TSQLRow;
class TBasketSQL;

class TTreeSQL : public TTree {

protected:
   Int_t                  fCurrentEntry;
   TString                fDB;
   TString                fInsertQuery;
   TString                fQuery;
   TString                fTable;
   TSQLResult            *fResult;
   TSQLRow               *fRow;
   TSQLServer            *fServer;
   Bool_t                 fBranchChecked;

   void                   CheckBasket(TBranch * tb);
   Bool_t                 CheckBranch(TBranch * tb);
   Bool_t                 CheckTable(const TString &table) const;
   TString                CreateBranches(TSQLResult * rs);
   std::vector<Int_t>    *GetColumnIndice(TBranch *branch);
   void                   Init();
   void                   ResetQuery();
   TString                ConvertTypeName(const TString& typeName );
   virtual void           CreateBranch(const TString& branchName,const TString &typeName);
   Bool_t                 CreateTable(const TString& table);
   virtual TBasket       *CreateBasket(TBranch * br);

   virtual TBranch *BranchImp(const char *branchname, const char *classname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel);
   virtual TBranch *BranchImp(const char *branchname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel);

public:
   TTreeSQL(TSQLServer * server, TString DB, const TString& table);

   virtual Int_t          Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="");
   virtual Int_t          Branch(TList *list, Int_t bufsize=32000, Int_t splitlevel=99);
   virtual Int_t          Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99);
   virtual TBranch       *Bronch(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99);
   virtual TBranch       *BranchOld(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=1);
#if !defined(__CINT__)
   virtual TBranch       *Branch(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99);
#endif

   virtual TBranch       *Branch(const char *name, void *address, const char *leaflist, Int_t bufsize);

   virtual Int_t          Fill();
   virtual Int_t          GetEntry(Long64_t entry=0, Int_t getall=0);
   virtual Long64_t       GetEntries()    const;
   virtual Long64_t       GetEntries(const char *sel) { return TTree::GetEntries(sel); }
   virtual Long64_t       GetEntriesFast()const;
           TString        GetTableName(){ return fTable; }
   virtual Long64_t       LoadTree(Long64_t entry);
   virtual Long64_t       PrepEntry(Long64_t entry);
           void           Refresh();

   ClassDef(TTreeSQL,1);  // TTree Implementation read and write to a SQL database.
};


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