Hi,
Thanks for your reply. In the meantime, I had solved the issue like this :
TFile f("../data/input_samples.root","RECREATE");
TTree T("ntuple","data from ascii file");
Long64_t nlines = T.ReadFile("../data/input_samples.csv",csv_format.c_str());
printf(" found %lld points\n",nlines);
T.Write();
The csv_format is a std::string which contains the names of the vars and their type (the header of the CSV file). The issue with this approach is that I can’t easily infer the type of the columns from the file (not all my columns are floating point numbers).
So I am back to the SQLite as suggested file without going through the CSV conversion. I am trying something like this:
auto dbname = "sqlite://../data/input_samples.sqlite";
auto username = "";
auto userpass = "";
auto f = new TSQLFile(dbname, "open", username, userpass);
f->ls();
But there seems to be a problem that I don’t understand, since I get the following message when I run this code:
Error in <TSQLFile::TSQLFile>: DB sqlite://../data/input_samples.sqlite tables not exist
TSQLFile** sqlite://../data/input_samples.sqlite TFile interface to SQL DB
TSQLFile* sqlite://../data/input_samples.sqlite TFile interface to SQL DB
I don’t think that there is a problem with my file, since the following works:
TSQLServer *db = TSQLServer::Connect("sqlite://../data/input_samples.sqlite","", "");
printf("Server info: %s\n", db->ServerInfo());
TSQLRow *row;
TSQLResult *res;
// list tables in database "test" (the permission tables)
printf("\nList all tables in database\n",
db->GetHost());
res = db->GetTables("");
while ((row = res->Next())) {
printf("%s\n", row->GetField(0));
delete row;
}
delete res;
auto* cols = db->GetTableInfo("selection")->GetColumns();
for(const auto&& col : *cols)
{
col->Print();
std::cout << "Name " << col->GetName() << '\n';
}
The col->Print() gives the correct information and col->GetName() also.
Now I am stuck retrieving the types of the columns, because
col->GetSQLType()
does not compile:
‘class TObject’ has no member named ‘GetSQLType’
and if I do:
std::cout << "SQL type " << ((TSQLColumnInfo*)col)->GetSQLType() << '\n';
I get -1; which means that something is wrong.
Any ideas?
Thanks.
Garjola.