Logo ROOT   6.18/05
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 "TFileCollection.h"
16#include "TH1F.h"
17#include "TTreeReader.h"
19
20const auto file0 = "http://root.cern.ch/files/h1/dstarmb.root";
21const 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
26int 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
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;
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}
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define gROOT
Definition: TROOT.h:414
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:223
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:38
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3980
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:467
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:71
Definition: file.py:1
Definition: tree.py:1