Logo ROOT  
Reference Guide
SQLiteVersionsOfRoot.C File Reference

Detailed Description

View in nbviewer Open in SWAN

This tutorial demonstrates how TSQLServer can be used to create a connection with a SQlite3 database. It accesses the Sqlite data base. Download from https://root.cern/download/root_download_stats.sqlite Then a TH1F histogram is created and filled using a expression which receives the recorded values in the "version" column of the sqlite3 database. The histogram shows the usage of the ROOT development version. This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com.

#include <TSQLiteServer.h>
#include <TSQLiteResult.h>
#include <TSQLRow.h>
#include <TString.h>
void SQLiteVersionsOfRoot(){
TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
const char *rootSourceVersion = "SELECT Version FROM accesslog;";
TSQLResult *rootSourceVersionRes = db->Query(rootSourceVersion);
TH1F *hVersionOfRoot= new TH1F("hVersionOfRoot", "Development Versions of ROOT", 7, 0, -1);
while (TSQLRow *row = rootSourceVersionRes->Next()) {
TString rowVersion(row->GetField(0));
TString shortVersion(rowVersion(0,4));
hVersionOfRoot->Fill(shortVersion,1);
delete row;
}
TCanvas *VersionOfRootHistogram = new TCanvas();
hVersionOfRoot->GetXaxis()->LabelsOption("a");
hVersionOfRoot->LabelsDeflate("X");
hVersionOfRoot->Draw();
}
Author
Alexandra-Maria Dobrescu 08/2018

Definition in file SQLiteVersionsOfRoot.C.

TSQLResult::Next
virtual TSQLRow * Next()=0
TSQLiteResult.h
TSQLiteServer.h
TString
Definition: TString.h:136
TAxis::LabelsOption
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition: TAxis.cxx:613
TString.h
TSQLResult
Definition: TSQLResult.h:32
TSQLServer::Connect
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
The db should be of the form: <dbms>://<host>[:<port>][/<database>], e.g.
Definition: TSQLServer.cxx:61
TSQLServer::Query
virtual TSQLResult * Query(const char *sql)=0
TSQLRow
Definition: TSQLRow.h:30
TSQLRow.h
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
TH1::LabelsDeflate
virtual void LabelsDeflate(Option_t *axis="X")
Reduce the number of bins for the axis passed in the option to the number of bins having a label.
Definition: TH1.cxx:5090
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
TSQLServer
Definition: TSQLServer.h:41
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997