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