Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TBasketSQL.cxx
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Philippe Canal and al. 08/2004
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 TBASKETSQL_CXX
13 #define TBASKETSQL_CXX
14 
15 #include "TBasket.h"
16 #include "TBuffer.h"
17 #include "TTree.h"
18 #include "TBranch.h"
19 #include "TFile.h"
20 #include "TMath.h"
21 #include "TBasketSQL.h"
22 #include <Riostream.h>
23 #include <vector>
24 #include "TTreeSQL.h"
25 #include "TBufferSQL.h"
26 
27 ClassImp(TBasketSQL);
28 
29 namespace std {} using namespace std;
30 
31 /** \class TBasketSQL
32 \ingroup tree
33 
34 Implement TBasket for a SQL backend.
35 */
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Default constructor.
39 
40 TBasketSQL::TBasketSQL() : TBasket(), fResultPtr(0), fRowPtr(0), fInsertQuery(0)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Regular constructor.
46 
47 TBasketSQL::TBasketSQL(const char *name, const char *title, TBranch *branch,
48  TSQLResult ** rs, TString *insert_query,
49  std::vector<Int_t> *vc, TSQLRow **r) :
50  fResultPtr(rs),fRowPtr(r)
51 {
52  SetName(name);
53  SetTitle(title);
54  fClassName = "TBasketSQL";
55  fBufferSize = branch->GetBasketSize();
56  fNevBufSize = branch->GetEntryOffsetLen();
57  fNevBuf = 0;
58  fEntryOffset = 0; //Must be set to 0 before calling Sizeof
59  fDisplacement= 0; //Must be set to 0 before calling Sizeof
60  fBuffer = 0; //Must be set to 0 before calling Sizeof
61  fInsertQuery = insert_query;
62 
63  if (vc==0) {
64  fBufferRef = 0;
65  } else {
66  fBufferRef = new TBufferSQL(TBuffer::kWrite, fBufferSize, vc, fInsertQuery, fRowPtr);
67  }
68  fHeaderOnly = kTRUE;
69  fLast = 0; // Must initialize before calling Streamer()
70  //Streamer(*fBufferRef);
71  fBuffer = 0;
72  fBranch = branch;
73  fHeaderOnly = kFALSE;
74  branch->GetTree()->IncrementTotalBuffers(fBufferSize);
75 
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Destructor
80 
81 TBasketSQL::~TBasketSQL()
82 {
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Create a TSQLBuffer for this basket.
87 
88 void TBasketSQL::CreateBuffer(const char *name, TString title,
89  std::vector<Int_t> *vc,
90  TBranch *branch, TSQLResult ** rs)
91 {
92  fResultPtr = rs;
93  SetName(name);
94  SetTitle(title);
95  fClassName = "TBasketSQL";
96  fBufferSize = branch->GetBasketSize();
97  fNevBufSize = branch->GetEntryOffsetLen();
98  fNevBuf = 0;
99  fEntryOffset = 0; //Must be set to 0 before calling Sizeof
100  fDisplacement= 0; //Must be set to 0 before calling Sizeof
101  fBuffer = 0; //Must be set to 0 before calling Sizeof
102 
103  if(vc==0) {
104  fBufferRef = 0;
105  Error("CreateBuffer","Need a vector of columns\n");
106  } else {
107  fBufferRef = new TBufferSQL(TBuffer::kWrite, fBufferSize, vc, fInsertQuery, fRowPtr);
108  }
109  fHeaderOnly = kTRUE;
110  fLast = 0;
111  //Streamer(*fBufferRef);
112  fBuffer = 0;
113  fBranch = branch;
114  fHeaderOnly = kFALSE;
115  branch->GetTree()->IncrementTotalBuffers(fBufferSize);
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Prepare the basket for the next entry.
120 
121 void TBasketSQL::PrepareBasket(Long64_t entry)
122 {
123  ((TBufferSQL*)fBufferRef)->ResetOffset();
124  ((TTreeSQL*)fBranch->GetTree())->PrepEntry(entry);
125  fBufferRef->Reset();
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// See TBasket::ReadBasketBytes. This is not implemented in TBasketSQL.
130 
131 Int_t TBasketSQL::ReadBasketBytes(Long64_t , TFile *)
132 {
133  Error("ReadBasketBytes","This member function should not be called!");
134  return 0;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// See TBasket::ReadBasketBuffers. This is not implemented in TBasketSQL.
139 
140 Int_t TBasketSQL::ReadBasketBuffers(Long64_t , Int_t, TFile *)
141 {
142  Error("ReadBasketBuffers","This member function should not be called!");
143  return 0;
144 }
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// See TBasket::Reset
148 
149 void TBasketSQL::Reset()
150 {
151  TBasket::Reset();
152 }
153 ////////////////////////////////////////////////////////////////////////////////
154 /// See TBasket::Update.
155 
156 void TBasketSQL::Update(Int_t, Int_t)
157 {
158  ((TBufferSQL*)fBufferRef)->ResetOffset();
159  fNevBuf++;
160 }
161 
162 #endif