Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
mp_processSelector.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Illustrate the usage of the multiprocessing TTreeProcessorMP and TSelector interfaces with the h1analysis.C example.

#include "TString.h"
#include "TROOT.h"
#include "TChain.h"
#include "TBranch.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include <memory>
const auto file0 = "root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root";
const std::vector<std::string> files = {file0,
"root://eospublic.cern.ch//eos/root-eos/h1/dstarp1a.root",
"root://eospublic.cern.ch//eos/root-eos/h1/dstarp1b.root",
"root://eospublic.cern.ch//eos/root-eos/h1/dstarp2.root"};
int mp_processSelector()
{
// MacOSX may generate connection to WindowServer errors
gROOT->SetBatch(kTRUE);
TString selectorPath = gROOT->GetTutorialDir();
selectorPath += "/analysis/tree/h1analysis.C+";
std::cout << "selector used is: " << selectorPath << "\n";
auto sel = TSelector::GetSelector(selectorPath);
// The following code generates a crash when Davix is used for HTTP
// Davix does not seem fork-safe; the problem has been reported to the
// Davix developers. For the time being we disable this part.
// To repoduce the problem, uncomment the next line.
//
// #define __reproduce_davix
#if defined(__reproduce_davix)
auto fp = std::make_unique<TTree>(TFile::Open(file0));
auto tree = fp->Get<TTree>("h42");
#endif
TList *out = nullptr;
#if defined(__reproduce_davix)
// TTreeProcessorMP::Process with a single tree
out = pool.Process(*tree, *sel);
sel->GetOutputList()->Delete();
#endif
// TTreeProcessorMP::Process with single file name and tree name
// Note: we have less files than workers here
out = pool.Process(file0, *sel, "h42");
sel->GetOutputList()->Delete();
// Prepare datasets: vector of files, TFileCollection
TChain ch;
for (auto &&file : files) {
fc.Add(new TFileInfo(file.c_str()));
ch.Add(file.c_str());
}
// TTreeProcessorMP::Process with vector of files and tree name
// Note: we have more files than workers here (different behaviour)
out = pool.Process(files, *sel, "h42");
sel->GetOutputList()->Delete();
// TTreeProcessorMP::Process with TFileCollection, no tree name
out = pool.Process(fc, *sel);
sel->GetOutputList()->Delete();
// TTreeProcessorMP::Process with TChain, no tree name
out = pool.Process(ch, *sel);
sel->GetOutputList()->Delete();
return 0;
}
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define gROOT
Definition TROOT.h:417
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:211
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:3787
A doubly linked list.
Definition TList.h:38
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
static TSelector * GetSelector(const char *filename)
The code in filename is loaded (interpreted or compiled, see below), filename must contain a valid cl...
Basic string class.
Definition TString.h:138
A TTree represents a columnar dataset.
Definition TTree.h:89
Authors
Anda Chelba, Gerardo Ganis

Definition in file mp_processSelector.C.