Logo ROOT  
Reference Guide
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 "TBranch.h"
16 #include "TFileCollection.h"
17 #include "TH1F.h"
18 #include "TTreeReader.h"
20 
21 const auto file0 = "http://root.cern.ch/files/h1/dstarmb.root";
22 const std::vector<std::string> files = {file0,
23  "http://root.cern.ch/files/h1/dstarp1a.root",
24  "http://root.cern.ch/files/h1/dstarp1b.root",
25  "http://root.cern.ch/files/h1/dstarp2.root"};
26 
27 int mp103_processSelector()
28 {
29 
30  // MacOSX may generate connection to WindowServer errors
31  gROOT->SetBatch(kTRUE);
32 
33  TString selectorPath = gROOT->GetTutorialDir();
34  selectorPath += "/tree/h1analysis.C+";
35  std::cout << "selector used is: " << selectorPath << "\n";
36  auto sel = TSelector::GetSelector(selectorPath);
37 
38 // The following code generates a crash when Davix is used for HTTP
39 // Davix does not seem fork-safe; the problem has been reported to the
40 // Davix developers. For the time being we disable this part.
41 // To repoduce the problem, uncomment the next line.
42 //
43 // #define __reproduce_davix
44 #if defined(__reproduce_davix)
45  auto fp = std::make_unique<TTree>(TFile::Open(file0));
46  auto tree = fp->Get<TTree>("h42");
47 #endif
48 
49  ROOT::TTreeProcessorMP pool(3);
50 
51  TList *out = nullptr;
52 #if defined(__reproduce_davix)
53  // TTreeProcessorMP::Process with a single tree
54  out = pool.Process(*tree, *sel);
55  sel->GetOutputList()->Delete();
56 #endif
57 
58  // TTreeProcessorMP::Process with single file name and tree name
59  // Note: we have less files than workers here
60  out = pool.Process(file0, *sel, "h42");
61  sel->GetOutputList()->Delete();
62 
63  // Prepare datasets: vector of files, TFileCollection
64  TChain ch;
66  for (auto &&file : files) {
67  fc.Add(new TFileInfo(file.c_str()));
68  ch.Add(file.c_str());
69  }
70 
71  // TTreeProcessorMP::Process with vector of files and tree name
72  // Note: we have more files than workers here (different behaviour)
73  out = pool.Process(files, *sel, "h42");
74  sel->GetOutputList()->Delete();
75 
76  // TTreeProcessorMP::Process with TFileCollection, no tree name
77  out = pool.Process(fc, *sel);
78  sel->GetOutputList()->Delete();
79 
80  // TTreeProcessorMP::Process with TChain, no tree name
81  out = pool.Process(ch, *sel);
82  sel->GetOutputList()->Delete();
83 
84  return 0;
85 }
TFileInfo
Class describing a generic file including meta information.
Definition: TFileInfo.h:39
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TH1F.h
fc
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:3728
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
tree
Definition: tree.py:1
TSelector::GetSelector
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
TBranch.h
TChain::Add
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition: TChain.cxx:229
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
TTreeProcessorMP.hxx
TFile::Open
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:3997
ROOT::TTreeProcessorMP
This class provides an interface to process a TTree dataset in parallel with multi-process technology...
Definition: TTreeProcessorMP.hxx:38
TString
Basic string class.
Definition: TString.h:136
TString.h
TROOT.h
TChain.h
TTreeReader.h
TFileCollection.h
file
Definition: file.py:1
TChain
A chain is a collection of files containing TTree objects.
Definition: TChain.h:33
RMakeUnique.hxx
TList
A doubly linked list.
Definition: TList.h:44
gROOT
#define gROOT
Definition: TROOT.h:406
TFileCollection
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Definition: TFileCollection.h:39