This is an example illustrating how the TSQLFile class can be used.
Histogram, list of TBox and clones array of TBox objects are stored to TSQLFile and read back. Except for the specific TSQLFile configuration, the TSQLFile functionality is absolutely similar to a normal root TFile
const char* dbname = "mysql://host.domain/test";
const char* username = "user";
const char* userpass = "pass";
void sqltables()
{
tables_write();
tables_read();
}
void tables_write()
{
if (
f->IsZombie()) {
delete f;
return; }
TH1I*
h1 =
new TH1I(
"histo1",
"histo title", 1000, -4., 4.);
h1->FillRandom(
"gaus",10000);
}
}
void tables_read()
{
if (
f->IsZombie()) {
delete f;
return; }
}
cout << "Printout of TList object" << endl;
if (obj!=0) obj->
Print(
"*");
delete obj;
cout << "Printout of TClonesArray object" << endl;
if (obj!=0) obj->
Print(
"*");
delete obj;
cout << "================ TBox QUERY ================ " << endl;
cout << "================ END of TBox QUERY ================ " << endl;
cout << "================== TH1I QUERY ================ " << endl;
cout << "================ END of TH1I QUERY ================ " << endl;
}
int Int_t
Signed integer 4 bytes (int).
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
An array of clone (identical) objects.
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
Write all objects in this collection.
1-D histogram with an int per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
void Add(TObject *obj) override
Mother of all ROOT objects.
@ kSingleKey
write collection with single key
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Access an SQL db via the TFile interface.
- Author
- Sergey Linev
Definition in file sqltables.C.