Logo ROOT  
Reference Guide
SQLiteTimeVersionOfRoot.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 In order to demonstrate the dependency over ROOT version 6.14, this tutorial uses the TSQLResult function which allows to extract the minimum time stored in the SQlite3 database. The next step is to create a TH1F Histogram, which will be filled with the values stored in two different columns from the database, the "Time" and "Version" columns. 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 SQLiteTimeVersionOfRoot(){
TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
const char *minTime = "SELECT min(Time) FROM accesslog;";
TSQLResult *minTimeRes = db->Query(minTime);
std::string strMinTimeField = minTimeRes->Next()->GetField(0);
TDatime minTimeFormat(strMinTimeField.c_str());
TDatime now;
TH1F *hTime = new TH1F("hTime", "Duration of ROOT dependency over version 6.14", 10, minTimeFormat.Convert(), now.Convert());
const char *time = "SELECT Time, Version FROM accesslog;";
TSQLResult *timeRes = db->Query(time);
while (TSQLRow *row = timeRes->Next()) {
TDatime rowTime(row->GetField(0));
TString rowVersion(row->GetField(1));
TString shortVersion(rowVersion(0,4));
if ( shortVersion == "6.14" ) {
hTime->Fill(rowTime.Convert());
}
delete row;
}
TCanvas *timeHistogram = new TCanvas();
hTime->GetXaxis()->SetTimeDisplay(1);
hTime->GetXaxis()->SetLabelSize(0.02);
hTime->GetXaxis()->SetNdivisions(512, kFALSE);
hTime->GetXaxis()->SetTimeFormat("%Y-%m-%d");
hTime->Draw();
}
Author
Alexandra-Maria Dobrescu 08/2018

Definition in file SQLiteTimeVersionOfRoot.C.

TSQLResult::Next
virtual TSQLRow * Next()=0
TSQLiteResult.h
TAxis::SetTimeFormat
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:1020
TSQLiteServer.h
TAxis::SetTimeDisplay
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:161
TString
Definition: TString.h:136
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
TAttAxis::SetLabelSize
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:203
TSQLServer::Query
virtual TSQLResult * Query(const char *sql)=0
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
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
TStyle::SetTimeOffset
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1803
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TAttAxis::SetNdivisions
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:228
TDatime
Definition: TDatime.h:37
TDatime::Convert
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:182
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
TSQLRow::GetField
virtual const char * GetField(Int_t field)=0
TSQLServer
Definition: TSQLServer.h:41
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997