AliRoot Core  3dc7879 (3dc7879)
AliAnalysisSelector.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 #include <Riostream.h>
17 #include <TProcessID.h>
18 #include <TROOT.h>
19 
20 #include "AliAnalysisManager.h"
21 #include "AliAnalysisTask.h"
23 #include "AliAnalysisSelector.h"
24 
25 using std::cout;
26 using std::endl;
27 ClassImp(AliAnalysisSelector)
28 
29 //______________________________________________________________________________
31  :TSelector(),
32  fInitialized(kFALSE),
33  fAnalysis(NULL)
34 {
35 // Dummy ctor.
37  if (fAnalysis) fAnalysis->SetSelector(this);
38 }
39 
40 //______________________________________________________________________________
42  :TSelector(),
43  fInitialized(kFALSE),
44  fAnalysis(mgr)
45 {
48 
49  mgr->SetSelector(this);
50 }
51 
52 //______________________________________________________________________________
54 {
58 
59 }
60 
61 //______________________________________________________________________________
63 {
66 
67  if (!fAnalysis) {
68  Error("Init", "Analysis manager NULL !");
69  Abort("Cannot initialize without analysis manager. Aborting.");
70  SetStatus(-1);
71  return;
72  }
73  if (fAnalysis->GetDebugLevel()>1) {
74  cout << "->AliAnalysisSelector->Init()" << endl;
75  }
76  if (!tree) {
77  Error("Init", "Input tree is NULL !");
78  Abort("Cannot initialize without tree. Aborting.");
79  SetStatus(-1);
80  return;
81  }
82  fInitialized = fAnalysis->Init(tree);
83  if (!fInitialized) {
84  Error("Init", "Some error occured during analysis manager initialization. Aborting.");
85  Abort("Error during AliAnalysisManager::Init()");
86  SetStatus(-1);
87  return;
88  }
89  if (fAnalysis->GetDebugLevel()>1) {
90  cout << "<-AliAnalysisSelector->Init()" << endl;
91  }
92 }
93 
94 //______________________________________________________________________________
96 {
98 
100  if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
101  cout << "->AliAnalysisSelector->Begin: Analysis manager restored" << endl;
102  gROOT->SetMustClean(fAnalysis->MustClean());
103  }
104 }
105 
106 //______________________________________________________________________________
108 {
110 
112  if (fAnalysis) {
113  gROOT->SetMustClean(fAnalysis->MustClean());
114  if (fAnalysis->GetDebugLevel()>1) {
115  cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl;
116  }
117  fAnalysis->SlaveBegin(tree);
118  if (fAnalysis->GetDebugLevel()>1) {
119  cout << "<-AliAnalysisSelector->SlaveBegin()" << endl;
120  }
121  }
122 }
123 
124 //______________________________________________________________________________
126 {
132 
133  if (fAnalysis) return fAnalysis->Notify();
134  return kFALSE;
135 }
136 
137 //______________________________________________________________________________
138 Bool_t AliAnalysisSelector::Process(Long64_t entry)
139 {
141 
142  static Int_t count = 0;
143  count++;
144  if (fAnalysis->GetDebugLevel() > 1) {
145  cout << "->AliAnalysisSelector::Process()" << endl;
146  }
147  static Bool_t init=kTRUE;
148  static Int_t nobjCount = 0;
149  if(init) {
150  nobjCount = TProcessID::GetObjectCount();
151  init=kFALSE;
152  }
153  TProcessID::SetObjectCount(nobjCount);
154  Int_t returnCode = fAnalysis->GetEntry(entry);
155  if (returnCode <= 0) {
156  cout << "Error retrieving event:" << entry << " Skipping ..." << endl;
157  fAnalysis->CountEvent(1,0,1,0);
158  // Try to skip file
159  Abort("Bad stream to file. Trying next image.", kAbortFile);
160  return kFALSE;
161  } else {
163  fAnalysis->CountEvent(1,1,0,0);
164  }
165  if (fAnalysis->GetDebugLevel() > 1) {
166  cout << "<-AliAnalysisSelector::Process()" << endl;
167  }
168  return kTRUE;
169 }
170 
171 //______________________________________________________________________________
173 {
175 
176  if (!fAnalysis) {
177  TIter next(fInput);
178  TObject *obj;
179  while ((obj=next())) {
180  if (obj->IsA() == AliAnalysisManager::Class()) {
182  fAnalysis->SetSelector(this);
183  if (fAnalysis->GetDebugLevel()>1) {
184  cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
185  }
186  break;
187  }
188  }
189  if (!fAnalysis) {
190  Error("SlaveBegin", "Analysis manager not found in the input list");
191  return;
192  }
193  }
194 }
195 
196 //______________________________________________________________________________
198 {
202 
203  gROOT->SetMustClean(kTRUE);
204  if (fStatus == -1) return; // TSelector won't abort...
206  if (fAnalysis->GetDebugLevel() > 1) {
207  cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
208  }
209  fAnalysis->PackOutput(fOutput);
210  if (fAnalysis->GetDebugLevel() > 1) {
211  cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
212  }
213 }
214 
215 //______________________________________________________________________________
217 {
221 
222  gROOT->SetMustClean(kTRUE);
223  if (fStatus == -1) return; // TSelector won't abort...
224  if (!fAnalysis) {
225  Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!");
226  return;
227  }
228  // No Terminate() in case of event mixing
230  if (fAnalysis->GetDebugLevel() > 1) {
231  cout << "->AliAnalysisSelector::Terminate()" << endl;
232  }
233  fAnalysis->UnpackOutput(fOutput);
234  fAnalysis->Terminate();
235  if (fAnalysis->GetDebugLevel() > 1) {
236  cout << "<-AliAnalysisSelector::Terminate()" << endl;
237  }
238 }
void SetSelector(AliAnalysisSelector *const sel)
static AliAnalysisManager * GetAnalysisManager()
AliAnalysysManager Manager analysis class. Allows creation of several analysis tasks and data contain...
virtual Bool_t Init(TTree *tree)
TROOT * gROOT
virtual void SlaveBegin(TTree *tree)
void UnpackOutput(TList *source)
AliAnalysisManager * fAnalysis
Analysis manager to be processed.
virtual Bool_t Process(Long64_t entry)
UInt_t GetDebugLevel() const
EAliAnalysisExecMode GetAnalysisType() const
bool init
Definition: XSection.C:263
TTree * tree
virtual void SlaveBegin(TTree *tree)
void PackOutput(TList *target)
virtual Bool_t Notify()
AliAnalysisSelector Transparent selector class instantiated by an analysis manager object...
void ExecAnalysis(Option_t *option="")
virtual void Begin(TTree *)
mgr
Definition: runKineProof.C:24
virtual void Init(TTree *tree)
Bool_t MustClean() const
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Bool_t fInitialized
Flag that initialization was done.
void CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted)