Logo ROOT   6.14/05
Reference Guide
mp105_processEntryList.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook -nodraw
4 /// Illustrate the usage of the multiproc to process TEntryList with the H1 analysis
5 /// example.
6 ///
7 /// \macro_code
8 ///
9 /// \author Gerardo Ganis
10 
11 #include "TString.h"
12 #include "TROOT.h"
13 #include "TTree.h"
14 #include "TH1F.h"
15 #include "TH2F.h"
16 #include "TEntryList.h"
17 #include "TTreeReader.h"
18 #include "TTreeReaderArray.h"
19 #include "TTreeReaderValue.h"
20 #include "TSystem.h"
21 #include "TMath.h"
22 #include "TCanvas.h"
23 #include "TStyle.h"
24 #include "TF1.h"
25 #include "TLine.h"
26 #include "TPaveStats.h"
27 #include "TStopwatch.h"
29 
30 static std::string tutname = "mp105_processEntryList: ";
31 static std::string logfile = "mp105_processEntryList.log";
32 static RedirectHandle_t gRH;
33 
34 const char *fh1[] = {"http://root.cern.ch/files/h1/dstarmb.root", "http://root.cern.ch/files/h1/dstarp1a.root",
35  "http://root.cern.ch/files/h1/dstarp1b.root", "http://root.cern.ch/files/h1/dstarp2.root"};
36 
37 int mp105_processEntryList()
38 {
39 
40  // MacOSX may generate connection to WindowServer errors
41  gROOT->SetBatch(kTRUE);
42 
43  TStopwatch stp;
44 
45  // Prepare dataset: vector of files
46  std::vector<std::string> files;
47  for (int i = 0; i < 4; i++) {
48  files.push_back(fh1[i]);
49  }
50 
51 #include "mp_H1_lambdas.C"
52 
53  ROOT::TTreeProcessorMP pool(3);
54 
55  std::cout << tutname << "creating the entry list \n";
56 
57  auto sumElist = pool.Process(files, doH1fillList, "h42");
58 
59  // Print the entry list
60  if (sumElist) {
61  sumElist->Print();
62  } else {
63  std::cout << tutname << " ERROR creating the entry list \n";
64  return -1;
65  }
66 
67  // Time taken
68  stp.Print();
69  stp.Start();
70 
71  // Let's analyse H1 with the list
72  std::cout << tutname << "processing the entry list with a lambda \n";
73 
74  // Run the analysis
75  auto hListFun = pool.Process(files, doH1useList, *sumElist, "h42");
76 
77  // Check the output
78  if (checkH1(hListFun) < 0)
79  return -1;
80 
81  // Do the fit
82  if (doFit(hListFun, logfile.c_str()) < 0)
83  return -1;
84 
85  stp.Print();
86  stp.Start();
87 
88  // Run the analysis with a selector
89  TString selectorPath = gROOT->GetTutorialDir();
90  selectorPath += "/tree/h1analysisTreeReader.C+";
91  std::cout << tutname << "processing the entry list with selector '" << selectorPath << "'\n";
92  TSelector *sel = TSelector::GetSelector(selectorPath);
93 
94  // In a second run we use sel
95  sel->SetOption("useList");
96  gSystem->RedirectOutput(logfile.c_str(), "w", &gRH);
97  auto hListSel = pool.Process(files, *sel, *sumElist, "h42");
98  gSystem->RedirectOutput(0, 0, &gRH);
99 
100  // Check the output
101  if (checkH1(hListSel) < 0)
102  return -1;
103 
104  // Do the fit
105  if (doFit(hListSel, logfile.c_str()) < 0)
106  return -1;
107 
108  stp.Print();
109  stp.Start();
110 
111  return 0;
112 }
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:219
#define gROOT
Definition: TROOT.h:410
Basic string class.
Definition: TString.h:131
<a href="http://nbviewer.jupyter.org/url/root.cern.ch/doc/master/notebooks/mp_H1_lambdas.C.nbconvert.ipynb" target="_blank"><img src= notebook.gif alt="View in nbviewer" style="height:1em" ></a> <a href="https://cern.ch/swanserver/cgi-bin/go?projurl=https://root.cern.ch/doc/master/notebooks/mp_H1_lambdas.C.nbconvert.ipynb" target="_blank"><img src="http://swanserver.web.cern.ch/swanserver/images/badge_swan_white_150.png" alt="Open in SWAN" style="height:1em" ></a> Lambdas used to check and fit the result of the H1 analysis.
This class provides an interface to process a TTree dataset in parallel with multi-process technology...
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
static TSelector * GetSelector(const char *filename)
The code in filename is loaded (interpreted or compiled, see below), filename must contain a valid cl...
Definition: TSelector.cxx:142
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
Definition: TSystem.cxx:1688
virtual void SetOption(const char *option)
Definition: TSelector.h:66
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition: TSelector.h:33
const Bool_t kTRUE
Definition: RtypesCore.h:87
Stopwatch class.
Definition: TStopwatch.h:28