hclient.C

Go to the documentation of this file.
00001 void hclient(Bool_t evol=kFALSE) 
00002 {
00003    // Client program which creates and fills a histogram. Every 1000 fills
00004    // the histogram is send to the server which displays the histogram.
00005    //
00006    // To run this demo do the following:
00007    //   - Open three windows
00008    //   - Start ROOT in all three windows
00009    //   - Execute in the first window: .x hserv.C (or hserv2.C)
00010    //   - Execute in the second and third windows: .x hclient.C
00011    // If you want to run the hserv.C on a different host, just change
00012    // "localhost" in the TSocket ctor below to the desired hostname.
00013    //
00014    // The script argument "evol" can be used when using a modified version
00015    // of the script where the clients and server are on systems with
00016    // different versions of ROOT. When evol is set to kTRUE the socket will
00017    // support automatic schema evolution between the client and the server.
00018    //
00019    //Author: Fons Rademakers
00020    
00021    gBenchmark->Start("hclient");
00022 
00023    // Open connection to server
00024    TSocket *sock = new TSocket("localhost", 9090);
00025 
00026    // Wait till we get the start message
00027    char str[32];
00028    sock->Recv(str, 32);
00029 
00030    // server tells us who we are
00031    int idx = !strcmp(str, "go 0") ? 0 : 1;
00032 
00033    Float_t messlen  = 0;
00034    Float_t cmesslen = 0;
00035    if (idx == 1)
00036       sock->SetCompressionLevel(1);
00037 
00038    TH1 *hpx;
00039    if (idx == 0) {
00040       // Create the histogram
00041       hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
00042       hpx->SetFillColor(48);  // set nice fillcolor
00043    } else {
00044       hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
00045    }
00046 
00047    TMessage::EnableSchemaEvolutionForAll(evol);
00048    TMessage mess(kMESS_OBJECT);
00049    //TMessage mess(kMESS_OBJECT | kMESS_ACK);
00050 
00051    // Fill histogram randomly
00052    gRandom->SetSeed();
00053    Float_t px, py;
00054    const int kUPDATE = 1000;
00055    for (int i = 0; i < 25000; i++) {
00056       gRandom->Rannor(px,py);
00057       if (idx == 0)
00058          hpx->Fill(px);
00059       else
00060          hpx->Fill(px,py);
00061       if (i && (i%kUPDATE) == 0) {
00062          mess.Reset();              // re-use TMessage object
00063          mess.WriteObject(hpx);     // write object in message buffer
00064          sock->Send(mess);          // send message
00065          messlen  += mess.Length();
00066          cmesslen += mess.CompLength();
00067       }
00068    }
00069    sock->Send("Finished");          // tell server we are finished
00070 
00071    if (cmesslen > 0)
00072       printf("Average compression ratio: %g\n", messlen/cmesslen);
00073 
00074    gBenchmark->Show("hclient");
00075 
00076    // Close the socket
00077    sock->Close();
00078 }

Generated on Tue Jul 5 15:44:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1