Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
treeClient.C File Reference

Detailed Description

Client program which creates and fills 2 histograms and a TTree.

Every 1000000 fills the histograms and TTree is send to the server which displays the histogram.

To run this demo do the following:

  • Open at least 2 windows
  • Start ROOT in the first windows
  • Execute in the first window: .x fastMergeServer.C
  • Execute in the other windows: root.exe -b -l -q .x treeClient.C (You can put it in the background if wanted). If you want to run the hserv.C on a different host, just change "localhost" in the TSocket ctor below to the desired hostname.
#include "TMessage.h"
#include "TBenchmark.h"
#include "TSocket.h"
#include "TH2.h"
#include "TTree.h"
#include "TMemFile.h"
#include "TRandom.h"
#include "TError.h"
{
gBenchmark->Start("treeClient");
// Open connection to server
TSocket *sock = new TSocket("localhost", 9090);
if (!sock->IsValid()) {
Error("treeClient","Could not establish a connection with the server %s:%d.","localhost",9090);
return;
}
// Wait till we get the start message
// server tells us who we are
Int_t status, version, kind;
sock->Recv(status, kind);
if (kind != 0 /* kStartConnection */)
{
Error("treeClient","Unexpected server message: kind=%d status=%d\n",kind,status);
delete sock;
return;
}
sock->Recv(version, kind);
if (kind != 1 /* kStartConnection */)
{
Fatal("treeClient","Unexpected server message: kind=%d status=%d\n",kind,status);
} else {
Info("treeClient","Connected to fastMergeServer version %d\n",version);
}
int idx = status;
TMemFile *file = new TMemFile("mergedClient.root","RECREATE");
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 fillcolor
} else {
hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
}
Float_t px, py;
TTree *tree = new TTree("tree","tree");
tree->SetAutoFlush(4000000);
tree->Branch("px",&px);
tree->Branch("py",&py);
// Fill histogram randomly
const int kUPDATE = 1000000;
for (int i = 0; i < 25000000; ) {
gRandom->Rannor(px,py);
if (idx%2 == 0)
hpx->Fill(px);
else
hpx->Fill(px,py);
tree->Fill();
++i;
if (i && (i%kUPDATE) == 0) {
file->Write();
mess.Reset(kMESS_ANY); // re-use TMessage object
mess.WriteInt(idx);
mess.WriteTString(file->GetName());
mess.WriteLong64(file->GetEND()); // 'mess << file->GetEND();' is broken in CINT for Long64_t
file->CopyTo(mess);
sock->Send(mess); // send message
messlen += mess.Length();
cmesslen += mess.CompLength();
file->ResetAfterMerge(nullptr); // This resets only the TTree objects.
hpx->Reset();
}
}
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_ANY
@ kMESS_OBJECT
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
R__EXTERN TBenchmark * gBenchmark
Definition TBenchmark.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition TError.cxx:244
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
virtual void Start(const char *name)
Starts Benchmark with the specified name.
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
virtual Long64_t GetEND() const
Definition TFile.h:231
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) override
Write memory objects to this file.
Definition TFile.cxx:2441
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:19
virtual Long64_t CopyTo(void *to, Long64_t maxsize) const
Copy the binary representation of the TMemFile into the memory area starting at 'to' and of length at...
Definition TMemFile.cxx:255
void ResetAfterMerge(TFileMergeInfo *) override
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition TMemFile.cxx:320
static void EnableSchemaEvolutionForAll(Bool_t enable=kTRUE)
Static function enabling or disabling the automatic schema evolution.
Definition TMessage.cxx:116
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:615
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:507
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:818
virtual void Close(Option_t *opt="")
Close the socket.
Definition TSocket.cxx:389
virtual Bool_t IsValid() const
Definition TSocket.h:132
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:522
A TTree represents a columnar dataset.
Definition TTree.h:79
Authors
Fons Rademakers, Philippe Canal

Definition in file treeClient.C.