Logo ROOT  
Reference Guide
SQLitePlatformDistribution.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/files/root_download_stats.sqlite
8/// In order to display the Platform Distribution of ROOT, we choose to create two TH1F
9/// histograms: one that includes all types of platforms, other filtering and classifying them.
10/// This procedure is taking as parameter the values stored in the "Platform" column from the
11/// database. At the end, the histograms are filled
12/// with their specific demand regarding the platform's type.
13/// This product includes GeoLite2 data created by MaxMind, available from
14/// <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
15///
16/// \macro_code
17///
18/// \author Alexandra-Maria Dobrescu 08/2018
19
20#include <TSQLiteServer.h>
21#include <TSQLiteResult.h>
22#include <TSQLRow.h>
23#include <TString.h>
24
25void SQLitePlatformDistribution(){
26
27 TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
28
29 const char *rootPlatform = "SELECT Platform FROM accesslog;";
30
31 TSQLResult *rootPlatformRes = db->Query(rootPlatform);
32
33 TH1F *hrootPlatform = new TH1F("hrootPlatform", "Platform Distribution", 7, 0, -1);
34 TH1F *shorthrootPlatform = new TH1F("shorthrootPlatform", "Short Platform Distribution", 7, 0, -1);
35
36 while (TSQLRow *row = rootPlatformRes->Next()) {
37 TString rowPlatform(row->GetField(0));
38 TString Platform(rowPlatform);
39 TString Platform_0(rowPlatform(0,5));
40 TString Platform_1(rowPlatform(0,6));
41 TString Platform_2(rowPlatform(0,8));
42 if ( rowPlatform.Contains("win32") ){
43 shorthrootPlatform->Fill(Platform_0,1);
44 } else if ( rowPlatform.Contains("Linux") ){
45 shorthrootPlatform->Fill(Platform_0,1);
46 } else if ( rowPlatform.Contains("source") ){
47 shorthrootPlatform->Fill(Platform_1,1);
48 } else if ( rowPlatform.Contains("macosx64") ){
49 shorthrootPlatform->Fill(Platform_2,1);
50 } else if ( rowPlatform.Contains("IRIX64") ){
51 shorthrootPlatform->Fill(Platform_1,1);
52 }
53
54 hrootPlatform->Fill(Platform,1);
55
56 delete row;
57 }
58
59 TCanvas *PlatformDistributionHistogram = new TCanvas();
60
61 hrootPlatform->GetXaxis()->LabelsOption("a");
62 hrootPlatform->LabelsDeflate("X");
63 hrootPlatform->Draw();
64
65 TCanvas *shortPlatformDistributionHistogram = new TCanvas();
66
67 shorthrootPlatform->GetXaxis()->LabelsOption("a");
68 shorthrootPlatform->LabelsDeflate("X");
69 shorthrootPlatform->Draw();
70}
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition: TAxis.cxx:641
The Canvas class.
Definition: TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:577
TAxis * GetXaxis()
Definition: TH1.h:322
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3338
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
virtual void LabelsDeflate(Option_t *axis="X")
Reduce the number of bins for the axis passed in the option to the number of bins having a label.
Definition: TH1.cxx:5209
virtual TSQLRow * Next()=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