Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df028_SQliteIPLocation.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_dataframe
3/// \notebook -js
4/// Plot the location of ROOT downloads reading a remote sqlite3 file.
5///
6/// The world map is held by a TH2Poly histogram which, after filling, will show
7/// the world wide dispersion of ROOT's users.
8/// To histogram filling, is done thanks to a lambda expression having as input parameters
9/// the two columns of the database: "IPLongitude' - for the longitude, and the
10/// "IPLatitude" - for the latitude.
11/// The data related to the latitude and the longitude has been provided from the
12/// log files storing the users IP.
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/// \macro_image
18///
19/// \date August 2018
20/// \author Alexandra-Maria Dobrescu
21
22void df028_SQliteIPLocation() {
23
24 auto rdf = ROOT::RDF::FromSqlite("http://root.cern/files/root_download_stats.sqlite", "SELECT * FROM accesslog;");
25
26 auto f = TFile::Open("http://root.cern.ch/files/WM.root");
27 auto worldMap = f->Get<TH2Poly>("WMUSA");
28
29 auto fillIPLocation = [&worldMap] ( const std::string &sLongitude, const std::string &sLatitude ) {
30 if (!( sLongitude == "" ) && !( sLatitude == "" )) {
31 auto latitude = std::stof(sLatitude);
32 auto longitude = std::stof(sLongitude);
33 worldMap->Fill(longitude, latitude);
34 }
35 };
36
37 rdf.Foreach( fillIPLocation, { "IPLongitude", "IPLatitude" } );
38
39 auto worldMapCanvas = new TCanvas();
40 worldMapCanvas->SetLogz();
41 worldMap->SetTitle("ROOT Downloads per Location (GitHub excluded);Longitude;Latitude");
42 worldMap->DrawClone("colz");
43}
#define f(i)
Definition RSha256.hxx:104
The Canvas class.
Definition TCanvas.h:23
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4053
2D Histogram with Polygonal Bins
Definition TH2Poly.h:66
RDataFrame FromSqlite(std::string_view fileName, std::string_view query)
Factory method to create a SQlite RDataFrame.