Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 A TTree object is a list of TBranch.
16 To Create a TTree object one must:
17 - Create the TTree header via the TTree constructor
18 - Call the TBranch constructor for every branch.
19
20 To Fill this object, use member function Fill with no parameters.
21 The Fill function loops on all defined TBranch.
22
23TTreeSQL is the TTree implementation interfacing with an SQL
24database
25
26*/
27
28#include <vector>
29#include <map>
30#include <cstdlib>
31
32#include "TString.h"
33#include "TError.h"
34#include "TLeaf.h"
35#include "TBranch.h"
36#include "TList.h"
37
38#include "TSQLRow.h"
39#include "TSQLResult.h"
40#include "TSQLServer.h"
41#include "TSQLTableInfo.h"
42#include "TSQLColumnInfo.h"
43
44#include "TTreeSQL.h"
45#include "TBasketSQL.h"
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor with an explicit TSQLServer
50
52 TTree(table.Data(), "Database read from table: " + table, 0), fDB(DB),
53 fTable(table.Data()),
54 fResult(nullptr), fRow(nullptr),
55 fServer(server),
56 fBranchChecked(false),
57 fTableInfo(nullptr)
58{
59 fCurrentEntry = -1;
60 fQuery = TString("Select * from " + fTable);
61 fEntries = 0;
62
63 if (fServer==nullptr) {
64 Error("TTreeSQL","No TSQLServer specified");
65 return;
66 }
67 if (CheckTable(fTable.Data())) {
68 Init();
69 }
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Not implemented yet
74
75TBranch* TTreeSQL::BranchImp(const char *, const char *,
76 TClass *, void *, Int_t ,
77 Int_t )
78{
79 Fatal("BranchImp","Not implemented yet");
80 return nullptr;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Not implemented yet
85
87 void *, Int_t , Int_t )
88{
89 Fatal("BranchImp","Not implemented yet");
90 return nullptr;
91}
92////////////////////////////////////////////////////////////////////////////////
93/// Not implemented yet
94
96 Int_t, const char *)
97{
98 Fatal("Branch","Not implemented yet");
99 return 0;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Not implemented yet
104
106{
107 Fatal("Branch","Not implemented yet");
108 return 0;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Not implemented yet
113
115 Int_t)
116{
117 Fatal("Branch","Not implemented yet");
118 return 0;
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Not implemented yet
123
124TBranch* TTreeSQL::Bronch(const char *, const char *, void *,
125 Int_t, Int_t)
126{
127 Fatal("Bronch","Not implemented yet");
128 return nullptr;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Not implemented yet
133
134TBranch* TTreeSQL::BranchOld(const char *, const char *,
135 void *, Int_t, Int_t)
136{
137 Fatal("BranchOld","Not implemented yet");
138 return nullptr;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Not implemented yet
143
144TBranch *TTreeSQL::Branch(const char *, const char *, void *,
145 Int_t, Int_t)
146{
147 Fatal("Branch","Not implemented yet");
148 return nullptr;
149}
150
151///////////////////////////////////////////////////////////////////////////////
152/// Create a branch
153
154TBranch * TTreeSQL::Branch(const char *name, void *address,
155 const char *leaflist, Int_t bufsize)
156{
160
161 for (int i=0;i<nb;i++) {
163 brName = branch->GetName();
164 if (brName.CompareTo(name) == 0) {
165 // Now if the branch exists in db, root gives a warning and exit
166 // Dealing with duplicate branch has been done, but not tested yet.
167 // So if you want to allow duplicate branch, just comment Fatal() line and uncomment commented
168 // below Fatal() line
169
170 Fatal("Branch()", "Duplicate branch!!!");
171
172 /* Commented. If uncommented, should comment Fatal line.
173 // this is a duplicate branch. So reset data structure memory address and return.
174 branch->SetAddress(address);
175 return branch;
176 */
177 }
178 }
179
180 return TTree::Branch(name, address, leaflist, bufsize);
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Check if the basket is properly setup
185
187{
188 TBasketSQL* basket = (TBasketSQL *)branch->GetBasket(0);
189
190 if (basket==nullptr) {
192 if (basket==nullptr) return;
193 //++(branch->fNBaskets);
194 branch->GetListOfBaskets()->AddAtAndExpand(basket,0);
195 }
196 TBuffer * buffer = basket->GetBufferRef();
197
198 if(buffer == nullptr){
199 std::vector<Int_t> *columns = GetColumnIndice(branch);
200 if (columns) basket->CreateBuffer(branch->GetName(),"A", columns, branch, &fResult);
201 }
202
203 Int_t nb = branch->GetListOfBranches()->GetEntriesFast();
204 for (int i=0;i<nb;i++) {
205 TBranch * subbranch = (TBranch*)branch->GetListOfBranches()->UncheckedAt(i);
207 }
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Check if the table has a column corresponding the branch
212/// and that the resultset are properly setup
213
215{
216 if (fServer==nullptr) {
217 return false;
218 }
220 TLeaf *leaf;
221 Int_t nl;
222 TString str = "";
223 TString typeName = "";
224
225 if (!tb) return false;
226
227 TBasketSQL *basket = (TBasketSQL *)tb->GetBasket(0);
228 if (!basket) return false;
229
230 TSQLResult *rs = basket->GetResultSet();
231 if (!rs) {
232 Error("CheckBranch","%s has basket but no resultset yet",tb->GetName());
233 return false;
234 }
235
236 nl = tb->GetNleaves();
237
238 for(int j=0;j<nl;j++) {
239 leaf = (TLeaf*)tb->GetListOfLeaves()->UncheckedAt(j);
240 typeName = leaf->GetTypeName();
241 typeName = ConvertTypeName(leaf->GetTypeName());
242 leafName = leaf->GetName();
243 str = "";
244 str = tb->GetName();
245 str += "__";
246 str += leafName;
247
248 for (int i=0; i< rs->GetFieldCount(); ++i) {
249 if (str.CompareTo(rs->GetFieldName(i),TString::kIgnoreCase) == 0) return true;
250 }
251 // We assume that if ONE of the leaf is in the table, then ALL the leaf are in
252 // the table.
253 // TODO: this assumption is harmful if user changes branch structure while keep its name
254 CreateBranch(str, typeName);
255 }
256 return false;
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Check the table exist in the database
261
262bool TTreeSQL::CheckTable(const TString &table) const
263{
264 if (fServer==nullptr) return false;
266 if (!tables) return false;
267 TSQLRow * row = nullptr;
268 while( (row = tables->Next()) ) {
269 if(table.CompareTo(row->GetField(0),TString::kIgnoreCase)==0){
270 return true;
271 }
272 }
273 // The table is a not a permanent table, let's see if it is a 'temporary' table
276 TSQLResult *res = fServer->GetColumns(fDB.Data(),table);
277 if (res) {
278 delete res;
279 return true;
280 }
282
283 return false;
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Convert from ROOT typename to SQL typename
288
290{
291 TString tn = "";
292
293 if(typeName == "Char_t"){
294 tn = "TEXT";
295 }
296 else if(typeName == "Int_t") {
297 tn = "INTEGER";
298 }
299 else if(typeName == "Short_t") {
300 tn = "SMALLINT";
301 }
302 else if( typeName == "UShort_t") {
303 tn = "SMALLINT UNSIGNED";
304 }
305 else if(typeName == "Float_t"){
306 tn = "FLOAT";
307 }
308 else if(typeName == "Float16_t"){
309 tn = "FLOAT";
310 }
311 else if(typeName == "Double_t"){
312 tn = "DOUBLE";
313 }
314 else if(typeName == "Double32_t"){
315 tn = "FLOAT";
316 }
317 else if(typeName == "UInt_t") {
318 tn = "INT UNSIGNED";
319 }
320 else if( typeName == "Long_t") {
321 tn = "INTEGER";
322 }
323 else if( typeName == "ULong_t") {
324 tn = "INTEGER UNSIGNED";
325 }
326 else if( typeName == "Long64_t") {
327 tn = "BIGINT";
328 }
329 else if( typeName == "ULong64_t") {
330 tn = "BIGINT UNSIGNED";
331 }
332 else if( typeName == "Bool_t") {
333 tn = "BOOL";
334 }
335 else if( typeName == "TString") {
336 tn = "TEXT";
337 }
338
339 else {
340 Error("ConvertTypeName","TypeName (%s) not found",typeName.Data());
341 return "";
342 }
343
344 return tn;
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Create a TBasketSQL
349
351{
352 if (fServer==nullptr) {
353 Error("CreateBasket","No TSQLServer specified");
354 return nullptr;
355 }
356 std::vector<Int_t> *columnVec = GetColumnIndice(tb);
357 if (columnVec) {
358 return new TBasketSQL(tb->GetName(), tb->GetName(), tb,
360 } else {
361 return nullptr;
362 }
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// Create the column(s) in the database that correspond to the branch/
367
369{
370 if (fServer==nullptr) {
371 Error("CreateBranch","No TSQLServer specified");
372 return;
373 }
374 TString alterSQL = "";
375 alterSQL = "";
376 alterSQL = "ALTER TABLE ";
377 alterSQL += fTable.Data();
378 alterSQL += " ADD ";
379 alterSQL += branchName.Data();
380 alterSQL += " ";
381 alterSQL += typeName;
382 alterSQL += " ";
383
385}
386
387////////////////////////////////////////////////////////////////////////////////
388/// determine leaf description string
389
391{
393 if(!columns) return;
394
395 TIter next(columns);
396
400 TBranch * br = nullptr;
402 while ( (info = ((TSQLColumnInfo*) next()) ))
403 {
404 type = info->GetTypeName();
405 branchName = info->GetName();
406
407
408 Int_t pos;
409 if ((pos=branchName.Index("__"))!=kNPOS) {
410 leafName = branchName(pos+2,branchName.Length());
411 branchName.Remove(pos);
412 } else {
414 }
415
416 TString str;
417 int i;
418 unsigned ui;
419 double d;
420 float f;
421
422 br = nullptr;
423
424 if(type.CompareTo("varchar",TString::kIgnoreCase)==0 ||
425 type.CompareTo("varchar2",TString::kIgnoreCase)==0 ||
426 type.CompareTo("char",TString::kIgnoreCase)==0 ||
427 type.CompareTo("longvarchar",TString::kIgnoreCase)==0 ||
428 type.CompareTo("longvarbinary",TString::kIgnoreCase)==0 ||
429 type.CompareTo("varbinary",TString::kIgnoreCase)==0 ||
430 type.CompareTo("text",TString::kIgnoreCase )==0 ) {
431 br = TTree::Branch(leafName,&str);
432
433 }
434 else if(type.CompareTo("int",TString::kIgnoreCase)==0 ){
436 }
437
438 //Somehow it should be possible to special-case the time classes
439 //but I think we'd need to create a new TSQLTime or something like that...
440 else if( type.CompareTo("date",TString::kIgnoreCase)==0 ||
441 type.CompareTo("time",TString::kIgnoreCase)==0 ||
442 type.CompareTo("timestamp",TString::kIgnoreCase)==0 ||
443 type.CompareTo("datetime",TString::kIgnoreCase)==0 ) {
444 br = TTree::Branch(leafName,&str);
445
446 }
447
448 else if(type.CompareTo("bit",TString::kIgnoreCase)==0 ||
449 type.CompareTo("tinyint",TString::kIgnoreCase)==0 ||
450 type.CompareTo("smallint",TString::kIgnoreCase)==0 ) {
452 }
453
454 else if( type.CompareTo("decimal",TString::kIgnoreCase)==0 ||
455 type.CompareTo("numeric",TString::kIgnoreCase)==0 ||
456 type.CompareTo("double",TString::kIgnoreCase)==0 ||
457 type.CompareTo("float",TString::kIgnoreCase)==0 )
458 {
460 }
461 else if( type.CompareTo("bigint",TString::kIgnoreCase)==0 ||
462 type.CompareTo("real",TString::kIgnoreCase) == 0)
463 {
465 }
466
467 if (br == nullptr)
468 {
469 Error("CreateBranches", "Skipped %s", branchName.Data());
470 continue;
471 }
472
473 br->ResetAddress();
474
475 (br->GetBasketEntry())[0] = 0;
476 (br->GetBasketEntry())[1] = fEntries;
477 br->SetEntries(fEntries);
478
479 //++(br->fNBaskets);
480 br->GetListOfBaskets()->AddAtAndExpand(CreateBasket(br),0);
481 }
482}
483
484////////////////////////////////////////////////////////////////////////////////
485/// Create the database table corresponding to this TTree.
486
488{
489 if (fServer==nullptr) {
490 Error("CreateTable","No TSQLServer specified");
491 return false;
492 }
493 Int_t i, j;
494 TString branchName, leafName, typeName;
497 Int_t nl = 0;
498
500 TLeaf *leaf;
501
502 for (i=0;i<nb;i++) {
504 branchName = branch->GetName();
505 nl = branch->GetNleaves();
506 for(j=0;j<nl;j++) {
507 leaf = (TLeaf*)branch->GetListOfLeaves()->UncheckedAt(j);
508 leafName = leaf->GetName();
509 typeName = ConvertTypeName(leaf->GetTypeName());
510 // length = leaf->GetLenStatic();
511
512 if(i == 0 && j == 0) {
513 createSQL = "";
514 createSQL += "CREATE TABLE ";
515 createSQL += table;
516 createSQL += " (";
518 createSQL += "__";
520 createSQL += " ";
521 createSQL += typeName;
522 createSQL += " ";
523 createSQL += ")";
524
526 if (!sres) {
527 Error("CreateTable","May have failed");
528 return false;
529 }
530 }
531 else {
532 str = "";
533 str = branchName;
534 str += "__";
535 str += leafName;
536 CreateBranch(str, typeName);
537 } //else
538 } // inner for loop
539 } // outer for loop
540 // retrieve table to initialize fResult
541 delete fResult;
543 return (fResult!=nullptr);
544}
545
546////////////////////////////////////////////////////////////////////////////////
547/// Initialization routine
548
550{
551 fCurrentEntry = -1;
552
553 GetEntries();
554
555 delete fResult;
557 if(!fResult) return;
558
559 if (fDB != "") {
561 }
564}
565
566////////////////////////////////////////////////////////////////////////////////
567/// Copy the information from the user object to the TTree
568
570{
572 TString typeName;
574
575 if (fServer==nullptr) return 0;
576
577 if(!CheckTable(fTable.Data())) {
578 if (!CreateTable(fTable.Data())) {
579 return -1;
580 }
581 }
582
584
585 for (int i=0;i<nb;i++) {
588 }
589
590 if (!fBranchChecked) {
591 for(int i=0;i<nb;i++) {
593 if (!CheckBranch(branch)) {
594 Error("Fill","CheckBranch for %s failed",branch->GetName());
595 }
596 }
597 fBranchChecked = true;
598 }
599 ResetQuery();
600
601 TTree::Fill();
602
603 if (fInsertQuery[fInsertQuery.Length()-1]!='(') {
605 fInsertQuery += ")";
607
608 if (res) {
609 return res->GetRowCount();
610 }
611 }
612 return -1;
613}
614
615////////////////////////////////////////////////////////////////////////////////
616/// Return a vector of columns index corresponding to the
617/// current SQL table and the branch given as argument
618/// Returns 0 if no columns indices is found
619/// Otherwise returns a pointer to a vector to be deleted by the caller
620
622{
623 if (!CheckTable(fTable)) return nullptr;
624
625 std::vector<Int_t> *columns = new std::vector<Int_t>;
626
627 Int_t nl = branch->GetNleaves();
628
629 std::vector<TString> names;
630
632 if (col_list==nullptr) {
633 delete columns;
634 return nullptr;
635 }
636
637 std::pair<TString,Int_t> value;
638
639 TIter next(col_list);
641 int rows = 0;
642 while ((cinfo = (TSQLColumnInfo*) next())) {
643 names.push_back( cinfo->GetName() );
644 rows++;
645 }
646
647 for(int j=0;j<nl;j++) {
648
649 Int_t col = -1;
650 TLeaf *leaf = (TLeaf*)branch->GetListOfLeaves()->UncheckedAt(j);
651 TString leafName = leaf->GetName();
652 TString str;
653
654 str = "";
655 str = branch->GetName();
656 str += "__";
657 str += leafName;
658 for (Int_t i=0;i<rows;++i) {
659 if (str.CompareTo(names[i],TString::kIgnoreCase)==0) {
660 col = i;
661 break;
662 }
663 }
664 if (col<0) {
665 str = leafName;
666 for (Int_t i=0;i<rows;++i) {
667 if (str.CompareTo(names[i],TString::kIgnoreCase)==0) {
668 col = i;
669 break;
670 }
671 }
672 }
673 if(col>=0){
674 columns->push_back(col);
675 } else Error("GetColumnIndice","Error finding column %d %s",j,str.Data());
676 }
677 if (columns->empty()) {
678 delete columns;
679 return nullptr;
680 } else
681 return columns;
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Get the number of rows in the database
686
688{
689 if (fServer==nullptr) return GetEntriesFast();
690 if (!CheckTable(fTable.Data())) return 0;
691
692 TTreeSQL* thisvar = const_cast<TTreeSQL*>(this);
693
694 // What if the user already started to call GetEntry
695 // What about the initial value of fEntries is it really 0?
696
697 TString counting = "select count(*) from " + fTable;
698 TSQLResult *count = fServer->Query(counting);
699
700 if (count==nullptr) {
701 thisvar->fEntries = 0;
702 } else {
703 TSQLRow * row = count->Next();
704 if (row) {
705 TString val = row->GetField(0);
706 Long_t ret;
707 sscanf(val.Data(), "%ld",&(ret) );
708 thisvar->fEntries = ret;
709 } else {
710 thisvar->fEntries = 0;
711 }
712 }
713 return fEntries;
714}
715
716////////////////////////////////////////////////////////////////////////////////
717/// Return the number of entries as of the last check.
718/// Use GetEntries for a more accurate count.
719
721{
722 return fEntries;
723}
724
725////////////////////////////////////////////////////////////////////////////////
726/// Load the data for the entry from the database.
727
729{
730 if (PrepEntry(entry)>=0) return TTree::GetEntry(entry,getall);
731 else return -1;
732}
733
734////////////////////////////////////////////////////////////////////////////////
735/// Setup the tree to the load the specified entry.
736
742
743////////////////////////////////////////////////////////////////////////////////
744/// Make sure the server and result set are setup for the requested entry
745
747{
748 if (entry < 0 || entry >= fEntries || fServer==nullptr) return 0;
750
751 if(entry == fCurrentEntry) return entry;
752
753 if(entry < fCurrentEntry || fResult==nullptr){
754 delete fResult;
756 fCurrentEntry = -1;
757 }
758
759 bool reset = false;
760 while ( fResult && fCurrentEntry < entry ) {
762 delete fRow;
763 fRow = fResult->Next();
764 if (fRow==nullptr && !reset) {
765 delete fResult;
767 fCurrentEntry = -1;
768 reset = true;
769 }
770 }
771 if (fRow==nullptr) return -1;
772 return entry;
773}
774
775//______________________________________________________________________________
776// void TTreeSQL::LoadNumberEntries()
777// {
778// R__ASSERT(0);
779
780// fResult = fServer->Query(fQuery.Data());
781// fEntries=0;
782
783// while(fResult->Next()){
784// fEntries++;
785// }
786// fResult = fServer->Query(fQuery.Data());
787// }
788
789////////////////////////////////////////////////////////////////////////////////
790/// Refresh contents of this Tree and its branches from the current
791/// Tree status in the database
792/// One can call this function in case the Tree on its file is being
793/// updated by another process
794
796{
797 // Note : something to be done?
798 GetEntries(); // Re-load the number of entries
799 fCurrentEntry = -1;
800 delete fResult; fResult = nullptr;
801 delete fRow; fRow = nullptr;
802}
803
804////////////////////////////////////////////////////////////////////////////////
805/// Reset the internal query
806
808{
809 fInsertQuery = "INSERT INTO " + fTable + " VALUES (";
810}
811
812
813////////////////////////////////////////////////////////////////////////////////
814// Destructor
815
817{
818 delete fTableInfo;
819 delete fResult;
820 delete fRow;
821}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:131
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
constexpr Int_t kFatal
Definition TError.h:50
Int_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
Definition TError.cxx:33
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
Implement TBasket for a SQL backend.
Definition TBasketSQL.h:31
Manages buffers for branches of a Tree.
Definition TBasket.h:34
A TTree is a list of TBranches.
Definition TBranch.h:93
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Collection abstract base class.
Definition TCollection.h:65
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
A doubly linked list.
Definition TList.h:38
Int_t GetEntriesFast() const
Definition TObjArray.h:58
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1099
virtual Int_t GetRowCount() const
Definition TSQLResult.h:44
virtual TSQLRow * Next()=0
virtual const char * GetField(Int_t field)=0
virtual Int_t SelectDataBase(const char *dbname)=0
virtual TSQLTableInfo * GetTableInfo(const char *tablename)
Produce TSQLTableInfo object, which contain info about table itself and each table column Object must...
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr)=0
virtual TSQLResult * Query(const char *sql)=0
virtual TSQLResult * GetTables(const char *dbname, const char *wild=nullptr)=0
TList * GetColumns() const
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:464
const char * Data() const
Definition TString.h:384
@ kIgnoreCase
Definition TString.h:285
TString & Remove(Ssiz_t pos)
Definition TString.h:693
A TTree object is a list of TBranch.
Definition TTreeSQL.h:42
TBasket * CreateBasket(TBranch *br) override
Create a TBasketSQL.
Definition TTreeSQL.cxx:350
TString fDB
Definition TTreeSQL.h:46
TString ConvertTypeName(const TString &typeName)
Convert from ROOT typename to SQL typename.
Definition TTreeSQL.cxx:289
bool fBranchChecked
Definition TTreeSQL.h:53
TBranch * BranchImp(const char *branchname, const char *classname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel) override
Not implemented yet.
Definition TTreeSQL.cxx:75
bool CheckTable(const TString &table) const
Check the table exist in the database.
Definition TTreeSQL.cxx:262
TBranch * BranchOld(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=1) override
Not implemented yet.
Definition TTreeSQL.cxx:134
void CreateBranches()
determine leaf description string
Definition TTreeSQL.cxx:390
TSQLTableInfo * fTableInfo
Definition TTreeSQL.h:54
void Init()
Initialization routine.
Definition TTreeSQL.cxx:549
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Load the data for the entry from the database.
Definition TTreeSQL.cxx:728
TSQLServer * fServer
Definition TTreeSQL.h:52
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:621
Long64_t LoadTree(Long64_t entry) override
Setup the tree to the load the specified entry.
Definition TTreeSQL.cxx:737
TSQLResult * fResult
Definition TTreeSQL.h:50
virtual Long64_t PrepEntry(Long64_t entry)
Make sure the server and result set are setup for the requested entry.
Definition TTreeSQL.cxx:746
bool CreateTable(const TString &table)
Create the database table corresponding to this TTree.
Definition TTreeSQL.cxx:487
Int_t Fill() override
Copy the information from the user object to the TTree.
Definition TTreeSQL.cxx:569
TBranch * Bronch(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99) override
Not implemented yet.
Definition TTreeSQL.cxx:124
TString fQuery
Definition TTreeSQL.h:48
TString fTable
Definition TTreeSQL.h:49
virtual void CreateBranch(const TString &branchName, const TString &typeName)
Create the column(s) in the database that correspond to the branch/.
Definition TTreeSQL.cxx:368
Int_t fCurrentEntry
Definition TTreeSQL.h:45
TString fInsertQuery
Definition TTreeSQL.h:47
TSQLRow * fRow
Definition TTreeSQL.h:51
void ResetQuery()
Reset the internal query.
Definition TTreeSQL.cxx:807
Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="") override
Not implemented yet.
Definition TTreeSQL.cxx:95
bool CheckBranch(TBranch *tb)
Check if the table has a column corresponding the branch and that the resultset are properly setup.
Definition TTreeSQL.cxx:214
Long64_t GetEntries() const override
Get the number of rows in the database.
Definition TTreeSQL.cxx:687
TTreeSQL(TSQLServer *server, TString DB, const TString &table)
Constructor with an explicit TSQLServer.
Definition TTreeSQL.cxx:51
Long64_t GetEntriesFast() const override
Return the number of entries as of the last check.
Definition TTreeSQL.cxx:720
~TTreeSQL() override
Definition TTreeSQL.cxx:816
void Refresh() override
Refresh contents of this Tree and its branches from the current Tree status in the database One can c...
Definition TTreeSQL.cxx:795
void CheckBasket(TBranch *tb)
Check if the basket is properly setup.
Definition TTreeSQL.cxx:186
A TTree represents a columnar dataset.
Definition TTree.h:89
virtual Int_t Fill()
Fill all branches.
Definition TTree.cxx:4653
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition TTree.cxx:5718
TObjArray fBranches
List of Branches.
Definition TTree.h:132
Long64_t fEntries
Number of entries.
Definition TTree.h:94
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:389
Long64_t fReadEntry
! Number of the entry being processed
Definition TTree.h:117