ROOT
6.07/01
Reference Guide
ROOT Home Page
Main Page
Tutorials
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
tutorials
http
httpaccess.C
Go to the documentation of this file.
1
#include "
TH1.h
"
2
#include "
TH2.h
"
3
#include "
TRandom3.h
"
4
#include "
TSystem.h
"
5
#include "
THttpServer.h
"
6
7
void
httpaccess
()
8
{
9
// This program demonstrates access control to the THttpServer with digest methods.
10
// Authentication file auth.txt was generated with following shell commands:
11
// [shell] htdigest -c auth.txt root guest
12
// typing <empty> password for guest account
13
// [shell] htdigest auth.txt root admin
14
// typing 'admin' as password for admin account
15
// When macro started and opening in browser with url
16
// http://localhost:8080
17
// User name and password will be requested. One should
18
// either specify guest account without password or
19
// admin account with password 'admin'
20
//
21
// User with guest account only can monitor histograms
22
// User with admin account see commands, which can be executed
23
24
// create histograms
25
TH1D
*
hpx
=
new
TH1D
(
"hpx"
,
"This is the px distribution"
,100,-4,4);
26
hpx->
SetFillColor
(48);
27
hpx->
SetDirectory
(0);
28
TH2D
*
hpxpy
=
new
TH2D
(
"hpxpy"
,
"py vs px"
,40,-4,4,40,-4,4);
29
hpxpy->
SetDirectory
(0);
30
31
if
(
gSystem
->
AccessPathName
(
"auth.txt"
)!=0) {
32
printf
(
"Please start macro from directory where auth.txt file is available\n"
);
33
printf
(
"It required to supply authentication information for the http server\n"
);
34
return
;
35
}
36
37
// start http server
38
THttpServer
* serv =
new
THttpServer
(
"http:8080?auth_file=auth.txt&auth_domain=root"
);
39
40
// or start FastCGI server, where host server (like Apache or lighttpd) should enable own authentication
41
// for apache one should add correspondent module and authentication for fastcgi location
42
// for lighttpd one add following lines to configuration file:
43
// server.modules += ( "mod_auth" )
44
// auth.backend = "htdigest"
45
// auth.backend.htdigest.userfile = "/srv/auth/auth.txt"
46
// auth.require = ( "/root.app" => ( "method" => "digest", "realm" => "root", "require" => "valid-user" ))
47
// THttpServer* serv = new THttpServer("fastcgi:9000");
48
49
// One could specify location of newer version of JSROOT
50
// serv->SetJSROOT("https://root.cern.ch/js/3.6/");
51
52
// register histograms
53
serv->
Register
(
"/"
, hpx);
54
serv->
Register
(
"/"
, hpxpy);
55
56
// register commands, invoking object methods
57
serv->
RegisterCommand
(
"/ResetHPX"
,
"/hpx/->Reset();"
,
"button;rootsys/icons/ed_delete.png"
);
58
serv->
SetItemField
(
"/ResetHPX"
,
"_update_item"
,
"hpx"
);
// let browser update histogram view after commands execution
59
serv->
RegisterCommand
(
"/ResetHPXPY"
,
"/hpxpy/->Reset();"
,
"button;rootsys/icons/bld_delete.png"
);
60
serv->
SetItemField
(
"/ResetHPXPY"
,
"_update_item"
,
"hpxpy"
);
// let browser update histogram view after commands execution
61
// here also example how command with arguments can be invoked
62
serv->
RegisterCommand
(
"/RebinHPX"
,
"/hpx/->Rebin(%arg1%);"
,
"button;rootsys/icons/ed_execute.png"
);
63
serv->
SetItemField
(
"/RebinHPX"
,
"_update_item"
,
"hpx"
);
// let browser update histogram view after commands execution
64
65
// these two commands fully hidden for other accounts,
66
// only admin can see and execute these commands
67
serv->
Restrict
(
"/ResetHPX"
,
"visible=admin"
);
68
serv->
Restrict
(
"/ResetHPXPY"
,
"visible=admin"
);
69
70
// this command visible for other, but will be refused (return false)
71
// when executed from any other account
72
serv->
Restrict
(
"/RebinHPX"
,
"allow=admin"
);
73
74
// Fill histograms randomly
75
TRandom3
random
;
76
Float_t
px
,
py
;
77
const
Long_t
kUPDATE
= 1000;
78
Long_t
cnt
= 0;
79
while
(
kTRUE
) {
80
random.
Rannor
(px,py);
81
hpx->
Fill
(px);
82
hpxpy->
Fill
(px,py);
83
84
// IMPORTANT: one should regularly call ProcessEvents
85
if
(cnt++ % kUPDATE == 0) {
86
if
(
gSystem
->
ProcessEvents
())
break
;
87
}
88
}
89
}
TSystem::AccessPathName
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition:
TSystem.cxx:1213
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition:
TH1.cxx:3159
TSystem::ProcessEvents
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition:
TSystem.cxx:420
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:460
TRandom3
Random number generator class based on M.
Definition:
TRandom3.h:29
hsimple.random
tuple random
Definition:
hsimple.py:62
Float_t
float Float_t
Definition:
RtypesCore.h:53
TH1::SetDirectory
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition:
TH1.cxx:8266
hpxpy
TH2F * hpxpy
Definition:
hcons.C:33
py
Float_t py
Definition:
hprod.C:33
TSystem.h
httpaccess
void httpaccess()
Definition:
httpaccess.C:7
THttpServer::Register
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
Definition:
THttpServer.cxx:696
gSystem
R__EXTERN TSystem * gSystem
Definition:
TSystem.h:545
THttpServer.h
TAttFill::SetFillColor
virtual void SetFillColor(Color_t fcolor)
Definition:
TAttFill.h:50
TH2.h
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition:
TH1.h:613
Long_t
long Long_t
Definition:
RtypesCore.h:50
printf
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
THttpServer::RegisterCommand
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=0)
Register command which can be executed from web interface.
Definition:
THttpServer.cxx:749
kUPDATE
Definition:
TFitParametersDialog.cxx:45
px
Float_t px
Definition:
hprod.C:33
TH1.h
hpx
TH1F * hpx
Definition:
hcons.C:32
kTRUE
const Bool_t kTRUE
Definition:
Rtypes.h:91
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition:
TH2.cxx:287
TRandom3.h
THttpServer::SetItemField
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
Definition:
THttpServer.cxx:782
THttpServer::Restrict
void Restrict(const char *path, const char *options)
Restrict access to specified object.
Definition:
THttpServer.cxx:716
xmlio::cnt
const char * cnt
Definition:
TXMLSetup.cxx:75
THttpServer
Definition:
THttpServer.h:30
TH2D
2-D histogram with a double per channel (see TH1 documentation)}
Definition:
TH2.h:297