Logo ROOT  
Reference Guide
httpserver.C File Reference

Detailed Description

This program creates :

  • a one dimensional histogram
  • a two dimensional histogram
  • a profile histogram
  • a memory-resident ntuple

These objects are filled with some random numbers and saved on a in-memory file. All objects can be seen in web browser is open url:

http://localhost:8080
#include <TFile.h>
#include <TMemFile.h>
#include <TNtuple.h>
#include <TH2.h>
#include <TProfile.h>
#include <TCanvas.h>
#include <TFrame.h>
#include <TROOT.h>
#include <TSystem.h>
#include <TRandom3.h>
#include <TBenchmark.h>
#include <TInterpreter.h>
#include <THttpServer.h>
void httpserver(const char* jobname = "job1", Long64_t maxcnt = 0)
{
TString filename = Form("%s.root", jobname);
TFile *hfile = new TMemFile(filename,"RECREATE","Demo ROOT file with histograms");
// Create some histograms, a profile histogram and an ntuple
TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
hpx->SetFillColor(48);
TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
hfile->Write();
// http server with port 8080, use jobname as top-folder name
THttpServer* serv = new THttpServer(Form("http:8080?top=%s", jobname));
// fastcgi server with port 9000, use jobname as top-folder name
// THttpServer* serv = new THttpServer(Form("fastcgi:9000?top=%s_fastcgi", jobname));
// dabc agent, connects to DABC master_host:1237, works only when DABC configured
// THttpServer* serv = new THttpServer(Form("dabc:master_host:1237?top=%s_dabc", jobname));
// when read-only mode disabled one could execute object methods like TTree::Draw()
// One could specify location of newer version of JSROOT
// serv->SetJSROOT("https://root.cern.ch/js/latest/");
// serv->SetJSROOT("http://jsroot.gsi.de/latest/");
gBenchmark->Start(jobname);
// Create a new canvas.
TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
c1->SetFillColor(42);
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(6);
c1->GetFrame()->SetBorderMode(-1);
// Fill histograms randomly
TRandom3 random;
Float_t px, py, pz;
const Int_t kUPDATE = 1000;
Long64_t i = 0;
while (true) {
random.Rannor(px,py);
pz = px*px + py*py;
Float_t rnd = random.Rndm(1);
hpx->Fill(px);
hpxpy->Fill(px,py);
hprof->Fill(px,pz);
// fill only first 25000 events in NTuple
if (i<25000) ntuple->Fill(px,py,pz,rnd,i);
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) hpx->Draw();
c1->Modified();
c1->Update();
if (i == kUPDATE) hfile->Write();
if (gSystem->ProcessEvents()) break;
}
i++;
if ((maxcnt>0) && (i>=maxcnt)) break;
}
gBenchmark->Show(jobname);
}
Author
Sergey Linev

Definition in file httpserver.C.

TNtuple
Definition: TNtuple.h:28
TBenchmark::Start
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
Form
char * Form(const char *fmt,...)
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
Float_t
float Float_t
Definition: RtypesCore.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TMemFile
Definition: TMemFile.h:19
TCanvas.h
TProfile.h
THttpServer::SetReadOnly
void SetReadOnly(Bool_t readonly)
Set read-only mode for the server (default on) In read-only server is not allowed to change any ROOT ...
Definition: THttpServer.cxx:265
TString
Definition: TString.h:136
TFile::Write
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:2300
TFile.h
TNtuple.h
TROOT.h
TRandom::Rannor
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:489
TMemFile.h
THttpServer
Definition: THttpServer.h:31
TSystem.h
TRandom3
Definition: TRandom3.h:27
gBenchmark
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:59
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TProfile::Fill
Int_t Fill(const Double_t *v)
Definition: TProfile.h:54
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
TRandom3.h
TBenchmark.h
TH2.h
TFile
Definition: TFile.h:54
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
TProfile
Definition: TProfile.h:32
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
THttpServer.h
TCanvas
Definition: TCanvas.h:23
TRandom3::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:99
TInterpreter.h
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TFrame.h
kUPDATE
@ kUPDATE
Definition: TFitParametersDialog.cxx:51
TBenchmark::Show
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
TSystem::ProcessEvents
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:417
TNtuple::Fill
virtual Int_t Fill()
Fill a Ntuple with current values in fArgs.
Definition: TNtuple.cxx:169
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41