Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 with RSqliteDS.
5 /// The world map is hold by a TH2Poly histogram which, after filling, will show
6 /// the world wide dispersion of ROOT's users.
7 /// To histogram filling, is done thanks to a lambda expression having as input parameters
8 /// the two columns of the database: "IPLongitude' - for the longitude, and the
9 /// "IPLatitude" - for the latitude.
10 /// The data related to the latitude and the longitude has been provided from the
11 /// log files storing the users IP.
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 /// \macro_image
17 ///
18 /// \date August 2018
19 /// \author Alexandra-Maria Dobrescu
20 
21 void df028_SQliteIPLocation() {
22 
23  auto rdf = ROOT::RDF::MakeSqliteDataFrame( "http://root.cern/files/root_download_stats.sqlite", "SELECT * FROM accesslog;" );
24 
25  auto f = TFile::Open("http://root.cern.ch/files/WM.root");
26  auto worldMap = f->Get<TH2Poly>("WMUSA");
27 
28  auto fillIPLocation = [&worldMap] ( const std::string &sLongitude, const std::string &sLatitude ) {
29  if (!( sLongitude == "" ) && !( sLatitude == "" )) {
30  auto latitude = std::stof(sLatitude);
31  auto longitude = std::stof(sLongitude);
32  worldMap->Fill(longitude, latitude);
33  }
34  };
35 
36  rdf.Foreach( fillIPLocation, { "IPLongitude", "IPLatitude" } );
37 
38  auto worldMapCanvas = new TCanvas();
39  worldMapCanvas->SetLogz();
40  worldMap->SetTitle("ROOT Downloads per Location (GitHub exluded);Longitude;Latitude");
41  worldMap->DrawClone("colz");
42 }