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