Logo ROOT   6.07/09
Reference Guide
parallelMergeTest.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_net
3 ///
4 /// \macro_code
5 ///
6 /// \author
7 
8 #include "TMessage.h"
9 #include "TBenchmark.h"
10 #include "TSocket.h"
11 #include "TH2.h"
12 #include "TTree.h"
13 #include "TFile.h"
14 #include "TRandom.h"
15 #include "TError.h"
16 
17 void parallelMergeTest(UInt_t nhist, UInt_t ndims = 1, UInt_t nbins = 100)
18 {
19 
20  gBenchmark->Start("parallelMergeTest");
21 
22  TFile *file = TFile::Open("mergedClient.root?pmerge=localhost:1095","RECREATE");
23 
24  Float_t px, py;
25  TTree *tree = 0;
26  switch (ndims) {
27  case 1: {
28  for(UInt_t h = 0 ; h < nhist; ++h) {
29  new TH1F(TString::Format("hpx%d",h),"This is the px distribution",nbins,-4,4);
30  }
31  break;
32  }
33  case 2: {
34  for(UInt_t h = 0 ; h < nhist; ++h) {
35  new TH2F(TString::Format("hpxy%d",h),"py vs px",nbins,-4,4,nbins,-4,-4);
36  }
37  break;
38  }
39  case 99: {
40  tree = new TTree("tree","tree");
41  tree->SetAutoFlush(4000000);
42  tree->Branch("px",&px);
43  tree->Branch("py",&py);
44  }
45  }
46 
47  // Fill histogram randomly
48  gRandom->SetSeed();
49  const int kUPDATE = 1000000;
50  for (int i = 0; i < 25000000; ) {
51 // gRandom->Rannor(px,py);
52 // if (idx%2 == 0)
53 // hpx->Fill(px);
54 // else
55 // hpx->Fill(px,py);
56  if(tree) tree->Fill();
57  ++i;
58  if (i && (i%kUPDATE) == 0) {
59  file->Write();
60  }
61  }
62  file->Write();
63  delete file;
64 
65  gBenchmark->Show("parallelMergeTest");
66 }
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
TH1 * h
Definition: legend2.C:5
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:157
int nbins[3]
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
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
Definition: TFile.cxx:2268
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
unsigned int UInt_t
Definition: RtypesCore.h:42
R__EXTERN TRandom * gRandom
Definition: TRandom.h:66
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