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 "TString.h"
12#include "TROOT.h"
13#include "TChain.h"
14#include "TBranch.h"
15#include "TFileCollection.h"
16#include "TH1F.h"
17#include "TTreeReader.h"
19
20#include <memory>
21
22const auto file0 = "http://root.cern.ch/files/h1/dstarmb.root";
23const std::vector<std::string> files = {file0,
24 "http://root.cern.ch/files/h1/dstarp1a.root",
25 "http://root.cern.ch/files/h1/dstarp1b.root",
26 "http://root.cern.ch/files/h1/dstarp2.root"};
27
28int mp103_processSelector()
29{
30
31 // MacOSX may generate connection to WindowServer errors
32 gROOT->SetBatch(kTRUE);
33
34 TString selectorPath = gROOT->GetTutorialDir();
35 selectorPath += "/tree/h1analysis.C+";
36 std::cout << "selector used is: " << selectorPath << "\n";
37 auto sel = TSelector::GetSelector(selectorPath);
38
39// The following code generates a crash when Davix is used for HTTP
40// Davix does not seem fork-safe; the problem has been reported to the
41// Davix developers. For the time being we disable this part.
42// To repoduce the problem, uncomment the next line.
43//
44// #define __reproduce_davix
45#if defined(__reproduce_davix)
46 auto fp = std::make_unique<TTree>(TFile::Open(file0));
47 auto tree = fp->Get<TTree>("h42");
48#endif
49
51
52 TList *out = nullptr;
53#if defined(__reproduce_davix)
54 // TTreeProcessorMP::Process with a single tree
55 out = pool.Process(*tree, *sel);
56 sel->GetOutputList()->Delete();
57#endif
58
59 // TTreeProcessorMP::Process with single file name and tree name
60 // Note: we have less files than workers here
61 out = pool.Process(file0, *sel, "h42");
62 sel->GetOutputList()->Delete();
63
64 // Prepare datasets: vector of files, TFileCollection
65 TChain ch;
67 for (auto &&file : files) {
68 fc.Add(new TFileInfo(file.c_str()));
69 ch.Add(file.c_str());
70 }
71
72 // TTreeProcessorMP::Process with vector of files and tree name
73 // Note: we have more files than workers here (different behaviour)
74 out = pool.Process(files, *sel, "h42");
75 sel->GetOutputList()->Delete();
76
77 // TTreeProcessorMP::Process with TFileCollection, no tree name
78 out = pool.Process(fc, *sel);
79 sel->GetOutputList()->Delete();
80
81 // TTreeProcessorMP::Process with TChain, no tree name
82 out = pool.Process(ch, *sel);
83 sel->GetOutputList()->Delete();
84
85 return 0;
86}
const Bool_t kTRUE
Definition: RtypesCore.h:100
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
#define gROOT
Definition: TROOT.h:404
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:33
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition: TChain.cxx:218
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Int_t Add(TFileInfo *info)
Add TFileInfo to the collection.
Class describing a generic file including meta information.
Definition: TFileInfo.h:39
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:4053
A doubly linked list.
Definition: TList.h:38
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:136
A TTree represents a columnar dataset.
Definition: TTree.h:79
Definition: file.py:1
Definition: tree.py:1