Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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/download/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 
25 void 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 }