Logo ROOT   6.14/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 "TString.h"
12 #include "TROOT.h"
13 #include "TChain.h"
14 #include "TFileCollection.h"
15 #include "TH1F.h"
16 #include "TTreeReader.h"
18 
19 const char *fh1[] = {"http://root.cern.ch/files/h1/dstarmb.root", "http://root.cern.ch/files/h1/dstarp1a.root",
20  "http://root.cern.ch/files/h1/dstarp1b.root", "http://root.cern.ch/files/h1/dstarp2.root"};
21 
22 int mp103_processSelector()
23 {
24 
25  // MacOSX may generate connection to WindowServer errors
26  gROOT->SetBatch(kTRUE);
27 
28  TString selectorPath = gROOT->GetTutorialDir();
29  selectorPath += "/tree/h1analysis.C+";
30  std::cout << "selector used is: " << selectorPath << "\n";
31  TSelector *sel = TSelector::GetSelector(selectorPath);
32 
33 // The following code generates a crash when Davix is used for HTTP
34 // Davix does not seem fork-safe; the problem has been reported to the
35 // Davix developers. For the time being we disable this part.
36 // To repoduce the problem, uncomment the next line.
37 //
38 // #define __reproduce_davix
39 #if defined(__reproduce_davix)
40  TFile *fp = TFile::Open(fh1[0]);
41  TTree *tree = (TTree *)fp->Get("h42");
42 #endif
43 
44  ROOT::TTreeProcessorMP pool(3);
45 
46  TList *out = nullptr;
47 #if defined(__reproduce_davix)
48  // TTreeProcessorMP::Process with a single tree
49  out = pool.Process(*tree, *sel);
50  sel->GetOutputList()->Delete();
51 #endif
52 
53  // TTreeProcessorMP::Process with single file name and tree name
54  // Note: we have less files than workers here
55  out = pool.Process(fh1[0], *sel, "h42");
56  sel->GetOutputList()->Delete();
57 
58  // Prepare datasets: vector of files, TFileCollection
59  TChain ch;
61  std::vector<std::string> files;
62  for (int i = 0; i < 4; i++) {
63  files.push_back(fh1[i]);
64  fc.Add(new TFileInfo(fh1[i]));
65  ch.Add(fh1[i]);
66  }
67 
68  // TTreeProcessorMP::Process with vector of files and tree name
69  // Note: we have more files than workers here (different behaviour)
70  out = pool.Process(files, *sel, "h42");
71  sel->GetOutputList()->Delete();
72 
73  // TTreeProcessorMP::Process with TFileCollection, no tree name
74  out = pool.Process(fc, *sel);
75  sel->GetOutputList()->Delete();
76 
77  // TTreeProcessorMP::Process with TChain, no tree name
78  out = pool.Process(ch, *sel);
79  sel->GetOutputList()->Delete();
80 
81  return 0;
82 }
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:410
Basic string class.
Definition: TString.h:131
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3976
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:3352
This class provides an interface to process a TTree dataset in parallel with multi-process technology...
A doubly linked list.
Definition: TList.h:44
Int_t Add(TFileInfo *info)
Add TFileInfo to the collection.
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
Class that contains a list of TFileInfo&#39;s and accumulated meta data information about its entries...
A chain is a collection of files containing TTree objects.
Definition: TChain.h:33
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:70
Class describing a generic file including meta information.
Definition: TFileInfo.h:38
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition: TSelector.h:33
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual TList * GetOutputList() const
Definition: TSelector.h:71
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition: TChain.cxx:222