Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
24 void 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 
52  gStyle->SetTimeOffset(0);
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 }