Server program which allows clients, "spies", to connect and snoop objects.
To run this demo do the following:
- open two or more windows
- start root in all windows
- execute in the first window: .x spyserv.C (or spyserv.C++)
- execute in the other window(s): .x spy.C (or spy.C++)
- in the "spy" client windows click the "Connect" button and snoop the histograms by clicking on the "hpx", "hpxpy" and "hprof" buttons
class SpyServ {
private:
public:
SpyServ();
~SpyServ();
};
void SpyServ::HandleSocket(
TSocket *s)
{
fMon->Add(sock);
fSockets->Add(sock);
} else {
char request[64];
if (s->
Recv(request,
sizeof(request)) <= 0) {
fMon->Remove(s);
fSockets->Remove(s);
return;
}
if (!strcmp(request, "get hpx"))
answer.WriteObject(fHpx);
else if (!strcmp(request, "get hpxpy"))
answer.WriteObject(fHpxpy);
else if (!strcmp(request, "get hprof"))
answer.WriteObject(fHprof);
else
Error(
"SpyServ::HandleSocket",
"unexpected message");
}
}
SpyServ::SpyServ()
{
if (!fServ->IsValid())
fCanvas =
new TCanvas(
"SpyServ",
"SpyServ",200,10,700,500);
fCanvas->SetFillColor(42);
fCanvas->GetFrame()->SetFillColor(21);
fCanvas->GetFrame()->SetBorderSize(6);
fCanvas->GetFrame()->SetBorderMode(-1);
fHpx =
new TH1F(
"hpx",
"This is the px distribution",100,-4,4);
fHpxpy =
new TH2F(
"hpxpy",
"py vs px",40,-4,4,40,-4,4);
fHprof =
new TProfile(
"hprof",
"Profile of pz versus px",100,-4,4,0,20);
fHpx->SetFillColor(48);
gRandom->SetSeed();
const Int_t kUPDATE = 1000;
for (
Int_t i = 0; ; i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
fHpx->Fill(px);
fHpxpy->Fill(px,py);
fHprof->Fill(px,pz);
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) fHpx->
Draw();
fCanvas->Modified();
fCanvas->Update();
HandleSocket(s);
break;
if (
gROOT->IsInterrupted())
break;
}
}
}
SpyServ::~SpyServ()
{
fSockets->Delete();
delete fSockets;
delete fServ;
delete fCanvas;
delete fHpx;
delete fHpxpy;
delete fHprof;
}
void spyserv()
{
new SpyServ;
}
- Author
- Fons Rademakers
Definition in file spyserv.C.