ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
parallelMergeClient.C
Go to the documentation of this file.
1 #include "TMessage.h"
2 #include "TBenchmark.h"
3 #include "TSocket.h"
4 #include "TH2.h"
5 #include "TTree.h"
6 #include "TParallelMergingFile.h"
7 #include "TRandom.h"
8 #include "TError.h"
9 
11 {
12  // Client program which creates and fills 2 histograms and a TTree.
13  // Every 1000000 fills the histograms and TTree is send to the server which displays the histogram.
14  //
15  // To run this demo do the following:
16  // - Open at least 2 windows
17  // - Start ROOT in the first windows
18  // - Execute in the first window: .x fastMergeServer.C
19  // - Execute in the other windows: root.exe -b -l -q .x treeClient.C
20  // (You can put it in the background if wanted).
21  // If you want to run the hserv.C on a different host, just change
22  // "localhost" in the TSocket ctor below to the desired hostname.
23  //
24  //Author: Fons Rademakers, Philippe Canal
25 
26  gBenchmark->Start("treeClient");
27 
28  TParallelMergingFile *file = (TParallelMergingFile*)TFile::Open("mergedClient.root?pmerge=localhost:1095","RECREATE");
29 
30  file->Write();
31  file->UploadAndReset(); // We do this early to get assigned an index.
32  UInt_t idx = file->fServerIdx; // This works on in ACLiC.
33 
34  TH1 *hpx;
35  if (idx%2 == 0) {
36  // Create the histogram
37  hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
38  hpx->SetFillColor(48); // set nice fillcolor
39  } else {
40  hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
41  }
42  Float_t px, py;
43  TTree *tree = new TTree("tree","tree");
44  tree->SetAutoFlush(4000000);
45  tree->Branch("px",&px);
46  tree->Branch("py",&py);
47 
48  // Fill histogram randomly
49  gRandom->SetSeed();
50  const int kUPDATE = 1000000;
51  for (int i = 0; i < 25000000; ) {
52  gRandom->Rannor(px,py);
53  if (idx%2 == 0)
54  hpx->Fill(px);
55  else
56  hpx->Fill(px,py);
57  tree->Fill();
58  ++i;
59  if (i && (i%kUPDATE) == 0) {
60  file->Write();
61  }
62  }
63  file->Write();
64  delete file;
65 
66  gBenchmark->Show("treeClient");
67 }
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 Fill()
Fill all branches.
Definition: TTree.cxx:4306
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
Float_t py
Definition: hprod.C:33
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3851
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
virtual void SetAutoFlush(Long64_t autof=-30000000)
This function may be called at the start of a program to change the default value for fAutoFlush...
Definition: TTree.cxx:7382
void parallelMergeClient()
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
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t UploadAndReset()
Upload the current file data to the merging server.
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
tuple tree
Definition: tree.py:24
tuple file
Definition: fildir.py:20
The TH1 histogram class.
Definition: TH1.h:80
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file and upload them to the parallel merge server.
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
Definition: TTree.cxx:1623
Float_t px
Definition: hprod.C:33
A TTree object has a header with a name and a title.
Definition: TTree.h:98
TH1F * hpx
Definition: hcons.C:32