Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
hclient.C File Reference

Detailed Description

Client program which creates and fills a histogram.

Every 1000 fills the histogram is send to the server which displays the histogram.

To run this demo do the following:

  • Open three windows
  • Start ROOT in all three windows
  • Execute in the first window: .x hserv.C (or hserv2.C)
  • Execute in the second and third windows: .x hclient.C If you want to run the hserv.C on a different host, just change "localhost" in the TSocket ctor below to the desired hostname.

The script argument "evol" can be used when using a modified version of the script where the clients and server are on systems with different versions of ROOT. When evol is set to kTRUE the socket will support automatic schema evolution between the client and the server.

void hclient(Bool_t evol=kFALSE)
{
gBenchmark->Start("hclient");
// Open connection to server
TSocket *sock = new TSocket("localhost", 9090);
// Wait till we get the start message
char str[32];
sock->Recv(str, 32);
// server tells us who we are
int idx = !strcmp(str, "go 0") ? 0 : 1;
Float_t messlen = 0;
Float_t cmesslen = 0;
if (idx == 1)
TH1 *hpx;
if (idx == 0) {
// Create the histogram
hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
hpx->SetFillColor(48); // set nice fill-color
} else {
hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
}
//TMessage mess(kMESS_OBJECT | kMESS_ACK);
// Fill histogram randomly
gRandom->SetSeed();
Float_t px, py;
const int kUPDATE = 1000;
for (int i = 0; i < 25000; i++) {
gRandom->Rannor(px,py);
if (idx == 0)
hpx->Fill(px);
else
hpx->Fill(px,py);
if (i && (i%kUPDATE) == 0) {
mess.Reset(); // re-use TMessage object
mess.WriteObject(hpx); // write object in message buffer
sock->Send(mess); // send message
messlen += mess.Length();
cmesslen += mess.CompLength();
}
}
sock->Send("Finished"); // tell server we are finished
if (cmesslen > 0)
printf("Average compression ratio: %g\n", messlen/cmesslen);
gBenchmark->Show("hclient");
// Close the socket
sock->Close();
}
@ kMESS_OBJECT
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
externTBenchmark * gBenchmark
Definition TBenchmark.h:59
externTRandom * gRandom
Definition TRandom.h:62
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
static void EnableSchemaEvolutionForAll(Bool_t enable=kTRUE)
Static function enabling or disabling the automatic schema evolution.
Definition TMessage.cxx:120
This class implements client sockets.
Definition TSocket.h:39
void SetCompressionLevel(Int_t level=ROOT::RCompressionSetting::ELevel::kUseMin)
See comments for function SetCompressionSettings.
Definition TSocket.cxx:1064
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:807
virtual void Close(Option_t *opt="")
Close the socket.
Definition TSocket.cxx:378
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:511
Author
Fons Rademakers

Definition in file hclient.C.