Logo ROOT   6.07/09
Reference Guide
parallelMergeClient.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_net
3 /// Client program which creates and fills 2 histograms and a TTree.
4 /// Every 1000000 fills the histograms and TTree is send to the server which displays the histogram.
5 ///
6 /// To run this demo do the following:
7 /// - Open at least 2 windows
8 /// - Start ROOT in the first windows
9 /// - Execute in the first window: .x fastMergeServer.C
10 /// - Execute in the other windows: root.exe -b -l -q .x treeClient.C
11 /// (You can put it in the background if wanted).
12 /// If you want to run the hserv.C on a different host, just change
13 /// "localhost" in the TSocket ctor below to the desired hostname.
14 ///
15 /// \macro_code
16 ///
17 /// \authors Fons Rademakers, Philippe Canal
18 
19 #include "TMessage.h"
20 #include "TBenchmark.h"
21 #include "TSocket.h"
22 #include "TH2.h"
23 #include "TTree.h"
24 #include "TParallelMergingFile.h"
25 #include "TRandom.h"
26 #include "TError.h"
27 
28 void parallelMergeClient()
29 {
30  gBenchmark->Start("treeClient");
31 
32  TParallelMergingFile *file = (TParallelMergingFile*)TFile::Open("mergedClient.root?pmerge=localhost:1095","RECREATE");
33 
34  file->Write();
35  file->UploadAndReset(); // We do this early to get assigned an index.
36  UInt_t idx = file->fServerIdx; // This works on in ACLiC.
37 
38  TH1 *hpx;
39  if (idx%2 == 0) {
40  // Create the histogram
41  hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
42  hpx->SetFillColor(48); // set nice fill-color
43  } else {
44  hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
45  }
46  Float_t px, py;
47  TTree *tree = new TTree("tree","tree");
48  tree->SetAutoFlush(4000000);
49  tree->Branch("px",&px);
50  tree->Branch("py",&py);
51 
52  // Fill histogram randomly
53  gRandom->SetSeed();
54  const int kUPDATE = 1000000;
55  for (int i = 0; i < 25000000; ) {
56  gRandom->Rannor(px,py);
57  if (idx%2 == 0)
58  hpx->Fill(px);
59  else
60  hpx->Fill(px,py);
61  tree->Fill();
62  ++i;
63  if (i && (i%kUPDATE) == 0) {
64  file->Write();
65  }
66  }
67  file->Write();
68  delete file;
69 
70  gBenchmark->Show("treeClient");
71 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3127
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:4374
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:157
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:3871
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:174
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:7591
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
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:66
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:1651
Definition: file.py:1
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:98
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308