-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathhttpserver.C
More file actions
97 lines (82 loc) · 2.86 KB
/
Copy pathhttpserver.C
File metadata and controls
97 lines (82 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/// \file
/// \ingroup tutorial_http
/// 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
/// ~~~
///
/// \macro_code
///
/// \author Sergey Linev
#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 "THttpServer.h"
void httpserver(const char* jobname = "job1", Long64_t maxcnt = 0)
{
auto filename = TString::Format("%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(TString::Format("http:8080?top=%s", jobname));
// fastcgi server with port 9000, use jobname as top-folder name
// THttpServer* serv = new THttpServer(TString::Format("fastcgi:9000?top=%s_fastcgi", jobname));
// when read-only mode disabled one could execute object methods like TTree::Draw()
serv->SetReadOnly(kFALSE);
// One could specify location of newer version of JSROOT
// serv->SetJSROOT("https://root.cern/js/latest/");
// serv->SetJSROOT("https://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);
}