Logo ROOT   6.12/07
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",
20  "http://root.cern.ch/files/h1/dstarp1a.root",
21  "http://root.cern.ch/files/h1/dstarp1b.root",
22  "http://root.cern.ch/files/h1/dstarp2.root"};
23 
24 int mp103_processSelector(){
25 
26  // MacOSX may generate connection to WindowServer errors
27  gROOT->SetBatch(kTRUE);
28 
29  TString selectorPath = gROOT->GetTutorialDir();
30  selectorPath += "/tree/h1analysis.C+";
31  std::cout << "selector used is: "<< selectorPath<<"\n";
32  TSelector *sel = TSelector::GetSelector(selectorPath);
33 
34 // The following code generates a crash when Davix is used for HTTP
35 // Davix does not seem fork-safe; the problem has been reported to the
36 // Davix developers. For the time being we disable this part.
37 // To repoduce the problem, uncomment the next line.
38 //
39 // #define __reproduce_davix
40 #if defined(__reproduce_davix)
41  TFile *fp = TFile::Open(fh1[0]);
42  TTree *tree = (TTree *) fp->Get("h42");
43 #endif
44 
45  ROOT::TTreeProcessorMP pool(3);
46 
47  TList* out = 0;
48 #if defined(__reproduce_davix)
49  //TTreeProcessorMP::Process with a single tree
50  out = pool.Process(*tree, *sel);;
51  sel->GetOutputList()->Delete();
52 #endif
53 
54  //TTreeProcessorMP::Process with single file name and tree name
55  //Note: we have less files than workers here
56  out = pool.Process(fh1[0], *sel, "h42");
57  sel->GetOutputList()->Delete();
58 
59  // Prepare datasets: vector of files, TFileCollection
60  TChain ch;
62  std::vector<std::string> files;
63  for (int i = 0; i < 4; i++) {
64  files.push_back(fh1[i]);
65  fc.Add(new TFileInfo(fh1[i]));
66  ch.Add(fh1[i]);
67  }
68 
69  //TTreeProcessorMP::Process with vector of files and tree name
70  //Note: we have more files than workers here (different behaviour)
71  out = pool.Process(files, *sel, "h42");
72  sel->GetOutputList()->Delete();
73 
74  //TTreeProcessorMP::Process with TFileCollection, no tree name
75  out = pool.Process(fc, *sel);
76  sel->GetOutputList()->Delete();
77 
78  // TTreeProcessorMP::Process with TChain, no tree name
79  out = pool.Process(ch, *sel);
80  sel->GetOutputList()->Delete();
81 
82  return 0;
83 }
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:46
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:402
Basic string class.
Definition: TString.h:125
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:3950
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:1956
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:221