ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
httpcontrol.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 
8 
9 void httpcontrol()
10 {
11 // This program demonstrates simple application control via THttpServer
12 // Two histogram are filled within endless loop.
13 // Via published commands one can enable/disable histograms filling
14 // There are also command to clear histograms content
15 //
16 // After macro started, open in browser with url
17 // http://localhost:8080
18 //
19 // Histograms will be automatically displayed and
20 // monitoring with interval 2000 ms started
21 
22  // create histograms
23  TH1D *hpx = new TH1D("hpx","This is the px distribution",100,-4,4);
24  hpx->SetFillColor(48);
25  hpx->SetDirectory(0);
26  TH2D *hpxpy = new TH2D("hpxpy","py vs px",40,-4,4,40,-4,4);
27  hpxpy->SetDirectory(0);
28 
29  // start http server
30  THttpServer* serv = new THttpServer("http:8080");
31 
32  // One could specify location of newer version of JSROOT
33  // serv->SetJSROOT("https://root.cern.ch/js/3.5/");
34  // serv->SetJSROOT("http://web-docs.gsi.de/~linev/js/3.5/");
35 
36  // register histograms
37  serv->Register("/", hpx);
38  serv->Register("/", hpxpy);
39 
40  // enable monitoring and
41  // specify items to draw when page is opened
42  serv->SetItemField("/","_monitoring","5000");
43  serv->SetItemField("/","_layout","grid2x2");
44  serv->SetItemField("/","_drawitem","[hpxpy,hpx,Debug]");
45  serv->SetItemField("/","_drawopt","col");
46 
47  // register simple start/stop commands
48  serv->RegisterCommand("/Start", "bFillHist=kTRUE;", "button;rootsys/icons/ed_execute.png");
49  serv->RegisterCommand("/Stop", "bFillHist=kFALSE;", "button;rootsys/icons/ed_interrupt.png");
50 
51  // one could hide commands and let them appear only as buttons
52  serv->Hide("/Start");
53  serv->Hide("/Stop");
54 
55  // register commands, invoking object methods
56  serv->RegisterCommand("/ResetHPX","/hpx/->Reset()", "button;rootsys/icons/ed_delete.png");
57  serv->RegisterCommand("/ResetHPXPY","/hpxpy/->Reset()", "button;rootsys/icons/bld_delete.png");
58 
59 
60  // create debug text element, use MathJax - works only on Firefox
61  serv->CreateItem("/Debug","debug output");
62  serv->SetItemField("/Debug", "_kind", "Text");
63  serv->SetItemField("/Debug", "value","\\(\\displaystyle{x+1\\over y-1}\\)");
64  serv->SetItemField("/Debug", "mathjax", "true");
65 
66  // Fill histograms randomly
68  Float_t px, py;
69  const Long_t kUPDATE = 1000;
70  Long_t cnt = 0;
71  while (kTRUE) {
72  if (bFillHist) {
73  random.Rannor(px,py);
74  hpx->Fill(px);
75  hpxpy->Fill(px,py);
76  cnt++;
77  } else {
78  gSystem->Sleep(10); // sleep minimal time
79  }
80 
81  if ((cnt % kUPDATE==0) || !bFillHist) {
82  // IMPORTANT: one should regularly call ProcessEvents
83  // to let http server process requests
84 
85  serv->SetItemField("/Debug", "value", Form("\\(\\displaystyle{x+1\\over y-1}\\) Loop:%d", cnt/kUPDATE));
86 
87  if (gSystem->ProcessEvents()) break;
88  }
89  }
90 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
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
tuple random
Definition: hsimple.py:62
float Float_t
Definition: RtypesCore.h:53
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
TH2F * hpxpy
Definition: hcons.C:33
bool Bool_t
Definition: RtypesCore.h:59
Float_t py
Definition: hprod.C:33
Bool_t CreateItem(const char *fullname, const char *title)
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:441
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
char * Form(const char *fmt,...)
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
long Long_t
Definition: RtypesCore.h:50
Bool_t Hide(const char *fullname, Bool_t hide=kTRUE)
hides folder or element from web gui
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=0)
Register command which can be executed from web interface.
Float_t px
Definition: hprod.C:33
TH1F * hpx
Definition: hcons.C:32
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:287
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
const char * cnt
Definition: TXMLSetup.cxx:75
void httpcontrol()
Definition: httpcontrol.C:9
Bool_t bFillHist
Definition: httpcontrol.C:7
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:297