43 TTree(table.
Data(), "Database
read from table: " + table, 0), fDB(DB),
50 fQuery =
TString(
"Select * from " + fTable);
54 Error(
"TTreeSQL",
"No TSQLServer specified");
57 if (CheckTable(fTable.Data())) {
69 Fatal(
"BranchImp",
"Not implemented yet");
79 Fatal(
"BranchImp",
"Not implemented yet");
89 Fatal(
"Branch",
"Not implemented yet");
98 Fatal(
"Branch",
"Not implemented yet");
108 Fatal(
"Branch",
"Not implemented yet");
118 Fatal(
"Bronc",
"Not implemented yet");
128 Fatal(
"BranchOld",
"Not implemented yet");
138 Fatal(
"Branch",
"Not implemented yet");
146 const char *leaflist,
Int_t bufsize)
152 for (
int i=0;i<nb;i++) {
161 Fatal(
"Branch()",
"Duplicate branch!!!");
182 if (basket==0)
return;
194 for (
int i=0;i<nb;i++) {
218 if (!basket)
return kFALSE;
222 Error(
"CheckBranch",
"%s has basket but no resultset yet",tb->
GetName());
228 for(
int j=0;j<nl;j++) {
256 if (!tables)
return kFALSE;
258 while( (row = tables->
Next()) ) {
283 if(typeName ==
"Char_t"){
286 else if(typeName ==
"Int_t") {
289 else if(typeName ==
"Short_t") {
292 else if( typeName ==
"UShort_t") {
293 tn =
"SMALLINT UNSIGNED";
295 else if(typeName ==
"Float_t"){
298 else if(typeName ==
"Float16_t"){
301 else if(typeName ==
"Double_t"){
304 else if(typeName ==
"Double32_t"){
307 else if(typeName ==
"UInt_t") {
310 else if( typeName ==
"Long_t") {
313 else if( typeName ==
"ULong_t") {
314 tn =
"INTEGER UNSIGNED";
316 else if( typeName ==
"Long64_t") {
319 else if( typeName ==
"ULong64_t") {
320 tn =
"BIGINT UNSIGNED";
322 else if( typeName ==
"Bool_t") {
326 Error(
"ConvertTypeName",
"TypeName (%s) not found",typeName.
Data());
339 Error(
"CreateBasket",
"No TSQLServer specified");
357 Error(
"CreateBranch",
"No TSQLServer specified");
362 alterSQL =
"ALTER TABLE ";
365 alterSQL += branchName.
Data();;
367 alterSQL += typeName;
391 for(
int i=0; i < rows; ++i ) {
398 type =
type(0,index);
403 leafName = branchName(pos+2,branchName.
Length());
406 leafName = branchName;
408 if (prevBranch.
Length()) {
409 if (prevBranch != branchName) {
423 prevBranch = branchName;
427 prevBranch = branchName;
432 snprintf(siz,6,
"[%d]",prec);
433 decl.
Append( leafName+siz+
"/C:" );
436 decl.
Append( leafName+
"/I:" );
441 decl.
Append( leafName+
"/I:" );
446 decl.
Append( leafName+
"/i:" );
449 decl.
Append( leafName+
"/S:" );
459 decl.
Append( leafName+
"/F:" );
466 if (prevBranch.
Length()) {
486 Error(
"CreateTable",
"No TSQLServer specified");
490 TString branchName, leafName, typeName;
491 TString createSQL, alterSQL, str;
500 branchName = branch->
GetName();
508 if(i == 0 && j == 0) {
510 createSQL +=
"CREATE TABLE ";
513 createSQL += branchName;
515 createSQL += leafName;
517 createSQL += typeName;
523 Error(
"CreateTable",
"May have failed");
577 for (
int i=0;i<nb;i++) {
583 for(
int i=0;i<nb;i++) {
586 Error(
"Fill",
"CheckBranch for %s failed",branch->
GetName());
617 std::vector<Int_t> *columns =
new std::vector<Int_t>;
621 std::vector<TString> names;
624 if (rs==0) {
delete columns;
return 0; }
627 std::pair<TString,Int_t>
value;
629 for (
Int_t i=0;i<rows;++i) {
631 names.push_back( row->
GetField(0) );
636 for(
int j=0;j<nl;j++) {
647 for (
Int_t i=0;i<rows;++i) {
655 for (
Int_t i=0;i<rows;++i) {
663 columns->push_back(col);
664 }
else Error(
"GetColumnIndice",
"Error finding column %d %s",j,str.
Data());
666 if (columns->empty()) {
667 delete columns;
return 0;
695 sscanf(val.
Data(),
"%ld",&(ret) );
752 if (
fRow==0 && !reset) {
759 if (
fRow==0)
return -1;
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
double read(const std::string &file_name)
reading
TSQLResult * GetResultSet()
TString CreateBranches(TSQLResult *rs)
determine leaf description string
R__EXTERN Int_t gErrorIgnoreLevel
TObjArray * GetListOfBaskets()
virtual TSQLResult * Query(const char *sql)=0
virtual Int_t Fill()
Copy the information from the user object to the TTree.
virtual Int_t Fill()
Fill all branches.
void Init()
Initializeation routine.
Buffer base class used for serializing objects.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Bool_t CheckBranch(TBranch *tb)
Check if the table has a column corresponding the branch and that the resultset are properly setup...
virtual Int_t GetRowCount() const
virtual Long64_t GetEntriesFast() const
Return the number of entries as of the last check.
Int_t GetEntriesFast() const
Implement TTree for a SQL backend.
Long64_t * GetBasketEntry() const
virtual TBranch * BranchOld(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=1)
Not implemented yet.
const char * Data() const
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
void CreateBuffer(const char *name, TString title, std::vector< Int_t > *vc, TBranch *branch, TSQLResult **rs)
Create a TSQLBuffer for this basket.
virtual TBranch * BranchImp(const char *branchname, const char *classname, TClass *ptrClass, void *addobj, Int_t bufsize, Int_t splitlevel)
Not implemented yet.
virtual Long64_t LoadTree(Long64_t entry)
Setup the tree to the load the specified entry.
void ResetQuery()
Reset the internal query.
void Init(TClassEdit::TInterpreterLookupHelper *helper)
virtual void CreateBranch(const TString &branchName, const TString &typeName)
Create the column(s) in the database that correspond to the branch/.
TString & Append(const char *cs)
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...
TObjArray * GetListOfBranches()
TBasket * GetBasket(Int_t basket)
Return pointer to basket basketnumber in this Branch.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void Error(const char *location, const char *msgfmt,...)
TBuffer * GetBufferRef() const
TObject * UncheckedAt(Int_t i) const
void Refresh()
Refresh contents of this Tree and its branches from the current Tree status in the database One can c...
virtual const char * GetTypeName() const
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
virtual void SetEntries(Long64_t entries)
Set the number of entries in this branch.
Long64_t fReadEntry
Offset of 1st entry of this Tree in a TChain.
Collection abstract base class.
TObjArray fBranches
Pointer to directory holding this tree.
Manages buffers for branches of a Tree.
virtual const char * GetField(Int_t field)=0
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
virtual Int_t GetFieldCount()=0
TString & Remove(Ssiz_t pos)
Implement TBasket for a SQL backend.
virtual void ResetAddress()
Reset the address of the branch.
virtual TSQLResult * GetTables(const char *dbname, const char *wild=0)=0
ClassImp(TTreeSQL) TTreeSQL
Constructor with an explicit TSQLServer.
TObjArray * GetListOfLeaves()
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Load the data for the entry from the database.
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Not implemented yet.
virtual TBranch * Bronch(const char *name, const char *classname, void *addobj, Int_t bufsize=32000, Int_t splitlevel=99)
Not implemented yet.
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.
Bool_t CreateTable(const TString &table)
Create the database table corresponding to this TTree.
Bool_t CheckTable(const TString &table) const
Check the table exist in the database.
virtual Long64_t GetEntries() const
Get the number of rows in the database.
virtual TBasket * CreateBasket(TBranch *br)
Create a TBasketSQL.
void CheckBasket(TBranch *tb)
Check if the basket is properly setup.
A TTree object has a header with a name and a title.
virtual const char * GetFieldName(Int_t field)=0
TString ConvertTypeName(const TString &typeName)
Convert from ROOT typename to SQL typename.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
A TTree is a list of TBranches.
virtual Long64_t PrepEntry(Long64_t entry)
Make sure the server and result set are setup for the requested entry.
Ssiz_t First(char c) const
Find first occurrence of a character c.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
virtual TSQLRow * Next()=0