Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
mp103_processSelector.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook -nodraw
4 /// Illustrate the usage of the multiproc TSelector interfaces with the h1 analysis
5 /// example.
6 ///
7 /// \macro_code
8 ///
9 /// \authors Anda Chelba, Gerardo Ganis
10 
11 #include "ROOT/RMakeUnique.hxx"
12 #include "TString.h"
13 #include "TROOT.h"
14 #include "TChain.h"
15 #include "TFileCollection.h"
16 #include "TH1F.h"
17 #include "TTreeReader.h"
19 
20 const auto file0 = "http://root.cern.ch/files/h1/dstarmb.root";
21 const std::vector<std::string> files = {file0,
22  "http://root.cern.ch/files/h1/dstarp1a.root",
23  "http://root.cern.ch/files/h1/dstarp1b.root",
24  "http://root.cern.ch/files/h1/dstarp2.root"};
25 
26 int mp103_processSelector()
27 {
28 
29  // MacOSX may generate connection to WindowServer errors
30  gROOT->SetBatch(kTRUE);
31 
32  TString selectorPath = gROOT->GetTutorialDir();
33  selectorPath += "/tree/h1analysis.C+";
34  std::cout << "selector used is: " << selectorPath << "\n";
35  auto sel = TSelector::GetSelector(selectorPath);
36 
37 // The following code generates a crash when Davix is used for HTTP
38 // Davix does not seem fork-safe; the problem has been reported to the
39 // Davix developers. For the time being we disable this part.
40 // To repoduce the problem, uncomment the next line.
41 //
42 // #define __reproduce_davix
43 #if defined(__reproduce_davix)
44  auto fp = std::make_unique<TTree>(TFile::Open(file0));
45  auto tree = fp->Get<TTree>("h42");
46 #endif
47 
48  ROOT::TTreeProcessorMP pool(3);
49 
50  TList *out = nullptr;
51 #if defined(__reproduce_davix)
52  // TTreeProcessorMP::Process with a single tree
53  out = pool.Process(*tree, *sel);
54  sel->GetOutputList()->Delete();
55 #endif
56 
57  // TTreeProcessorMP::Process with single file name and tree name
58  // Note: we have less files than workers here
59  out = pool.Process(file0, *sel, "h42");
60  sel->GetOutputList()->Delete();
61 
62  // Prepare datasets: vector of files, TFileCollection
63  TChain ch;
64  TFileCollection fc;
65  for (auto &&file : files) {
66  fc.Add(new TFileInfo(file.c_str()));
67  ch.Add(file.c_str());
68  }
69 
70  // TTreeProcessorMP::Process with vector of files and tree name
71  // Note: we have more files than workers here (different behaviour)
72  out = pool.Process(files, *sel, "h42");
73  sel->GetOutputList()->Delete();
74 
75  // TTreeProcessorMP::Process with TFileCollection, no tree name
76  out = pool.Process(fc, *sel);
77  sel->GetOutputList()->Delete();
78 
79  // TTreeProcessorMP::Process with TChain, no tree name
80  out = pool.Process(ch, *sel);
81  sel->GetOutputList()->Delete();
82 
83  return 0;
84 }