Logo ROOT  
Reference Guide
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
21void 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}
#define f(i)
Definition: RSha256.hxx:104
The Canvas class.
Definition: TCanvas.h:27
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:3942
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:66
RDataFrame MakeSqliteDataFrame(std::string_view fileName, std::string_view query)
Factory method to create a SQlite RDataFrame.
Definition: RSqliteDS.cxx:541