Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
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 parallelMergeServer.C
10/// - Execute in the other windows: root.exe -b -l -q .x 'parallelMergeClient.C("<socket path printed by server>")'
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"
25#include "TRandom.h"
26#include "TError.h"
27
28#include <string>
29
30void parallelMergeClient(const std::string &socketPath)
31{
32 gBenchmark->Start("treeClient");
33
35 (TParallelMergingFile *)TFile::Open((std::string("mergedClient.root?pmerge=") + socketPath).c_str(), "RECREATE");
36
37 file->Write();
38 file->UploadAndReset(); // We do this early to get assigned an index.
39 UInt_t idx = file->GetServerIdx();
40
41 TH1 *hpx;
42 if (idx%2 == 0) {
43 // Create the histogram
44 hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
45 hpx->SetFillColor(48); // set nice fill-color
46 } else {
47 hpx = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
48 }
49 Float_t px, py;
50 TTree *tree = new TTree("tree","tree");
51 tree->SetAutoFlush(4000000);
52 tree->Branch("px",&px);
53 tree->Branch("py",&py);
54
55 // Fill histogram randomly
57 const int kUPDATE = 1000000;
58 for (int i = 0; i < 25000000; ) {
59 gRandom->Rannor(px,py);
60 if (idx%2 == 0)
61 hpx->Fill(px);
62 else
63 hpx->Fill(px,py);
64 tree->Fill();
65 ++i;
66 if (i && (i%kUPDATE) == 0) {
67 file->Write();
68 }
69 }
70 file->Write();
71 delete file;
72
73 gBenchmark->Show("treeClient");
74}
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
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.
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.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4094
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
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
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) override
Write memory objects to this file and upload them to the parallel merge server.
Bool_t UploadAndReset()
Upload the current file data to the merging server.
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
A TTree represents a columnar dataset.
Definition TTree.h:79