Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
SQLiteTimeVersionOfRoot.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_sql
3/// \notebook -js
4/// This tutorial demonstrates how TSQLServer can be used to create a connection with a SQlite3 database.
5/// It accesses the Sqlite data base.
6/// Download from https://root.cern/files/root_download_stats.sqlite
7/// In order to demonstrate the dependency over ROOT version 6.14, this tutorial uses the TSQLResult
8/// function which allows to extract the minimum time stored in the SQlite3 database.
9/// The next step is to create a TH1F Histogram, which will be filled with the values stored in
10/// two different columns from the database, the "Time" and "Version" columns.
11/// This product includes GeoLite2 data created by MaxMind, available from
12/// <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
13///
14/// \macro_code
15///
16/// \author Alexandra-Maria Dobrescu 08/2018
17
18#include <TSQLiteServer.h>
19#include <TSQLiteResult.h>
20#include <TSQLRow.h>
21#include <TString.h>
22
23void SQLiteTimeVersionOfRoot(){
24
25 TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
26
27 const char *minTime = "SELECT min(Time) FROM accesslog;";
28 TSQLResult *minTimeRes = db->Query(minTime);
29
30 std::string strMinTimeField = minTimeRes->Next()->GetField(0);
31 TDatime minTimeFormat(strMinTimeField.c_str());
32
33 TDatime now;
34 TH1F *hTime = new TH1F("hTime", "Duration of ROOT dependency over version 6.14", 10, minTimeFormat.Convert(), now.Convert());
35
36 const char *time = "SELECT Time, Version FROM accesslog;";
37 TSQLResult *timeRes = db->Query(time);
38
39 while (TSQLRow *row = timeRes->Next()) {
40 TDatime rowTime(row->GetField(0));
41 TString rowVersion(row->GetField(1));
42 TString shortVersion(rowVersion(0,4));
43 if ( shortVersion == "6.14" ) {
44 hTime->Fill(rowTime.Convert());
45 }
46 delete row;
47 }
48
49 TCanvas *timeHistogram = new TCanvas();
50
52 hTime->GetXaxis()->SetTimeDisplay(1);
53 hTime->GetXaxis()->SetLabelSize(0.02);
54 hTime->GetXaxis()->SetNdivisions(512, kFALSE);
55 hTime->GetXaxis()->SetTimeFormat("%Y-%m-%d");
56
57 hTime->Draw();
58}
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
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:233
virtual void SetTimeDisplay(Int_t value)
Definition TAxis.h:173
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition TAxis.cxx:1159
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:634
TAxis * GetXaxis()
Definition TH1.h:336
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3333
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3055
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....
Basic string class.
Definition TString.h:139
void SetTimeOffset(Double_t toffset)
Change the time offset for time plotting.
Definition TStyle.cxx:1913