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
21const auto file0 = "http://root.cern.ch/files/h1/dstarmb.root";
22const 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
27int 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
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}
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define gROOT
Definition: TROOT.h:406
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:3728
This class provides an interface to process a TTree dataset in parallel with multi-process technology...
A chain is a collection of files containing TTree objects.
Definition: TChain.h:34
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition: TChain.cxx:226
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Class describing a generic file including meta information.
Definition: TFileInfo.h:36
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:3942
A doubly linked list.
Definition: TList.h:44
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
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
Basic string class.
Definition: TString.h:131
A TTree represents a columnar dataset.
Definition: TTree.h:78
Definition: file.py:1
Definition: tree.py:1