This macro demonstrates custom access and custom drawing for TMsgList class Main motivation for this example - demonstrate how traffic between server and client can be minimized and how one could build custom UI in the browser.
TMsgList in this tutorial keep last N messages, numbering each with unique identifier There is TMsgList::Select() method which selects messages from the list If one specifies identifier, only messages newer than this identifier are selected In the selection list (TList object of TObjString) first item always identifier for the latest message in the list
In JavaScript code (httptextlog.js) one uses Select() method to receive latest messages, which not yet been seen in the browser and display them as text At maximum, 1000 elements are preserved in the browser.
Macro should always be started in compiled mode, otherwise Select() method is not accessible via TClass instance. One also requires comments after ClassDef to correctly configure behavior of the JavaScript ROOT code
After macro started, one could open in browser address
One could either click item again or enable monitoring to always receive latest messages Or one could open only this output and nothing else:
In last case it could be used in iframe, also it requires less code to load on the page
#include <stdio.h>
#include <string.h>
class TMsgList :
public TNamed {
protected:
public:
TMsgList(
const char* name =
"log",
Int_t limit = 1000) :
TNamed(name,
"list of log messages"),
fMsgs(),
fLimit(limit),
fCounter(0),
fSelect(),
fStrCounter()
{
}
virtual ~TMsgList() { fMsgs.
Clear(); }
void AddMsg(const char* msg)
{
while (fMsgs.
GetSize() >= fLimit) {
delete last;
}
if (msg==0) return;
fCounter++;
}
{
if (max == 0) max = fMsgs.
GetLast()+1;
fSelect.
Add(&fStrCounter);
while (((obj = iter()) != 0) && (--curr >=
id) && (--max>=0)) fSelect.
Add(obj);
return &fSelect;
}
};
void httptextlog()
{
TMsgList*
log =
new TMsgList(
"log", 200);
if ((
TMsgList::Class()->GetMethodAllAny(
"Select") == 0) || (strcmp(log->ClassName(),
"TMsgList")!=0)) {
printf("Most probably, macro runs in interpreter mode\n");
printf("To access new methods from TMsgList class,\n");
printf("one should run macro with ACLiC like:\n");
printf(" shell> root -b httpextlog.C+\n");
return;
}
printf("Please start macro from directory where httptextlog.js is available\n");
printf("Only in this case web interface can work\n");
return;
}
TH1D *hpx =
new TH1D(
"hpx",
"This is the px distribution",100,-4,4);
TH2F *hpxpy =
new TH2F(
"hpxpy",
"py vs px",40,-4,4,40,-4,4);
serv->
Restrict(
"/log",
"allow_method=Select,GetTitle");
serv->
RegisterCommand(
"/Stop",
"bRun=kFALSE;",
"rootsys/icons/ed_delete.png");
serv->
RegisterCommand(
"/ExitRoot",
"gSystem->Exit(1);",
"rootsys/icons/ed_delete.png");
while (bRun) {
if (cnt++ % kUPDATE == 0) {
if (loop % 1000 == 0) {
loop = loop/1000;
}
}
}
delete serv;
}
- Author
Definition in file httptextlog.C.