Logo ROOT   6.08/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 /// \author Anda Chelba
10 /// \author Gerardo Ganis
11 
12 #include "TString.h"
13 #include "TROOT.h"
14 #include "TTree.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->GetTutorialsDir();
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::TProcessExecutor pool(3);
46 
47  TList* out = 0;
48 #if defined(__reproduce_davix)
49  //TProcessExecutor::Process with a single tree
50  out = pool.ProcTree(*tree, *sel);;
51  sel->GetOutputList()->Delete();
52 #endif
53 
54  //TProcessExecutor::Process with single file name and tree name
55  //Note: we have less files than workers here
56  out = pool.ProcTree(fh1[0], *sel, "h1");
57  sel->GetOutputList()->Delete();
58 
59  // Prepare datasets: vector of files, TFileCollection
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  }
66 
67  //TProcessExecutor::Process with vector of files and tree name
68  //Note: we have more files than workers here (different behaviour)
69  out = pool.ProcTree(files, *sel, "h1");
70  sel->GetOutputList()->Delete();
71 
72  //TProcessExecutor::Process with TFileCollection, no tree name
73  out = pool.ProcTree(fc, *sel);
74  sel->GetOutputList()->Delete();
75 
76  return 0;
77 }
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
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:3907
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:1956
A doubly linked list.
Definition: TList.h:47
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...
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:98
Class describing a generic file including meta information.
Definition: TFileInfo.h:50
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition: TSelector.h:39
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual TList * GetOutputList() const
Definition: TSelector.h:76