Loading [MathJax]/jax/output/HTML-CSS/config.js
Logo ROOT   6.08/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 ///
11 /// \macro_code
12 ///
13 /// \author
14 
15 #include <TFile.h>
16 #include <TMemFile.h>
17 #include <TNtuple.h>
18 #include <TH2.h>
19 #include <TProfile.h>
20 #include <TCanvas.h>
21 #include <TFrame.h>
22 #include <TROOT.h>
23 #include <TSystem.h>
24 #include <TRandom3.h>
25 #include <TBenchmark.h>
26 #include <TInterpreter.h>
27 #include <THttpServer.h>
28 
29 void httpserver(const char* jobname = "job1", Long64_t maxcnt = 0)
30 {
31  TString filename = Form("%s.root", jobname);
32  TFile *hfile = new TMemFile(filename,"RECREATE","Demo ROOT file with histograms");
33 
34  // Create some histograms, a profile histogram and an ntuple
35  TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
36  hpx->SetFillColor(48);
37  TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
38  TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
39  TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
40  hfile->Write();
41 
42 
43  // http server with port 8080, use jobname as top-folder name
44  THttpServer* serv = new THttpServer(Form("http:8080?top=%s", jobname));
45 
46  // fastcgi server with port 9000, use jobname as top-folder name
47  // THttpServer* serv = new THttpServer(Form("fastcgi:9000?top=%s_fastcgi", jobname));
48 
49  // dabc agent, connects to DABC master_host:1237, works only when DABC configured
50  // THttpServer* serv = new THttpServer(Form("dabc:master_host:1237?top=%s_dabc", 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.ch/js/latest/");
57  // serv->SetJSROOT("http://jsroot.gsi.de/latest/");
58 
59  gBenchmark->Start(jobname);
60 
61  // Create a new canvas.
62  TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
63  c1->SetFillColor(42);
64  c1->GetFrame()->SetFillColor(21);
65  c1->GetFrame()->SetBorderSize(6);
66  c1->GetFrame()->SetBorderMode(-1);
67 
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 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3125
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:421
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:460
Random number generator class based on M.
Definition: TRandom3.h:29
long long Long64_t
Definition: RtypesCore.h:69
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:94
float Float_t
Definition: RtypesCore.h:53
virtual void SetBorderMode(Short_t bordermode)
Definition: TWbox.h:53
return c1
Definition: legend1.C:41
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:157
Basic string class.
Definition: TString.h:137
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
Profile Historam.
Definition: TProfile.h:34
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition: TMemFile.h:19
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:174
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2746
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:54
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 ...
A simple TTree restricted to a list of float variables only.
Definition: TNtuple.h:30
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
Definition: TFile.cxx:2268
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
tomato 2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:255
char * Form(const char *fmt,...)
Int_t Fill(const Double_t *v)
Definition: TProfile.h:56
The Canvas class.
Definition: TCanvas.h:41
virtual Int_t Fill()
Fill a Ntuple with current values in fArgs.
Definition: TNtuple.cxx:170
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308
void Modified(Bool_t flag=1)
Definition: TPad.h:399