Logo ROOT  
Reference Guide
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
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/// ~~~
15/// \macro_code
17/// \author Sergey Linev
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 <TInterpreter.h>
31#include <THttpServer.h>
33void httpserver(const char* jobname = "job1", Long64_t maxcnt = 0)
35 TString filename = Form("%s.root", jobname);
36 TFile *hfile = new TMemFile(filename,"RECREATE","Demo ROOT file with histograms");
38 // Create some histograms, a profile histogram and an ntuple
39 TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
40 hpx->SetFillColor(48);
41 TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
42 TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
43 TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
44 hfile->Write();
47 // http server with port 8080, use jobname as top-folder name
48 THttpServer* serv = new THttpServer(Form("http:8080?top=%s", jobname));
50 // fastcgi server with port 9000, use jobname as top-folder name
51 // THttpServer* serv = new THttpServer(Form("fastcgi:9000?top=%s_fastcgi", jobname));
53 // dabc agent, connects to DABC master_host:1237, works only when DABC configured
54 // THttpServer* serv = new THttpServer(Form("dabc:master_host:1237?top=%s_dabc", jobname));
56 // when read-only mode disabled one could execute object methods like TTree::Draw()
57 serv->SetReadOnly(kFALSE);
59 // One could specify location of newer version of JSROOT
60 // serv->SetJSROOT("https://root.cern.ch/js/latest/");
61 // serv->SetJSROOT("http://jsroot.gsi.de/latest/");
63 gBenchmark->Start(jobname);
65 // Create a new canvas.
66 TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
67 c1->SetFillColor(42);
68 c1->GetFrame()->SetFillColor(21);
69 c1->GetFrame()->SetBorderSize(6);
70 c1->GetFrame()->SetBorderMode(-1);
73 // Fill histograms randomly
74 TRandom3 random;
75 Float_t px, py, pz;
76 const Int_t kUPDATE = 1000;
77 Long64_t i = 0;
79 while (true) {
80 random.Rannor(px,py);
81 pz = px*px + py*py;
82 Float_t rnd = random.Rndm(1);
83 hpx->Fill(px);
84 hpxpy->Fill(px,py);
85 hprof->Fill(px,pz);
86 // fill only first 25000 events in NTuple
87 if (i<25000) ntuple->Fill(px,py,pz,rnd,i);
88 if (i && (i%kUPDATE) == 0) {
89 if (i == kUPDATE) hpx->Draw();
90 c1->Modified();
91 c1->Update();
92 if (i == kUPDATE) hfile->Write();
94 if (gSystem->ProcessEvents()) break;
95 }
96 i++;
97 if ((maxcnt>0) && (i>=maxcnt)) break;
98 }
100 gBenchmark->Show(jobname);
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
long long Long64_t
Definition: RtypesCore.h:80
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:59
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2456
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
The Canvas class.
Definition: TCanvas.h:23
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) override
Write memory objects to this file.
Definition: TFile.cxx:2402
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:577
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3338
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:257
Int_t Fill(Double_t) override
Invalid Fill method.
Definition: TH2.cxx:347
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:19
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:28
Int_t Fill() override
Fill a Ntuple with current values in fArgs.
Definition: TNtuple.cxx:169
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:99
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:500
Basic string class.
Definition: TString.h:136
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:419
return c1
Definition: legend1.C:41