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
24
25 TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
26
27 const char *minTime = "SELECT min(Time) FROM accesslog;";
29
30 std::string strMinTimeField = minTimeRes->Next()->GetField(0);
32
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));
43 if ( shortVersion == "6.14" ) {
44 hTime->Fill(rowTime.Convert());
45 }
46 delete row;
47 }
48
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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
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
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:645
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