Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
SQLitePlatformDistribution.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 display the Platform Distribution of ROOT, we choose to create two TH1F
8/// histograms: one that includes all types of platforms, other filtering and classifying them.
9/// This procedure is taking as parameter the values stored in the "Platform" column from the
10/// database. At the end, the histograms are filled
11/// with their specific demand regarding the platform's type.
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
24void SQLitePlatformDistribution(){
25
26 TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
27
28 const char *rootPlatform = "SELECT Platform FROM accesslog;";
29
30 TSQLResult *rootPlatformRes = db->Query(rootPlatform);
31
32 TH1F *hrootPlatform = new TH1F("hrootPlatform", "Platform Distribution", 7, 0, -1);
33 TH1F *shorthrootPlatform = new TH1F("shorthrootPlatform", "Short Platform Distribution", 7, 0, -1);
34
35 while (TSQLRow *row = rootPlatformRes->Next()) {
36 TString rowPlatform(row->GetField(0));
37 TString Platform(rowPlatform);
38 TString Platform_0(rowPlatform(0,5));
39 TString Platform_1(rowPlatform(0,6));
40 TString Platform_2(rowPlatform(0,8));
41 if ( rowPlatform.Contains("win32") ){
42 shorthrootPlatform->Fill(Platform_0,1);
43 } else if ( rowPlatform.Contains("Linux") ){
44 shorthrootPlatform->Fill(Platform_0,1);
45 } else if ( rowPlatform.Contains("source") ){
46 shorthrootPlatform->Fill(Platform_1,1);
47 } else if ( rowPlatform.Contains("macosx64") ){
48 shorthrootPlatform->Fill(Platform_2,1);
49 } else if ( rowPlatform.Contains("IRIX64") ){
50 shorthrootPlatform->Fill(Platform_1,1);
51 }
52
53 hrootPlatform->Fill(Platform,1);
54
55 delete row;
56 }
57
58 TCanvas *PlatformDistributionHistogram = new TCanvas();
59
60 hrootPlatform->GetXaxis()->LabelsOption("a");
61 hrootPlatform->LabelsDeflate("X");
62 hrootPlatform->Draw();
63
64 TCanvas *shortPlatformDistributionHistogram = new TCanvas();
65
66 shorthrootPlatform->GetXaxis()->LabelsOption("a");
67 shorthrootPlatform->LabelsDeflate("X");
68 shorthrootPlatform->Draw();
69}
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition TAxis.cxx:658
The Canvas class.
Definition TCanvas.h:23
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 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:5261
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....
Basic string class.
Definition TString.h:139