ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
httpserver.C
Go to the documentation of this file.
1 #include <TFile.h>
2 #include <TMemFile.h>
3 #include <TNtuple.h>
4 #include <TH2.h>
5 #include <TProfile.h>
6 #include <TCanvas.h>
7 #include <TFrame.h>
8 #include <TROOT.h>
9 #include <TSystem.h>
10 #include <TRandom3.h>
11 #include <TBenchmark.h>
12 #include <TInterpreter.h>
13 #include <THttpServer.h>
14 
15 void httpserver(const char* jobname = "job1", Long64_t maxcnt = 0)
16 {
17 // This program creates :
18 // - a one dimensional histogram
19 // - a two dimensional histogram
20 // - a profile histogram
21 // - a memory-resident ntuple
22 //
23 // These objects are filled with some random numbers and saved on a in-memory file.
24 
25  TString filename = Form("%s.root", jobname);
26  TFile *hfile = new TMemFile(filename,"RECREATE","Demo ROOT file with histograms");
27 
28  // Create some histograms, a profile histogram and an ntuple
29  TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
30  hpx->SetFillColor(48);
31  TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
32  TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
33  TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
34  hfile->Write();
35 
36 
37  // http server with port 8080, use jobname as top-folder name
38  THttpServer* serv = new THttpServer(Form("http:8080?top=%s", jobname));
39 
40  // fastcgi server with port 9000, use jobname as top-folder name
41  // THttpServer* serv = new THttpServer(Form("fastcgi:9000?top=%s_fastcgi", jobname));
42 
43  // dabc agent, connects to DABC master_host:1237, works only when DABC configured
44  // THttpServer* serv = new THttpServer(Form("dabc:master_host:1237?top=%s_dabc", jobname));
45 
46  // when read-only mode disabled one could execute object methdos like TTree::Draw()
47  serv->SetReadOnly(kFALSE);
48 
49  gBenchmark->Start(jobname);
50 
51  // Create a new canvas.
52  TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
53  c1->SetFillColor(42);
54  c1->GetFrame()->SetFillColor(21);
55  c1->GetFrame()->SetBorderSize(6);
56  c1->GetFrame()->SetBorderMode(-1);
57 
58 
59  // Fill histograms randomly
61  Float_t px, py, pz;
62  const Int_t kUPDATE = 1000;
63  Long64_t i = 0;
64 
65  while (true) {
66  random.Rannor(px,py);
67  pz = px*px + py*py;
68  Float_t rnd = random.Rndm(1);
69  hpx->Fill(px);
70  hpxpy->Fill(px,py);
71  hprof->Fill(px,pz);
72  // fill only first 25000 events in NTuple
73  if (i<25000) ntuple->Fill(px,py,pz,rnd,i);
74  if (i && (i%kUPDATE) == 0) {
75  if (i == kUPDATE) hpx->Draw();
76  c1->Modified();
77  c1->Update();
78  if (i == kUPDATE) hfile->Write();
79 
80  if (gSystem->ProcessEvents()) break;
81  }
82  i++;
83  if ((maxcnt>0) && (i>=maxcnt)) break;
84  }
85 
86  gBenchmark->Show(jobname);
87 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
tuple ntuple
Definition: hsimple.py:39
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
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
Float_t pz
Definition: hprod.C:33
long long Long64_t
Definition: RtypesCore.h:69
tuple hfile
Definition: hsimple.py:30
tuple random
Definition: hsimple.py:62
float Float_t
Definition: RtypesCore.h:53
virtual void SetBorderMode(Short_t bordermode)
Definition: TWbox.h:62
TCanvas * c1
Definition: legend1.C:2
TH2F * hpxpy
Definition: hcons.C:33
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
void httpserver(const char *jobname="job1", Long64_t maxcnt=0)
Definition: httpserver.C:15
static const char * filename()
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
Basic string class.
Definition: TString.h:137
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
TProfile * hprof
Definition: hcons.C:34
Float_t py
Definition: hprod.C:33
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:172
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2729
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom3.cxx:94
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:63
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:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
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:2248
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
char * Form(const char *fmt,...)
Int_t Fill(const Double_t *v)
Definition: TProfile.h:56
The Canvas class.
Definition: TCanvas.h:48
virtual Int_t Fill()
[fNvar] Array of variables
Definition: TNtuple.cxx:168
Float_t px
Definition: hprod.C:33
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
TH1F * hpx
Definition: hcons.C:32
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:287
void Modified(Bool_t flag=1)
Definition: TPad.h:407