ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hclient.C
Go to the documentation of this file.
1 void hclient(Bool_t evol=kFALSE)
2 {
3  // Client program which creates and fills a histogram. Every 1000 fills
4  // the histogram is send to the server which displays the histogram.
5  //
6  // To run this demo do the following:
7  // - Open three windows
8  // - Start ROOT in all three windows
9  // - Execute in the first window: .x hserv.C (or hserv2.C)
10  // - Execute in the second and third windows: .x hclient.C
11  // If you want to run the hserv.C on a different host, just change
12  // "localhost" in the TSocket ctor below to the desired hostname.
13  //
14  // The script argument "evol" can be used when using a modified version
15  // of the script where the clients and server are on systems with
16  // different versions of ROOT. When evol is set to kTRUE the socket will
17  // support automatic schema evolution between the client and the server.
18  //
19  //Author: Fons Rademakers
20 
21  gBenchmark->Start("hclient");
22 
23  // Open connection to server
24  TSocket *sock = new TSocket("localhost", 9090);
25 
26  // Wait till we get the start message
27  char str[32];
28  sock->Recv(str, 32);
29 
30  // server tells us who we are
31  int idx = !strcmp(str, "go 0") ? 0 : 1;
32 
33  Float_t messlen = 0;
34  Float_t cmesslen = 0;
35  if (idx == 1)
36  sock->SetCompressionLevel(1);
37 
38  TH1 *hpx;
39  if (idx == 0) {
40  // Create the histogram
41  hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
42  hpx->SetFillColor(48); // set nice fillcolor
43  } else {
44  hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
45  }
46 
48  TMessage mess(kMESS_OBJECT);
49  //TMessage mess(kMESS_OBJECT | kMESS_ACK);
50 
51  // Fill histogram randomly
52  gRandom->SetSeed();
53  Float_t px, py;
54  const int kUPDATE = 1000;
55  for (int i = 0; i < 25000; i++) {
56  gRandom->Rannor(px,py);
57  if (idx == 0)
58  hpx->Fill(px);
59  else
60  hpx->Fill(px,py);
61  if (i && (i%kUPDATE) == 0) {
62  mess.Reset(); // re-use TMessage object
63  mess.WriteObject(hpx); // write object in message buffer
64  sock->Send(mess); // send message
65  messlen += mess.Length();
66  cmesslen += mess.CompLength();
67  }
68  }
69  sock->Send("Finished"); // tell server we are finished
70 
71  if (cmesslen > 0)
72  printf("Average compression ratio: %g\n", messlen/cmesslen);
73 
74  gBenchmark->Show("hclient");
75 
76  // Close the socket
77  sock->Close();
78 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
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
float Float_t
Definition: RtypesCore.h:53
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition: TSocket.cxx:520
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TSocket.cxx:818
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
Int_t CompLength() const
Definition: TMessage.h:95
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Float_t py
Definition: hprod.C:33
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
void SetCompressionLevel(Int_t level=1)
See comments for function SetCompressionSettings.
Definition: TSocket.cxx:1065
void Reset()
Reset the message buffer so we can use (i.e. fill) it again.
Definition: TMessage.cxx:171
virtual void Close(Option_t *opt="")
Close the socket.
Definition: TSocket.cxx:388
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
static void EnableSchemaEvolutionForAll(Bool_t enable=kTRUE)
Static function enabling or disabling the automatic schema evolution.
Definition: TMessage.cxx:116
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
The TH1 histogram class.
Definition: TH1.h:80
Float_t px
Definition: hprod.C:33
Int_t Length() const
Definition: TBuffer.h:96
void WriteObject(const TObject *obj)
Write object to message buffer.
Definition: TMessage.cxx:418
TH1F * hpx
Definition: hcons.C:32
void hclient(Bool_t evol=kFALSE)
Definition: hclient.C:1