Logo ROOT   6.16/01
Reference Guide
TTreeSQL.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/** \class TTreeSQL
13\ingroup tree
14
15Implement TTree for a SQL backend
16*/
17
18#include <Riostream.h>
19#include <vector>
20#include <map>
21#include <stdlib.h>
22
23#include "TString.h"
24#include "TROOT.h"
25#include "TSystem.h"
26#include "TError.h"
27#include "TFile.h"
28#include "TTree.h"
29#include "TLeaf.h"
30#include "TBranch.h"
31
32#include "TSQLRow.h"
33#include "TSQLResult.h"
34#include "TSQLServer.h"
35
36#include "TTreeSQL.h"
37#include "TBasketSQL.h"
38
40
41////////////////////////////////////////////////////////////////////////////////
42/// Constructor with an explicit TSQLServer
43
45 TTree(table.Data(), "Database read from table: " + table, 0), fDB(DB),
46 fTable(table.Data()),
47 fResult(0), fRow(0),
48 fServer(server),
49 fBranchChecked(kFALSE)
50{
51 fCurrentEntry = -1;
52 fQuery = TString("Select * from " + fTable);
53 fEntries = 0;
54
55 if (fServer==0) {
56 Error("TTreeSQL","No TSQLServer specified");
57 return;
58 }
59 if (CheckTable(fTable.Data())) {
60 Init();
61 }
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Not implemented yet
66
67TBranch* TTreeSQL::BranchImp(const char *, const char *,
68 TClass *, void *, Int_t ,
69 Int_t )
70{
71 Fatal("BranchImp","Not implemented yet");
72 return 0;
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Not implemented yet
77
79 void *, Int_t , Int_t )
80{
81 Fatal("BranchImp","Not implemented yet");
82 return 0;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Not implemented yet
87
89 Int_t, const char *)
90{
91 Fatal("Branch","Not implemented yet");
92 return 0;
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Not implemented yet
97
99{
100 Fatal("Branch","Not implemented yet");
101 return 0;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Not implemented yet
106
108 Int_t)
109{
110 Fatal("Branch","Not implemented yet");
111 return 0;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Not implemented yet
116
117TBranch* TTreeSQL::Bronch(const char *, const char *, void *,
118 Int_t, Int_t)
119{
120 Fatal("Bronc","Not implemented yet");
121 return 0;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Not implemented yet
126
127TBranch* TTreeSQL::BranchOld(const char *, const char *,
128 void *, Int_t, Int_t)
129{
130 Fatal("BranchOld","Not implemented yet");
131 return 0;
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Not implemented yet
136
137TBranch *TTreeSQL::Branch(const char *, const char *, void *,
138 Int_t, Int_t)
139{
140 Fatal("Branch","Not implemented yet");
141 return 0;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Create a branch
146
147TBranch * TTreeSQL::Branch(const char *name, void *address,
148 const char *leaflist, Int_t bufsize)
149{
151 TBranch *branch;
152 TString brName;
153
154 for (int i=0;i<nb;i++) {
155 branch = (TBranch*)fBranches.UncheckedAt(i);
156 brName = branch->GetName();
157 if (brName.CompareTo(name) == 0) {
158 // Now if the branch exists in db, root gives a warning and exit
159 // Dealing with duplicate branch has been done, but not tested yet.
160 // So if you want to allow duplicate branch, just comment Fatal() line and uncomment commented
161 // below Fatal() line
162
163 Fatal("Branch()", "Duplicate branch!!!");
164
165 /* Commented. If uncommented, should comment Fatal line.
166 // this is a duplicate branch. So reset data structure memory address and return.
167 branch->SetAddress(address);
168 return branch;
169 */
170 }
171 }
172 return TTree::Branch(name, address, leaflist, bufsize);
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Check if the basket is properly setup
177
179{
180 TBasketSQL* basket = (TBasketSQL *)branch->GetBasket(0);
181
182 if (basket==0) {
183 basket = (TBasketSQL*)CreateBasket(branch);
184 if (basket==0) return;
185 //++(branch->fNBaskets);
186 branch->GetListOfBaskets()->AddAtAndExpand(basket,0);
187 }
188 TBuffer * buffer = basket->GetBufferRef();
189
190 if(buffer == 0){
191 std::vector<Int_t> *columns = GetColumnIndice(branch);
192 if (columns) basket->CreateBuffer(branch->GetName(),"A", columns, branch, &fResult);
193 }
194
195 Int_t nb = branch->GetListOfBranches()->GetEntriesFast();
196 for (int i=0;i<nb;i++) {
197 TBranch * subbranch = (TBranch*)branch->GetListOfBranches()->UncheckedAt(i);
198 if(subbranch) CheckBasket(subbranch);
199 }
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Check if the table has a column corresponding the branch
204/// and that the resultset are properly setup
205
207{
208 if (fServer==0) {
209 return kFALSE;
210 }
211 TString leafName;
212 TLeaf *leaf;
213 Int_t nl;
214 TString str = "";
215 TString typeName = "";
216
217 if (!tb) return kFALSE;
218
219 TBasketSQL *basket = (TBasketSQL *)tb->GetBasket(0);
220 if (!basket) return kFALSE;
221
222 TSQLResult *rs = basket->GetResultSet();
223 if (!rs) {
224 Error("CheckBranch","%s has basket but no resultset yet",tb->GetName());
225 return kFALSE;
226 }
227
228 nl = tb->GetNleaves();
229
230 for(int j=0;j<nl;j++) {
231 leaf = (TLeaf*)tb->GetListOfLeaves()->UncheckedAt(j);
232 typeName = leaf->GetTypeName();
233 typeName = ConvertTypeName(leaf->GetTypeName());
234 leafName = leaf->GetName();
235 str = "";
236 str = tb->GetName();
237 str += "__";
238 str += leafName;
239
240 for (int i=0; i< rs->GetFieldCount(); ++i) {
241 if (str.CompareTo(rs->GetFieldName(i),TString::kIgnoreCase) == 0) return kTRUE;
242 }
243 // We assume that if ONE of the leaf is in the table, then ALL the leaf are in
244 // the table.
245 // TODO: this assumption is harmful if user changes branch structure while keep its name
246 CreateBranch(str, typeName);
247 }
248 return kFALSE;
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Check the table exist in the database
253
255{
256 if (fServer==0) return kFALSE;
257 TSQLResult * tables = fServer->GetTables(fDB.Data(),table);
258 if (!tables) return kFALSE;
259 TSQLRow * row = 0;
260 while( (row = tables->Next()) ) {
261 if(table.CompareTo(row->GetField(0),TString::kIgnoreCase)==0){
262 return kTRUE;
263 }
264 }
265 // The table is a not a permanent table, let's see if it is a 'temporary' table
266 Int_t before = gErrorIgnoreLevel;
269 if (res) {
270 delete res;
271 return kTRUE;
272 }
273 gErrorIgnoreLevel = before;
274
275 return kFALSE;
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Convert from ROOT typename to SQL typename
280
282{
283 TString tn = "";
284
285 if(typeName == "Char_t"){
286 tn = "TEXT";
287 }
288 else if(typeName == "Int_t") {
289 tn = "INTEGER";
290 }
291 else if(typeName == "Short_t") {
292 tn = "SMALLINT";
293 }
294 else if( typeName == "UShort_t") {
295 tn = "SMALLINT UNSIGNED";
296 }
297 else if(typeName == "Float_t"){
298 tn = "FLOAT";
299 }
300 else if(typeName == "Float16_t"){
301 tn = "FLOAT";
302 }
303 else if(typeName == "Double_t"){
304 tn = "DOUBLE";
305 }
306 else if(typeName == "Double32_t"){
307 tn = "FLOAT";
308 }
309 else if(typeName == "UInt_t") {
310 tn = "INT UNSIGNED";
311 }
312 else if( typeName == "Long_t") {
313 tn = "INTEGER";
314 }
315 else if( typeName == "ULong_t") {
316 tn = "INTEGER UNSIGNED";
317 }
318 else if( typeName == "Long64_t") {
319 tn = "BIGINT";
320 }
321 else if( typeName == "ULong64_t") {
322 tn = "BIGINT UNSIGNED";
323 }
324 else if( typeName == "Bool_t") {
325 tn = "BOOL";
326 }
327 else {
328 Error("ConvertTypeName","TypeName (%s) not found",typeName.Data());
329 return "";
330 }
331
332 return tn;
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Create a TBasketSQL
337
339{
340 if (fServer==0) {
341 Error("CreateBasket","No TSQLServer specified");
342 return 0;
343 }
344 std::vector<Int_t> *columnVec = GetColumnIndice(tb);
345 if (columnVec) {
346 return new TBasketSQL(tb->GetName(), tb->GetName(), tb,
347 &fResult, &fInsertQuery, columnVec, &fRow);
348 } else {
349 return 0;
350 }
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Create the column(s) in the database that correspond to the branch/
355
357{
358 if (fServer==0) {
359 Error("CreateBranch","No TSQLServer specified");
360 return;
361 }
362 TString alterSQL = "";
363 alterSQL = "";
364 alterSQL = "ALTER TABLE ";
365 alterSQL += fTable.Data();
366 alterSQL += " ADD ";
367 alterSQL += branchName.Data();;
368 alterSQL += " ";
369 alterSQL += typeName;
370 alterSQL += " ";
371
372 fServer->Query(alterSQL);
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// determine leaf description string
377
379{
380 if(!rs) return "";
381
382 Int_t rows;
384 TString res;
386 TString leafName;
387 Int_t prec=0;
388 TBranch * br = 0;
389 rows = rs->GetRowCount();
390 TString decl;
391 TString prevBranch;
392
393 for( int i=0; i < rows; ++i ) {
394 TSQLRow * row = rs->Next();
395 if (!row) continue;
396 type = row->GetField(1);
397 Int_t index = type.First('(');
398 if(index>0){
399 prec = atoi(type(index+1,type.First(')')-1).Data());
400 type = type(0,index);
401 }
402 branchName = row->GetField(0);
403 Int_t pos;
404 if ((pos=branchName.Index("__"))!=kNPOS) {
405 leafName = branchName(pos+2,branchName.Length());
406 branchName.Remove(pos);
407 } else {
408 leafName = branchName;
409 }
410 if (prevBranch.Length()) {
411 if (prevBranch != branchName) {
412 // new branch let's flush.
413 if (decl.Length()) decl.Remove(decl.Length()-1);
414 br = TTree::Branch(prevBranch,0,decl);
415 br->ResetAddress();
416
417 (br->GetBasketEntry())[0] = 0;
418 (br->GetBasketEntry())[1] = fEntries;
419
420 br->SetEntries(fEntries);
421
422 //++(br->fNBaskets);
424
425 prevBranch = branchName;
426 decl = "";
427 }
428 } else {
429 prevBranch = branchName;
430 }
431
432 if(type.CompareTo("varchar",TString::kIgnoreCase)==0 || type.CompareTo("varchar2",TString::kIgnoreCase)==0 || type.CompareTo("char",TString::kIgnoreCase)==0 ) {
433 char siz[6];
434 snprintf(siz,6,"[%d]",prec);
435 decl.Append( leafName+siz+"/C:" );
436 }
437 else if(type.CompareTo("int",TString::kIgnoreCase)==0){
438 decl.Append( leafName+"/I:" );
439 }
440 else if( type.CompareTo("date",TString::kIgnoreCase)==0 ||
441 type.CompareTo("time",TString::kIgnoreCase)==0 ||
442 type.CompareTo("timestamp",TString::kIgnoreCase)==0 ) {
443 decl.Append( leafName+"/I:" );
444 }
445 else if(type.CompareTo("bit",TString::kIgnoreCase)==0 ||
446 type.CompareTo("tinyint",TString::kIgnoreCase)==0 ||
447 type.CompareTo("smallint",TString::kIgnoreCase)==0 ) {
448 decl.Append( leafName+"/i:" );
449 }
450 else if(type.CompareTo("real",TString::kIgnoreCase)==0 || type.CompareTo("longvarchar",TString::kIgnoreCase)==0 || type.CompareTo("longvarbinary",TString::kIgnoreCase)==0 || type.CompareTo("varbinary",TString::kIgnoreCase)==0 ){
451 decl.Append( leafName+"/S:" );
452 }
453
454 // case kLONGVARCHAR: // not resolved yet how to handle
455 // case kLONGVARBINARY:
456 //case kVARBINARY:
457 // break;
458 else /*if(type.CompareTo("bigint",TString::kIgnoreCase)==0 || type.CompareTo("decimal",TString::kIgnoreCase)==0 || type.CompareTo("numeric",TString::kIgnoreCase)==0 || type.CompareTo("double",TString::kIgnoreCase)==0 ||
459 type.CompareTo("float",TString::kIgnoreCase)==0 )*/{
460
461 decl.Append( leafName+"/F:" );
462 }
463
464 }
465
466 // new branch let's flush.
467 if (decl.Length()) decl.Remove(decl.Length()-1);
468 if (prevBranch.Length()) {
469 br = TTree::Branch(prevBranch,0,decl);
470 br->ResetAddress();
471
472 (br->GetBasketEntry())[0] = 0;
473 (br->GetBasketEntry())[1] = fEntries;
474 br->SetEntries(fEntries);
476 }
477
478 if(!res.IsNull()) res.Resize(res.Length()-1); // cut off last ":"
479 return res;
480}
481
482////////////////////////////////////////////////////////////////////////////////
483/// Create the database table corresponding to this TTree.
484
486{
487 if (fServer==0) {
488 Error("CreateTable","No TSQLServer specified");
489 return false;
490 }
491 Int_t i, j;
492 TString branchName, leafName, typeName;
493 TString createSQL, alterSQL, str;
495 Int_t nl = 0;
496
497 TBranch *branch;
498 TLeaf *leaf;
499
500 for (i=0;i<nb;i++) {
501 branch = (TBranch*)fBranches.UncheckedAt(i);
502 branchName = branch->GetName();
503 nl = branch->GetNleaves();
504 for(j=0;j<nl;j++) {
505 leaf = (TLeaf*)branch->GetListOfLeaves()->UncheckedAt(j);
506 leafName = leaf->GetName();
507 typeName = ConvertTypeName(leaf->GetTypeName());
508 // length = leaf->GetLenStatic();
509
510 if(i == 0 && j == 0) {
511 createSQL = "";
512 createSQL += "CREATE TABLE ";
513 createSQL += table;
514 createSQL += " (";
515 createSQL += branchName;
516 createSQL += "__";
517 createSQL += leafName;
518 createSQL += " ";
519 createSQL += typeName;
520 createSQL += " ";
521 createSQL += ")";
522
523 TSQLResult *sres = fServer->Query(createSQL.Data());
524 if (!sres) {
525 Error("CreateTable","May have failed");
526 return false;
527 }
528 }
529 else {
530 str = "";
531 str = branchName;
532 str += "__";
533 str += leafName;
534 CreateBranch(str, typeName);
535 } //else
536 } // inner for loop
537 } // outer for loop
538 // retrieve table to initialize fResult
539 delete fResult;
541 return (fResult!=0);
542}
543
544////////////////////////////////////////////////////////////////////////////////
545/// Initializeation routine
546
548{
549 fCurrentEntry = -1;
550
551 GetEntries();
552
553 delete fResult;
555 if(!fResult) return;
556
558}
559
560////////////////////////////////////////////////////////////////////////////////
561/// Copy the information from the user object to the TTree
562
564{
566 TString typeName;
567 TBranch *branch;
568
569 if (fServer==0) return 0;
570
571 if(!CheckTable(fTable.Data())) {
572 if (!CreateTable(fTable.Data())) {
573 return -1;
574 }
575 }
576
578
579 for (int i=0;i<nb;i++) {
580 branch = (TBranch*)fBranches.UncheckedAt(i);
581 CheckBasket(branch);
582 }
583
584 if (!fBranchChecked) {
585 for(int i=0;i<nb;i++) {
586 branch = (TBranch*)fBranches.UncheckedAt(i);
587 if (!CheckBranch(branch)) {
588 Error("Fill","CheckBranch for %s failed",branch->GetName());
589 }
590 }
592 }
593 ResetQuery();
594
595 TTree::Fill();
596
597 if (fInsertQuery[fInsertQuery.Length()-1]!='(') {
599 fInsertQuery += ")";
601
602 if (res) {
603 return res->GetRowCount();
604 }
605 }
606 return -1;
607}
608
609////////////////////////////////////////////////////////////////////////////////
610/// Return a vector of columns index corresponding to the
611/// current SQL table and the branch given as argument
612/// Returns 0 if no columns indices is found
613/// Otherwise returns a pointer to a vector to be deleted by the caller
614
615std::vector<Int_t> *TTreeSQL::GetColumnIndice(TBranch *branch)
616{
617 if (!CheckTable(fTable)) return 0;
618
619 std::vector<Int_t> *columns = new std::vector<Int_t>;
620
621 Int_t nl = branch->GetNleaves();
622
623 std::vector<TString> names;
624
626 if (rs==0) { delete columns; return 0; }
627 Int_t rows = rs->GetRowCount();
628
629 std::pair<TString,Int_t> value;
630
631 for (Int_t i=0;i<rows;++i) {
632 TSQLRow *row = rs->Next();
633 names.push_back( row->GetField(0) );
634 delete row;
635 }
636 delete rs;
637
638 for(int j=0;j<nl;j++) {
639
640 Int_t col = -1;
641 TLeaf *leaf = (TLeaf*)branch->GetListOfLeaves()->UncheckedAt(j);
642 TString leafName = leaf->GetName();
643 TString str;
644
645 str = "";
646 str = branch->GetName();
647 str += "__";
648 str += leafName;
649 for (Int_t i=0;i<rows;++i) {
650 if (str.CompareTo(names[i],TString::kIgnoreCase)==0) {
651 col = i;
652 break;
653 }
654 }
655 if (col<0) {
656 str = leafName;
657 for (Int_t i=0;i<rows;++i) {
658 if (str.CompareTo(names[i],TString::kIgnoreCase)==0) {
659 col = i;
660 break;
661 }
662 }
663 }
664 if(col>=0){
665 columns->push_back(col);
666 } else Error("GetColumnIndice","Error finding column %d %s",j,str.Data());
667 }
668 if (columns->empty()) {
669 delete columns; return 0;
670 } else
671 return columns;
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Get the number of rows in the database
676
678{
679 if (fServer==0) return GetEntriesFast();
680 if (!CheckTable(fTable.Data())) return 0;
681
682 TTreeSQL* thisvar = const_cast<TTreeSQL*>(this);
683
684 // What if the user already started to call GetEntry
685 // What about the initial value of fEntries is it really 0?
686
687 TString counting = "select count(*) from " + fTable;
688 TSQLResult *count = fServer->Query(counting);
689
690 if (count==0) {
691 thisvar->fEntries = 0;
692 } else {
693 TSQLRow * row = count->Next();
694 if (row) {
695 TString val = row->GetField(0);
696 Long_t ret;
697 sscanf(val.Data(), "%ld",&(ret) );
698 thisvar->fEntries = ret;
699 } else {
700 thisvar->fEntries = 0;
701 }
702 }
703 return fEntries;
704}
705
706////////////////////////////////////////////////////////////////////////////////
707/// Return the number of entries as of the last check.
708/// Use GetEntries for a more accurate count.
709
711{
712 return fEntries;
713}
714
715////////////////////////////////////////////////////////////////////////////////
716/// Load the data for the entry from the database.
717
719{
720 if (PrepEntry(entry)>=0) return TTree::GetEntry(entry,getall);
721 else return -1;
722}
723
724////////////////////////////////////////////////////////////////////////////////
725/// Setup the tree to the load the specified entry.
726
728{
729 fReadEntry = entry;
730 return PrepEntry(entry);
731}
732
733////////////////////////////////////////////////////////////////////////////////
734/// Make sure the server and result set are setup for the requested entry
735
737{
738 if (entry < 0 || entry >= fEntries || fServer==0) return 0;
739 fReadEntry = entry;
740
741 if(entry == fCurrentEntry) return entry;
742
743 if(entry < fCurrentEntry || fResult==0){
744 delete fResult;
746 fCurrentEntry = -1;
747 }
748
749 Bool_t reset = false;
750 while ( fResult && fCurrentEntry < entry ) {
752 delete fRow;
753 fRow = fResult->Next();
754 if (fRow==0 && !reset) {
755 delete fResult;
757 fCurrentEntry = -1;
758 reset = true;
759 }
760 }
761 if (fRow==0) return -1;
762 return entry;
763}
764
765//______________________________________________________________________________
766// void TTreeSQL::LoadNumberEntries()
767// {
768// R__ASSERT(0);
769
770// fResult = fServer->Query(fQuery.Data());
771// fEntries=0;
772
773// while(fResult->Next()){
774// fEntries++;
775// }
776// fResult = fServer->Query(fQuery.Data());
777// }
778
779////////////////////////////////////////////////////////////////////////////////
780/// Refresh contents of this Tree and its branches from the current
781/// Tree status in the database
782/// One can call this function in case the Tree on its file is being
783/// updated by another process
784
786{
787 // Note : something to be done?
788 GetEntries(); // Re-load the number of entries
789 fCurrentEntry = -1;
790 delete fResult; fResult = 0;
791 delete fRow; fRow = 0;
792}
793
794////////////////////////////////////////////////////////////////////////////////
795/// Reset the internal query
796
798{
799 fInsertQuery = "INSERT INTO " + fTable + " VALUES (";
800}
const Ssiz_t kNPOS
Definition: RtypesCore.h:111
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
const Int_t kFatal
Definition: TError.h:42
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:105
int type
Definition: TGX11.cxx:120
#define snprintf
Definition: civetweb.c:1540
Implement TBasket for a SQL backend.
Definition: TBasketSQL.h:31
TSQLResult * GetResultSet()
Definition: TBasketSQL.h:52
void CreateBuffer(const char *name, TString title, std::vector< Int_t > *vc, TBranch *branch, TSQLResult **rs)
Create a TSQLBuffer for this basket.
Definition: TBasketSQL.cxx:88
Manages buffers for branches of a Tree.
Definition: TBasket.h:34
A TTree is a list of TBranches.
Definition: TBranch.h:64
virtual void ResetAddress()
Reset the address of the branch.
Definition: TBranch.cxx:2234
TObjArray * GetListOfBranches()
Definition: TBranch.h:203
TBasket * GetBasket(Int_t basket)
Return pointer to basket basketnumber in this Branch.
Definition: TBranch.cxx:1184
Int_t GetNleaves() const
Definition: TBranch.h:206
TObjArray * GetListOfBaskets()
Definition: TBranch.h:202
TObjArray * GetListOfLeaves()
Definition: TBranch.h:204
virtual void SetEntries(Long64_t entries)
Set the number of entries in this branch.
Definition: TBranch.cxx:2421
Long64_t * GetBasketEntry() const
Definition: TBranch.h:174
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
Collection abstract base class.
Definition: TCollection.h:63
TBuffer * GetBufferRef() const
Definition: TKey.h:75
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:32
virtual const char * GetTypeName() const
Definition: TLeaf.h:93
A doubly linked list.
Definition: TList.h:44
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:234
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:89
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:908
virtual const char * GetFieldName(Int_t field)=0
virtual Int_t GetRowCount() const
Definition: TSQLResult.h:45
virtual TSQLRow * Next()=0
virtual Int_t GetFieldCount()=0
virtual const char * GetField(Int_t field)=0
virtual TSQLResult * Query(const char *sql)=0
virtual TSQLResult * GetTables(const char *dbname, const char *wild=0)=0
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)=0
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:406
const char * Data() const
Definition: TString.h:364
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1070
@ kIgnoreCase
Definition: TString.h:263
Bool_t IsNull() const
Definition: TString.h:402
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
TString & Append(const char *cs)
Definition: TString.h:559
Implement TTree for a SQL backend.
Definition: TTreeSQL.h:41
TString fDB
Definition: TTreeSQL.h:45
TString ConvertTypeName(const TString &typeName)
Convert from ROOT typename to SQL typename.
Definition: TTreeSQL.cxx:281
virtual Long64_t GetEntries() const
Get the number of rows in the database.
Definition: TTreeSQL.cxx:677
virtual Long64_t GetEntriesFast() const
Return the number of entries as of the last check.
Definition: TTreeSQL.cxx:710
Bool_t CheckTable(const TString &table) const
Check the table exist in the database.
Definition: TTreeSQL.cxx:254
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Load the data for the entry from the database.
Definition: TTreeSQL.cxx:718
virtual Int_t Fill()
Copy the information from the user object to the TTree.
Definition: TTreeSQL.cxx:563
void Init()
Initializeation routine.
Definition: TTreeSQL.cxx:547
Bool_t fBranchChecked
Definition: TTreeSQL.h:52
TString CreateBranches(TSQLResult *rs)
determine leaf description string
Definition: TTreeSQL.cxx:378
TSQLServer * fServer
Definition: TTreeSQL.h:51
std::vector< Int_t > * GetColumnIndice(TBranch *branch)
Return a vector of columns index corresponding to the current SQL table and the branch given as argum...
Definition: TTreeSQL.cxx:615
TSQLResult * fResult
Definition: TTreeSQL.h:49
Bool_t CheckBranch(TBranch *tb)
Check if the table has a column corresponding the branch and that the resultset are properly setup.
Definition: TTreeSQL.cxx:206
virtual TBranch * Bronch(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99)
Not implemented yet.
Definition: TTreeSQL.cxx:117
virtual Long64_t PrepEntry(Long64_t entry)
Make sure the server and result set are setup for the requested entry.
Definition: TTreeSQL.cxx:736
TString fQuery
Definition: TTreeSQL.h:47
virtual Long64_t LoadTree(Long64_t entry)
Setup the tree to the load the specified entry.
Definition: TTreeSQL.cxx:727
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Not implemented yet.
Definition: TTreeSQL.cxx:88
TString fTable
Definition: TTreeSQL.h:48
virtual TBranch * BranchOld(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=1)
Not implemented yet.
Definition: TTreeSQL.cxx:127
virtual void CreateBranch(const TString &branchName, const TString &typeName)
Create the column(s) in the database that correspond to the branch/.
Definition: TTreeSQL.cxx:356
void Refresh()
Refresh contents of this Tree and its branches from the current Tree status in the database One can c...
Definition: TTreeSQL.cxx:785
Int_t fCurrentEntry
Definition: TTreeSQL.h:44
TString fInsertQuery
Definition: TTreeSQL.h:46
TSQLRow * fRow
Definition: TTreeSQL.h:50
void ResetQuery()
Reset the internal query.
Definition: TTreeSQL.cxx:797
TTreeSQL(TSQLServer *server, TString DB, const TString &table)
Constructor with an explicit TSQLServer.
Definition: TTreeSQL.cxx:44
virtual TBasket * CreateBasket(TBranch *br)
Create a TBasketSQL.
Definition: TTreeSQL.cxx:338
Bool_t CreateTable(const TString &table)
Create the database table corresponding to this TTree.
Definition: TTreeSQL.cxx:485
virtual TBranch * BranchImp(const char *branchname, const char *classname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel)
Not implemented yet.
Definition: TTreeSQL.cxx:67
void CheckBasket(TBranch *tb)
Check if the basket is properly setup.
Definition: TTreeSQL.cxx:178
A TTree object has a header with a name and a title.
Definition: TTree.h:71
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4395
TObjArray fBranches
List of Branches.
Definition: TTree.h:111
Long64_t fEntries
Number of entries.
Definition: TTree.h:76
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition: TTree.cxx:5397
Long64_t fReadEntry
! Number of the entry being processed
Definition: TTree.h:99
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
Definition: TTree.cxx:1722
void table()
Definition: table.C:85