Logo ROOT  
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 
15 Implement TTree for a SQL backend
16 */
17 
18 #include <vector>
19 #include <map>
20 #include <cstdlib>
21 
22 #include "TString.h"
23 #include "TError.h"
24 #include "TLeaf.h"
25 #include "TBranch.h"
26 #include "TList.h"
27 
28 #include "TSQLRow.h"
29 #include "TSQLResult.h"
30 #include "TSQLServer.h"
31 #include "TSQLTableInfo.h"
32 #include "TSQLColumnInfo.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  fTableInfo(0)
49 {
50  fCurrentEntry = -1;
51  fQuery = TString("Select * from " + fTable);
52  fEntries = 0;
53 
54  if (fServer==0) {
55  Error("TTreeSQL","No TSQLServer specified");
56  return;
57  }
58  if (CheckTable(fTable.Data())) {
59  Init();
60  }
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Not implemented yet
65 
66 TBranch* TTreeSQL::BranchImp(const char *, const char *,
67  TClass *, void *, Int_t ,
68  Int_t )
69 {
70  Fatal("BranchImp","Not implemented yet");
71  return 0;
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Not implemented yet
76 
78  void *, Int_t , Int_t )
79 {
80  Fatal("BranchImp","Not implemented yet");
81  return 0;
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("Bronch","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 
171  return TTree::Branch(name, address, leaflist, bufsize);
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Check if the basket is properly setup
176 
178 {
179  TBasketSQL* basket = (TBasketSQL *)branch->GetBasket(0);
180 
181  if (basket==0) {
182  basket = (TBasketSQL*)CreateBasket(branch);
183  if (basket==0) return;
184  //++(branch->fNBaskets);
185  branch->GetListOfBaskets()->AddAtAndExpand(basket,0);
186  }
187  TBuffer * buffer = basket->GetBufferRef();
188 
189  if(buffer == 0){
190  std::vector<Int_t> *columns = GetColumnIndice(branch);
191  if (columns) basket->CreateBuffer(branch->GetName(),"A", columns, branch, &fResult);
192  }
193 
194  Int_t nb = branch->GetListOfBranches()->GetEntriesFast();
195  for (int i=0;i<nb;i++) {
196  TBranch * subbranch = (TBranch*)branch->GetListOfBranches()->UncheckedAt(i);
197  if(subbranch) CheckBasket(subbranch);
198  }
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Check if the table has a column corresponding the branch
203 /// and that the resultset are properly setup
204 
206 {
207  if (fServer==0) {
208  return kFALSE;
209  }
210  TString leafName;
211  TLeaf *leaf;
212  Int_t nl;
213  TString str = "";
214  TString typeName = "";
215 
216  if (!tb) return kFALSE;
217 
218  TBasketSQL *basket = (TBasketSQL *)tb->GetBasket(0);
219  if (!basket) return kFALSE;
220 
221  TSQLResult *rs = basket->GetResultSet();
222  if (!rs) {
223  Error("CheckBranch","%s has basket but no resultset yet",tb->GetName());
224  return kFALSE;
225  }
226 
227  nl = tb->GetNleaves();
228 
229  for(int j=0;j<nl;j++) {
230  leaf = (TLeaf*)tb->GetListOfLeaves()->UncheckedAt(j);
231  typeName = leaf->GetTypeName();
232  typeName = ConvertTypeName(leaf->GetTypeName());
233  leafName = leaf->GetName();
234  str = "";
235  str = tb->GetName();
236  str += "__";
237  str += leafName;
238 
239  for (int i=0; i< rs->GetFieldCount(); ++i) {
240  if (str.CompareTo(rs->GetFieldName(i),TString::kIgnoreCase) == 0) return kTRUE;
241  }
242  // We assume that if ONE of the leaf is in the table, then ALL the leaf are in
243  // the table.
244  // TODO: this assumption is harmful if user changes branch structure while keep its name
245  CreateBranch(str, typeName);
246  }
247  return kFALSE;
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Check the table exist in the database
252 
254 {
255  if (fServer==0) return kFALSE;
256  TSQLResult * tables = fServer->GetTables(fDB.Data(),table);
257  if (!tables) return kFALSE;
258  TSQLRow * row = 0;
259  while( (row = tables->Next()) ) {
260  if(table.CompareTo(row->GetField(0),TString::kIgnoreCase)==0){
261  return kTRUE;
262  }
263  }
264  // The table is a not a permanent table, let's see if it is a 'temporary' table
265  Int_t before = gErrorIgnoreLevel;
267  TSQLResult *res = fServer->GetColumns(fDB.Data(),table);
268  if (res) {
269  delete res;
270  return kTRUE;
271  }
272  gErrorIgnoreLevel = before;
273 
274  return kFALSE;
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Convert from ROOT typename to SQL typename
279 
281 {
282  TString tn = "";
283 
284  if(typeName == "Char_t"){
285  tn = "TEXT";
286  }
287  else if(typeName == "Int_t") {
288  tn = "INTEGER";
289  }
290  else if(typeName == "Short_t") {
291  tn = "SMALLINT";
292  }
293  else if( typeName == "UShort_t") {
294  tn = "SMALLINT UNSIGNED";
295  }
296  else if(typeName == "Float_t"){
297  tn = "FLOAT";
298  }
299  else if(typeName == "Float16_t"){
300  tn = "FLOAT";
301  }
302  else if(typeName == "Double_t"){
303  tn = "DOUBLE";
304  }
305  else if(typeName == "Double32_t"){
306  tn = "FLOAT";
307  }
308  else if(typeName == "UInt_t") {
309  tn = "INT UNSIGNED";
310  }
311  else if( typeName == "Long_t") {
312  tn = "INTEGER";
313  }
314  else if( typeName == "ULong_t") {
315  tn = "INTEGER UNSIGNED";
316  }
317  else if( typeName == "Long64_t") {
318  tn = "BIGINT";
319  }
320  else if( typeName == "ULong64_t") {
321  tn = "BIGINT UNSIGNED";
322  }
323  else if( typeName == "Bool_t") {
324  tn = "BOOL";
325  }
326  else if( typeName == "TString") {
327  tn = "TEXT";
328  }
329 
330  else {
331  Error("ConvertTypeName","TypeName (%s) not found",typeName.Data());
332  return "";
333  }
334 
335  return tn;
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Create a TBasketSQL
340 
342 {
343  if (fServer==0) {
344  Error("CreateBasket","No TSQLServer specified");
345  return 0;
346  }
347  std::vector<Int_t> *columnVec = GetColumnIndice(tb);
348  if (columnVec) {
349  return new TBasketSQL(tb->GetName(), tb->GetName(), tb,
350  &fResult, &fInsertQuery, columnVec, &fRow);
351  } else {
352  return 0;
353  }
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 /// Create the column(s) in the database that correspond to the branch/
358 
359 void TTreeSQL::CreateBranch(const TString &branchName, const TString &typeName)
360 {
361  if (fServer==0) {
362  Error("CreateBranch","No TSQLServer specified");
363  return;
364  }
365  TString alterSQL = "";
366  alterSQL = "";
367  alterSQL = "ALTER TABLE ";
368  alterSQL += fTable.Data();
369  alterSQL += " ADD ";
370  alterSQL += branchName.Data();;
371  alterSQL += " ";
372  alterSQL += typeName;
373  alterSQL += " ";
374 
375  fServer->Query(alterSQL);
376 }
377 
378 ////////////////////////////////////////////////////////////////////////////////
379 /// determine leaf description string
380 
382 {
383  TList * columns = fTableInfo->GetColumns();
384  if(!columns) return;
385 
386  TIter next(columns);
387 
388  TString branchName;
389  TString type;
390  TString leafName;
391  TBranch * br = 0;
392  TSQLColumnInfo * info;
393  while ( (info = ((TSQLColumnInfo*) next()) ))
394  {
395  type = info->GetTypeName();
396  branchName = info->GetName();
397 
398 
399  Int_t pos;
400  if ((pos=branchName.Index("__"))!=kNPOS) {
401  leafName = branchName(pos+2,branchName.Length());
402  branchName.Remove(pos);
403  } else {
404  leafName = branchName;
405  }
406 
407  TString str;
408  int i;
409  unsigned ui;
410  double d;
411  float f;
412 
413  br = 0;
414 
415  if(type.CompareTo("varchar",TString::kIgnoreCase)==0 ||
416  type.CompareTo("varchar2",TString::kIgnoreCase)==0 ||
417  type.CompareTo("char",TString::kIgnoreCase)==0 ||
418  type.CompareTo("longvarchar",TString::kIgnoreCase)==0 ||
419  type.CompareTo("longvarbinary",TString::kIgnoreCase)==0 ||
420  type.CompareTo("varbinary",TString::kIgnoreCase)==0 ||
421  type.CompareTo("text",TString::kIgnoreCase )==0 ) {
422  br = TTree::Branch(leafName,&str);
423 
424  }
425  else if(type.CompareTo("int",TString::kIgnoreCase)==0 ){
426  br = TTree::Branch(leafName,&i);
427  }
428 
429  //Somehow it should be possible to special-case the time classes
430  //but I think we'd need to create a new TSQLTime or something like that...
431  else if( type.CompareTo("date",TString::kIgnoreCase)==0 ||
432  type.CompareTo("time",TString::kIgnoreCase)==0 ||
433  type.CompareTo("timestamp",TString::kIgnoreCase)==0 ||
434  type.CompareTo("datetime",TString::kIgnoreCase)==0 ) {
435  br = TTree::Branch(leafName,&str);
436 
437  }
438 
439  else if(type.CompareTo("bit",TString::kIgnoreCase)==0 ||
440  type.CompareTo("tinyint",TString::kIgnoreCase)==0 ||
441  type.CompareTo("smallint",TString::kIgnoreCase)==0 ) {
442  br = TTree::Branch(leafName,&ui);
443  }
444 
445  else if( type.CompareTo("decimal",TString::kIgnoreCase)==0 ||
446  type.CompareTo("numeric",TString::kIgnoreCase)==0 ||
447  type.CompareTo("double",TString::kIgnoreCase)==0 ||
448  type.CompareTo("float",TString::kIgnoreCase)==0 )
449  {
450  br = TTree::Branch(leafName,&f);
451  }
452  else if( type.CompareTo("bigint",TString::kIgnoreCase)==0 ||
453  type.CompareTo("real",TString::kIgnoreCase) == 0)
454  {
455  br = TTree::Branch(leafName,&d);
456  }
457 
458  if (br == 0)
459  {
460  Error("CreateBranches", "Skipped %s", branchName.Data());
461  continue;
462  }
463 
464  br->ResetAddress();
465 
466  (br->GetBasketEntry())[0] = 0;
467  (br->GetBasketEntry())[1] = fEntries;
468  br->SetEntries(fEntries);
469 
470  //++(br->fNBaskets);
472  }
473 }
474 
475 ////////////////////////////////////////////////////////////////////////////////
476 /// Create the database table corresponding to this TTree.
477 
479 {
480  if (fServer==0) {
481  Error("CreateTable","No TSQLServer specified");
482  return false;
483  }
484  Int_t i, j;
485  TString branchName, leafName, typeName;
486  TString createSQL, alterSQL, str;
488  Int_t nl = 0;
489 
490  TBranch *branch;
491  TLeaf *leaf;
492 
493  for (i=0;i<nb;i++) {
494  branch = (TBranch*)fBranches.UncheckedAt(i);
495  branchName = branch->GetName();
496  nl = branch->GetNleaves();
497  for(j=0;j<nl;j++) {
498  leaf = (TLeaf*)branch->GetListOfLeaves()->UncheckedAt(j);
499  leafName = leaf->GetName();
500  typeName = ConvertTypeName(leaf->GetTypeName());
501  // length = leaf->GetLenStatic();
502 
503  if(i == 0 && j == 0) {
504  createSQL = "";
505  createSQL += "CREATE TABLE ";
506  createSQL += table;
507  createSQL += " (";
508  createSQL += branchName;
509  createSQL += "__";
510  createSQL += leafName;
511  createSQL += " ";
512  createSQL += typeName;
513  createSQL += " ";
514  createSQL += ")";
515 
516  TSQLResult *sres = fServer->Query(createSQL.Data());
517  if (!sres) {
518  Error("CreateTable","May have failed");
519  return false;
520  }
521  }
522  else {
523  str = "";
524  str = branchName;
525  str += "__";
526  str += leafName;
527  CreateBranch(str, typeName);
528  } //else
529  } // inner for loop
530  } // outer for loop
531  // retrieve table to initialize fResult
532  delete fResult;
534  return (fResult!=0);
535 }
536 
537 ////////////////////////////////////////////////////////////////////////////////
538 /// Initializeation routine
539 
541 {
542  fCurrentEntry = -1;
543 
544  GetEntries();
545 
546  delete fResult;
548  if(!fResult) return;
549 
550  if (fDB != "") {
552  }
554  CreateBranches();
555 }
556 
557 ////////////////////////////////////////////////////////////////////////////////
558 /// Copy the information from the user object to the TTree
559 
561 {
563  TString typeName;
564  TBranch *branch;
565 
566  if (fServer==0) return 0;
567 
568  if(!CheckTable(fTable.Data())) {
569  if (!CreateTable(fTable.Data())) {
570  return -1;
571  }
572  }
573 
575 
576  for (int i=0;i<nb;i++) {
577  branch = (TBranch*)fBranches.UncheckedAt(i);
578  CheckBasket(branch);
579  }
580 
581  if (!fBranchChecked) {
582  for(int i=0;i<nb;i++) {
583  branch = (TBranch*)fBranches.UncheckedAt(i);
584  if (!CheckBranch(branch)) {
585  Error("Fill","CheckBranch for %s failed",branch->GetName());
586  }
587  }
589  }
590  ResetQuery();
591 
592  TTree::Fill();
593 
594  if (fInsertQuery[fInsertQuery.Length()-1]!='(') {
596  fInsertQuery += ")";
598 
599  if (res) {
600  return res->GetRowCount();
601  }
602  }
603  return -1;
604 }
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 /// Return a vector of columns index corresponding to the
608 /// current SQL table and the branch given as argument
609 /// Returns 0 if no columns indices is found
610 /// Otherwise returns a pointer to a vector to be deleted by the caller
611 
612 std::vector<Int_t> *TTreeSQL::GetColumnIndice(TBranch *branch)
613 {
614  if (!CheckTable(fTable)) return 0;
615 
616  std::vector<Int_t> *columns = new std::vector<Int_t>;
617 
618  Int_t nl = branch->GetNleaves();
619 
620  std::vector<TString> names;
621 
622  TList *col_list = fTableInfo->GetColumns();
623  if (col_list==0) {
624  delete columns;
625  return 0;
626  }
627 
628  std::pair<TString,Int_t> value;
629 
630  TIter next(col_list);
631  TSQLColumnInfo * cinfo;
632  int rows = 0;
633  while ((cinfo = (TSQLColumnInfo*) next())) {
634  names.push_back( cinfo->GetName() );
635  rows++;
636  }
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;
670  return 0;
671  } else
672  return columns;
673 }
674 
675 ////////////////////////////////////////////////////////////////////////////////
676 /// Get the number of rows in the database
677 
679 {
680  if (fServer==0) return GetEntriesFast();
681  if (!CheckTable(fTable.Data())) return 0;
682 
683  TTreeSQL* thisvar = const_cast<TTreeSQL*>(this);
684 
685  // What if the user already started to call GetEntry
686  // What about the initial value of fEntries is it really 0?
687 
688  TString counting = "select count(*) from " + fTable;
689  TSQLResult *count = fServer->Query(counting);
690 
691  if (count==0) {
692  thisvar->fEntries = 0;
693  } else {
694  TSQLRow * row = count->Next();
695  if (row) {
696  TString val = row->GetField(0);
697  Long_t ret;
698  sscanf(val.Data(), "%ld",&(ret) );
699  thisvar->fEntries = ret;
700  } else {
701  thisvar->fEntries = 0;
702  }
703  }
704  return fEntries;
705 }
706 
707 ////////////////////////////////////////////////////////////////////////////////
708 /// Return the number of entries as of the last check.
709 /// Use GetEntries for a more accurate count.
710 
712 {
713  return fEntries;
714 }
715 
716 ////////////////////////////////////////////////////////////////////////////////
717 /// Load the data for the entry from the database.
718 
720 {
721  if (PrepEntry(entry)>=0) return TTree::GetEntry(entry,getall);
722  else return -1;
723 }
724 
725 ////////////////////////////////////////////////////////////////////////////////
726 /// Setup the tree to the load the specified entry.
727 
729 {
730  fReadEntry = entry;
731  return PrepEntry(entry);
732 }
733 
734 ////////////////////////////////////////////////////////////////////////////////
735 /// Make sure the server and result set are setup for the requested entry
736 
738 {
739  if (entry < 0 || entry >= fEntries || fServer==0) return 0;
740  fReadEntry = entry;
741 
742  if(entry == fCurrentEntry) return entry;
743 
744  if(entry < fCurrentEntry || fResult==0){
745  delete fResult;
747  fCurrentEntry = -1;
748  }
749 
750  Bool_t reset = false;
751  while ( fResult && fCurrentEntry < entry ) {
752  ++fCurrentEntry;
753  delete fRow;
754  fRow = fResult->Next();
755  if (fRow==0 && !reset) {
756  delete fResult;
758  fCurrentEntry = -1;
759  reset = true;
760  }
761  }
762  if (fRow==0) return -1;
763  return entry;
764 }
765 
766 //______________________________________________________________________________
767 // void TTreeSQL::LoadNumberEntries()
768 // {
769 // R__ASSERT(0);
770 
771 // fResult = fServer->Query(fQuery.Data());
772 // fEntries=0;
773 
774 // while(fResult->Next()){
775 // fEntries++;
776 // }
777 // fResult = fServer->Query(fQuery.Data());
778 // }
779 
780 ////////////////////////////////////////////////////////////////////////////////
781 /// Refresh contents of this Tree and its branches from the current
782 /// Tree status in the database
783 /// One can call this function in case the Tree on its file is being
784 /// updated by another process
785 
787 {
788  // Note : something to be done?
789  GetEntries(); // Re-load the number of entries
790  fCurrentEntry = -1;
791  delete fResult; fResult = 0;
792  delete fRow; fRow = 0;
793 }
794 
795 ////////////////////////////////////////////////////////////////////////////////
796 /// Reset the internal query
797 
799 {
800  fInsertQuery = "INSERT INTO " + fTable + " VALUES (";
801 }
802 
803 
804 ////////////////////////////////////////////////////////////////////////////////
805 // Destructor
806 
808 {
809  delete fTableInfo;
810  delete fResult;
811  delete fRow;
812 }
TBranch::ResetAddress
virtual void ResetAddress()
Reset the address of the branch.
Definition: TBranch.cxx:2483
kFatal
const Int_t kFatal
Definition: TError.h:51
TTreeSQL::fTableInfo
TSQLTableInfo * fTableInfo
Definition: TTreeSQL.h:54
TBranch::GetNleaves
Int_t GetNleaves() const
Definition: TBranch.h:245
TSQLColumnInfo
Definition: TSQLColumnInfo.h:17
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TSQLResult::Next
virtual TSQLRow * Next()=0
TTreeSQL::BranchOld
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
TTreeSQL::TTreeSQL
TTreeSQL(TSQLServer *server, TString DB, const TString &table)
Constructor with an explicit TSQLServer.
Definition: TTreeSQL.cxx:42
f
#define f(i)
Definition: RSha256.hxx:122
kNPOS
const Ssiz_t kNPOS
Definition: RtypesCore.h:115
TTreeSQL::ConvertTypeName
TString ConvertTypeName(const TString &typeName)
Convert from ROOT typename to SQL typename.
Definition: TTreeSQL.cxx:280
TTreeSQL::CreateTable
Bool_t CreateTable(const TString &table)
Create the database table corresponding to this TTree.
Definition: TTreeSQL.cxx:478
TString::Data
const char * Data() const
Definition: TString.h:369
TSQLServer.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TSQLServer::GetColumns
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr)=0
TTreeSQL::PrepEntry
virtual Long64_t PrepEntry(Long64_t entry)
Make sure the server and result set are setup for the requested entry.
Definition: TTreeSQL.cxx:737
TBranch::GetListOfBranches
TObjArray * GetListOfBranches()
Definition: TBranch.h:242
TBranch.h
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TString::kIgnoreCase
@ kIgnoreCase
Definition: TString.h:268
TTree
Definition: TTree.h:79
TTreeSQL::Fill
virtual Int_t Fill()
Copy the information from the user object to the TTree.
Definition: TTreeSQL.cxx:560
TSQLServer::GetTableInfo
virtual TSQLTableInfo * GetTableInfo(const char *tablename)
Produce TSQLTableInfo object, which contain info about table itself and each table column Object must...
Definition: TSQLServer.cxx:236
TLeaf::GetTypeName
virtual const char * GetTypeName() const
Definition: TLeaf.h:138
TBranch::GetListOfBaskets
TObjArray * GetListOfBaskets()
Definition: TBranch.h:241
TBranch::SetEntries
virtual void SetEntries(Long64_t entries)
Set the number of entries in this branch.
Definition: TBranch.cxx:2670
TObject::Fatal
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:918
TTreeSQL.h
TTreeSQL::fBranchChecked
Bool_t fBranchChecked
Definition: TTreeSQL.h:53
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
TList.h
TBuffer
Definition: TBuffer.h:43
TTree::Fill
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4527
TTreeSQL::Refresh
void Refresh()
Refresh contents of this Tree and its branches from the current Tree status in the database One can c...
Definition: TTreeSQL.cxx:786
TKey::GetBufferRef
TBuffer * GetBufferRef() const
Definition: TKey.h:80
TObjArray::UncheckedAt
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:90
TTreeSQL::fRow
TSQLRow * fRow
Definition: TTreeSQL.h:51
TString
Definition: TString.h:136
TTreeSQL::Init
void Init()
Initializeation routine.
Definition: TTreeSQL.cxx:540
TBranch::GetBasketEntry
Long64_t * GetBasketEntry() const
Definition: TBranch.h:211
TTreeSQL::GetColumnIndice
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:612
TString.h
TTree::GetEntry
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:5537
TTreeSQL::fResult
TSQLResult * fResult
Definition: TTreeSQL.h:50
bool
TSQLResult
Definition: TSQLResult.h:32
TTreeSQL::fDB
TString fDB
Definition: TTreeSQL.h:46
TBranch
Definition: TBranch.h:89
TTreeSQL::CheckBranch
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:205
TTreeSQL::ResetQuery
void ResetQuery()
Reset the internal query.
Definition: TTreeSQL.cxx:798
TTreeSQL::CheckTable
Bool_t CheckTable(const TString &table) const
Check the table exist in the database.
Definition: TTreeSQL.cxx:253
TSQLTableInfo::GetColumns
TList * GetColumns() const
Definition: TSQLTableInfo.h:40
TSQLServer::Query
virtual TSQLResult * Query(const char *sql)=0
TLeaf.h
TBasketSQL::GetResultSet
TSQLResult * GetResultSet()
Definition: TBasketSQL.h:52
TBasketSQL
Definition: TBasketSQL.h:30
TLeaf
Definition: TLeaf.h:57
TTreeSQL::BranchImp
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:66
TTree::Branch
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
Definition: TTree.h:349
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
TTree::fBranches
TObjArray fBranches
List of Branches.
Definition: TTree.h:119
TString::Remove
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
TTreeSQL::fQuery
TString fQuery
Definition: TTreeSQL.h:48
TTreeSQL::LoadTree
virtual Long64_t LoadTree(Long64_t entry)
Setup the tree to the load the specified entry.
Definition: TTreeSQL.cxx:728
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TSQLRow
Definition: TSQLRow.h:30
TSQLRow.h
Long_t
long Long_t
Definition: RtypesCore.h:54
TTreeSQL::CreateBranch
virtual void CreateBranch(const TString &branchName, const TString &typeName)
Create the column(s) in the database that correspond to the branch/.
Definition: TTreeSQL.cxx:359
TObjArray::AddAtAndExpand
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:235
TTreeSQL::GetEntry
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Load the data for the entry from the database.
Definition: TTreeSQL.cxx:719
TTreeSQL::Branch
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Not implemented yet.
Definition: TTreeSQL.cxx:86
TTree::fReadEntry
Long64_t fReadEntry
! Number of the entry being processed
Definition: TTree.h:107
TTreeSQL::fCurrentEntry
Int_t fCurrentEntry
Definition: TTreeSQL.h:45
TTreeSQL::CreateBasket
virtual TBasket * CreateBasket(TBranch *br)
Create a TBasketSQL.
Definition: TTreeSQL.cxx:341
TTreeSQL::fTable
TString fTable
Definition: TTreeSQL.h:49
TString::Index
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
TBasket
Definition: TBasket.h:34
gErrorIgnoreLevel
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:129
TTreeSQL::CreateBranches
void CreateBranches()
determine leaf description string
Definition: TTreeSQL.cxx:381
TSQLResult.h
TString::CompareTo
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
TTreeSQL::fServer
TSQLServer * fServer
Definition: TTreeSQL.h:52
TBasketSQL.h
TTree::fEntries
Long64_t fEntries
Number of entries.
Definition: TTree.h:84
TClass
Definition: TClass.h:80
TTreeSQL
Definition: TTreeSQL.h:42
TSQLColumnInfo.h
TTreeSQL::CheckBasket
void CheckBasket(TBranch *tb)
Check if the basket is properly setup.
Definition: TTreeSQL.cxx:177
name
char name[80]
Definition: TGX11.cxx:110
TTreeSQL::~TTreeSQL
virtual ~TTreeSQL()
Definition: TTreeSQL.cxx:807
TSQLTableInfo.h
d
#define d(i)
Definition: RSha256.hxx:120
TSQLServer::SelectDataBase
virtual Int_t SelectDataBase(const char *dbname)=0
TIter
Definition: TCollection.h:233
TTreeSQL::GetEntriesFast
virtual Long64_t GetEntriesFast() const
Return the number of entries as of the last check.
Definition: TTreeSQL.cxx:711
TCollection
Definition: TCollection.h:63
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
type
int type
Definition: TGX11.cxx:121
TBranch::GetListOfLeaves
TObjArray * GetListOfLeaves()
Definition: TBranch.h:243
TBranch::GetBasket
TBasket * GetBasket(Int_t basket)
Definition: TBranch.h:209
TTreeSQL::GetEntries
virtual Long64_t GetEntries() const
Get the number of rows in the database.
Definition: TTreeSQL.cxx:678
TSQLRow::GetField
virtual const char * GetField(Int_t field)=0
TSQLResult::GetFieldName
virtual const char * GetFieldName(Int_t field)=0
TSQLServer::GetTables
virtual TSQLResult * GetTables(const char *dbname, const char *wild=nullptr)=0
TTreeSQL::fInsertQuery
TString fInsertQuery
Definition: TTreeSQL.h:47
TSQLServer
Definition: TSQLServer.h:41
TSQLResult::GetRowCount
virtual Int_t GetRowCount() const
Definition: TSQLResult.h:45
TSQLColumnInfo::GetTypeName
const char * GetTypeName() const
Definition: TSQLColumnInfo.h:49
TList
Definition: TList.h:44
TBasketSQL::CreateBuffer
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:82
TTreeSQL::Bronch
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
int
TSQLResult::GetFieldCount
virtual Int_t GetFieldCount()=0
TError.h