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
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) :
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 (loop % 1000 == 0) {
loop = loop/1000;
int shift = loop % 40;
}
}
}
delete serv;
}
#define ClassDef(name, id)
R__EXTERN TSystem * gSystem
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
UInt_t Get() const
Return raw date/time as encoded by TDatime.
1-D histogram with a double per channel (see TH1 documentation)}
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
2-D histogram with a float per channel (see TH1 documentation)}
Int_t Fill(Double_t)
Invalid Fill method.
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=nullptr)
Register command which can be executed from web interface.
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
TRootSniffer * GetSniffer() const
returns pointer on objects sniffer
void Restrict(const char *path, const char *options)
Restrict access to specified object.
virtual void Add(TObject *obj)
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
virtual void RemoveLast()
Remove the last object of the list.
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
virtual void Clear(Option_t *option="")
Remove all objects from the list.
The TNamed class is the base class for all named ROOT classes.
Collectable string class.
void SetString(const char *s)
Mother of all ROOT objects.
Random number generator class based on M.
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
void SetAutoLoad(const char *scripts="")
When specified, _autoload attribute will be always add to top element of h.json/h....
virtual Int_t GetLast() const
Returns index of last object in collection.
static TString LLtoa(Long64_t value, Int_t base)
Converts a Long64_t to a TString with respect to the base specified (2-36).
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).