Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
httpserver.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_http
3/// This program creates :
4/// - a one dimensional histogram
5/// - a two dimensional histogram
6/// - a profile histogram
7/// - a memory-resident ntuple
8///
9/// These objects are filled with some random numbers and saved on a in-memory file.
10/// All objects can be seen in web browser is open url:
11/// ~~~
12/// http://localhost:8080
13/// ~~~
14///
15/// \macro_code
16///
17/// \author Sergey Linev
18
19#include "TFile.h"
20#include "TMemFile.h"
21#include "TNtuple.h"
22#include "TH2.h"
23#include "TProfile.h"
24#include "TCanvas.h"
25#include "TFrame.h"
26#include "TROOT.h"
27#include "TSystem.h"
28#include "TRandom3.h"
29#include "TBenchmark.h"
30#include "THttpServer.h"
31
32void httpserver(const char* jobname = "job1", Long64_t maxcnt = 0)
33{
34 auto filename = TString::Format("%s.root", jobname);
35 TFile *hfile = new TMemFile(filename,"RECREATE","Demo ROOT file with histograms");
36
37 // Create some histograms, a profile histogram and an ntuple
39 hpx->SetFillColor(48);
40 TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
41 TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
43 hfile->Write();
44
45
46 // http server with port 8080, use jobname as top-folder name
47 THttpServer* serv = new THttpServer(TString::Format("http:8080?top=%s", jobname));
48
49 // fastcgi server with port 9000, use jobname as top-folder name
50 // THttpServer* serv = new THttpServer(TString::Format("fastcgi:9000?top=%s_fastcgi", jobname));
51
52 // when read-only mode disabled one could execute object methods like TTree::Draw()
53 serv->SetReadOnly(kFALSE);
54
55 // One could specify location of newer version of JSROOT
56 // serv->SetJSROOT("https://root.cern/js/latest/");
57 // serv->SetJSROOT("https://jsroot.gsi.de/latest/");
58
59
60 gBenchmark->Start(jobname);
61
62 // Create a new canvas.
63 TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
64 c1->SetFillColor(42);
65 c1->GetFrame()->SetFillColor(21);
66 c1->GetFrame()->SetBorderSize(6);
67 c1->GetFrame()->SetBorderMode(-1);
68
69 // Fill histograms randomly
70 TRandom3 random;
71 Float_t px, py, pz;
72 const Int_t kUPDATE = 1000;
73 Long64_t i = 0;
74
75 while (true) {
76 random.Rannor(px,py);
77 pz = px*px + py*py;
78 Float_t rnd = random.Rndm(1);
79 hpx->Fill(px);
80 hpxpy->Fill(px,py);
81 hprof->Fill(px,pz);
82 // fill only first 25000 events in NTuple
83 if (i < 25000) ntuple->Fill(px,py,pz,rnd,i);
84 if (i && (i%kUPDATE) == 0) {
85 if (i == kUPDATE) hpx->Draw();
86 c1->Modified();
87 c1->Update();
88 if (i == kUPDATE) hfile->Write();
89
90 if (gSystem->ProcessEvents()) break;
91 }
92 i++;
93 if ((maxcnt>0) && (i>=maxcnt)) break;
94 }
95
96 gBenchmark->Show(jobname);
97}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
externTBenchmark * gBenchmark
Definition TBenchmark.h:59
externTSystem * gSystem
Definition TSystem.h:582
The Canvas class.
Definition TCanvas.h:23
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write memory objects to this file.
Definition TFile.cxx:2488
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:363
Online http server for arbitrary ROOT application.
Definition THttpServer.h:31
void SetReadOnly(Bool_t readonly=kTRUE)
Set read-only mode for the server (default on).
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:27
A simple TTree restricted to a list of float variables only.
Definition TNtuple.h:28
Profile Histogram.
Definition TProfile.h:32
Int_t Fill(const Double_t *v)
Definition TProfile.h:55
Random number generator class based on M.
Definition TRandom3.h:27
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom3.cxx:107
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition TRandom.cxx:506
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2385
return c1
Definition legend1.C:41