Logo ROOT  
Reference Guide
SQLiteTimeVersionOfRoot.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_sql
3/// \notebook -js
4///
5/// This tutorial demonstrates how TSQLServer can be used to create a
6/// connection with a SQlite3 database. It accesses the Sqlite data base.
7/// Download from https://root.cern/download/root_download_stats.sqlite
8/// In order to demonstrate the dependency over ROOT version 6.14, this tutorial uses the TSQLResult
9/// function which allows to extract the minimum time stored in the SQlite3 database.
10/// The next step is to create a TH1F Histogram, which will be filled with the values stored in
11/// two different columns from the database, the "Time" and "Version" columns.
12/// This product includes GeoLite2 data created by MaxMind, available from
13/// <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
14///
15/// \macro_code
16///
17/// \author Alexandra-Maria Dobrescu 08/2018
18
19#include <TSQLiteServer.h>
20#include <TSQLiteResult.h>
21#include <TSQLRow.h>
22#include <TString.h>
23
24void SQLiteTimeVersionOfRoot(){
25
26 TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
27
28 const char *minTime = "SELECT min(Time) FROM accesslog;";
29 TSQLResult *minTimeRes = db->Query(minTime);
30
31 std::string strMinTimeField = minTimeRes->Next()->GetField(0);
32 TDatime minTimeFormat(strMinTimeField.c_str());
33
34 TDatime now;
35 TH1F *hTime = new TH1F("hTime", "Duration of ROOT dependency over version 6.14", 10, minTimeFormat.Convert(), now.Convert());
36
37 const char *time = "SELECT Time, Version FROM accesslog;";
38 TSQLResult *timeRes = db->Query(time);
39
40 while (TSQLRow *row = timeRes->Next()) {
41 TDatime rowTime(row->GetField(0));
42 TString rowVersion(row->GetField(1));
43 TString shortVersion(rowVersion(0,4));
44 if ( shortVersion == "6.14" ) {
45 hTime->Fill(rowTime.Convert());
46 }
47 delete row;
48 }
49
50 TCanvas *timeHistogram = new TCanvas();
51
53 hTime->GetXaxis()->SetTimeDisplay(1);
54 hTime->GetXaxis()->SetLabelSize(0.02);
55 hTime->GetXaxis()->SetNdivisions(512, kFALSE);
56 hTime->GetXaxis()->SetTimeFormat("%Y-%m-%d");
57
58 hTime->Draw();
59}
const Bool_t kFALSE
Definition: RtypesCore.h:92
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:203
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:228
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:161
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:1020
The Canvas class.
Definition: TCanvas.h:23
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:37
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
Definition: TDatime.cxx:182
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:320
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3350
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3073
virtual TSQLRow * Next()=0
virtual const char * GetField(Int_t field)=0
virtual TSQLResult * Query(const char *sql)=0
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.: mysql://pcroot....
Definition: TSQLServer.cxx:61
Basic string class.
Definition: TString.h:136
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition: TStyle.cxx:1800