Logo ROOT  
Reference Guide
httpcontrol.C File Reference

Detailed Description

This program demonstrates simple application control via THttpServer Two histogram are filled within endless loop. Via published commands one can enable/disable histograms filling There are also command to clear histograms content

After macro started, open in browser with url

http://localhost:8080

Histograms will be automatically displayed and monitoring with interval 2000 ms started

#include "TH1.h"
#include "TH2.h"
#include "TRandom3.h"
#include "TSystem.h"
#include "THttpServer.h"
Bool_t bFillHist = kTRUE;
void httpcontrol()
{
// create histograms
TH1D *hpx = new TH1D("hpx","This is the px distribution",100,-4,4);
hpx->SetFillColor(48);
hpx->SetDirectory(0);
TH2D *hpxpy = new TH2D("hpxpy","py vs px",40,-4,4,40,-4,4);
hpxpy->SetDirectory(0);
// start http server
THttpServer* serv = new THttpServer("http:8080");
// One could specify location of newer version of JSROOT
// serv->SetJSROOT("https://root.cern.ch/js/latest/");
// serv->SetJSROOT("http://jsroot.gsi.de/latest/");
// register histograms
serv->Register("/", hpx);
serv->Register("/", hpxpy);
// enable monitoring and
// specify items to draw when page is opened
serv->SetItemField("/","_monitoring","5000");
serv->SetItemField("/","_layout","grid2x2");
serv->SetItemField("/","_drawitem","[hpxpy,hpx,Debug]");
serv->SetItemField("/","_drawopt","col");
// register simple start/stop commands
serv->RegisterCommand("/Start", "bFillHist=kTRUE;", "button;rootsys/icons/ed_execute.png");
serv->RegisterCommand("/Stop", "bFillHist=kFALSE;", "button;rootsys/icons/ed_interrupt.png");
// one could hide commands and let them appear only as buttons
serv->Hide("/Start");
serv->Hide("/Stop");
// register commands, invoking object methods
serv->RegisterCommand("/ResetHPX","/hpx/->Reset()", "button;rootsys/icons/ed_delete.png");
serv->RegisterCommand("/ResetHPXPY","/hpxpy/->Reset()", "button;rootsys/icons/bld_delete.png");
// create debug text element, use MathJax - works only on Firefox
serv->CreateItem("/Debug","debug output");
serv->SetItemField("/Debug", "_kind", "Text");
serv->SetItemField("/Debug", "value","\\(\\displaystyle{x+1\\over y-1}\\)");
serv->SetItemField("/Debug", "mathjax", "true");
// Fill histograms randomly
TRandom3 random;
Float_t px, py;
const Long_t kUPDATE = 1000;
Long_t cnt = 0;
while (kTRUE) {
if (bFillHist) {
random.Rannor(px,py);
hpx->Fill(px);
hpxpy->Fill(px,py);
cnt++;
} else {
gSystem->Sleep(10); // sleep minimal time
}
if ((cnt % kUPDATE==0) || !bFillHist) {
// IMPORTANT: one should regularly call ProcessEvents
// to let http server process requests
serv->SetItemField("/Debug", "value", Form("\\(\\displaystyle{x+1\\over y-1}\\) Loop:%ld", cnt/kUPDATE));
if (gSystem->ProcessEvents()) break;
}
}
}
Author
Sergey Linev

Definition in file httpcontrol.C.

kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
THttpServer::SetItemField
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
Definition: THttpServer.cxx:1184
THttpServer::CreateItem
Bool_t CreateItem(const char *fullname, const char *title)
Definition: THttpServer.cxx:1177
Form
char * Form(const char *fmt,...)
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:615
Float_t
float Float_t
Definition: RtypesCore.h:57
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
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
THttpServer
Definition: THttpServer.h:31
TSystem.h
TRandom3
Definition: TRandom3.h:27
THttpServer::Register
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
Definition: THttpServer.cxx:980
Long_t
long Long_t
Definition: RtypesCore.h:54
TH2D
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:292
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
TRandom3.h
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:8392
TSystem::Sleep
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:438
TH2.h
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
THttpServer.h
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:1151
kUPDATE
@ kUPDATE
Definition: TFitParametersDialog.cxx:51
THttpServer::Hide
Bool_t Hide(const char *fullname, Bool_t hide=kTRUE)
hides folder or element from web gui
Definition: THttpServer.cxx:1159
xmlio::cnt
const char * cnt
Definition: TXMLSetup.cxx:81
TH1.h
TSystem::ProcessEvents
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:417