1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // Author: Andrei Gheata, 31/05/2006
19 //==============================================================================
20 // AliAnalysisSelector - A transparent selector to be created by
21 // AliAnalysisManager to handle analysis.
22 //==============================================================================
24 #include <Riostream.h>
25 #include <TProcessID.h>
28 #include "AliAnalysisManager.h"
29 #include "AliAnalysisTask.h"
30 #include "AliAnalysisDataContainer.h"
31 #include "AliAnalysisSelector.h"
33 ClassImp(AliAnalysisSelector)
35 //______________________________________________________________________________
36 AliAnalysisSelector::AliAnalysisSelector()
42 fAnalysis = AliAnalysisManager::GetAnalysisManager();
43 if (fAnalysis) fAnalysis->SetSelector(this);
46 //______________________________________________________________________________
47 AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
52 // Constructor. Called by AliAnalysisManager which registers itself on the
53 // selector running on the master.
54 mgr->SetSelector(this);
57 //______________________________________________________________________________
58 AliAnalysisSelector::~AliAnalysisSelector()
60 // Dtor. The analysis manager object is sent in the input list and duplicated
61 // on the workers - it needs to be deleted (?)
62 // if (fAnalysis) delete fAnalysis;
65 //______________________________________________________________________________
66 void AliAnalysisSelector::Init(TTree *tree)
68 // Called after Begin/SlaveBegin, assumes that fAnalysis is already initialized.
69 // Is Init called on workers in case of PROOF.
71 Error("Init", "Analysis manager NULL !");
72 Abort("Cannot initialize without analysis manager. Aborting.");
76 if (fAnalysis->GetDebugLevel()>1) {
77 cout << "->AliAnalysisSelector->Init()" << endl;
80 Error("Init", "Input tree is NULL !");
81 Abort("Cannot initialize without tree. Aborting.");
85 fInitialized = fAnalysis->Init(tree);
87 Error("Init", "Some error occured during analysis manager initialization. Aborting.");
88 Abort("Error during AliAnalysisManager::Init()");
92 if (fAnalysis->GetDebugLevel()>1) {
93 cout << "<-AliAnalysisSelector->Init()" << endl;
97 //______________________________________________________________________________
98 void AliAnalysisSelector::Begin(TTree *)
100 // Assembly the input list.
101 RestoreAnalysisManager();
102 if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
103 cout << "->AliAnalysisSelector->Begin: Analysis manager restored" << endl;
104 gROOT->SetMustClean(fAnalysis->MustClean());
108 //______________________________________________________________________________
109 void AliAnalysisSelector::SlaveBegin(TTree *tree)
111 // Called on each worker. We "unpack" analysis manager here and call InitAnalysis.
112 RestoreAnalysisManager();
114 gROOT->SetMustClean(fAnalysis->MustClean());
115 if (fAnalysis->GetDebugLevel()>1) {
116 cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl;
118 fAnalysis->SlaveBegin(tree);
119 if (fAnalysis->GetDebugLevel()>1) {
120 cout << "<-AliAnalysisSelector->SlaveBegin()" << endl;
125 //______________________________________________________________________________
126 Bool_t AliAnalysisSelector::Notify()
128 // The Notify() function is called when a new file is opened. This
129 // can be either for a new TTree in a TChain or when when a new TTree
130 // is started when using PROOF. It is normaly not necessary to make changes
131 // to the generated code, but the routine can be extended by the
132 // user if needed. The return value is currently not used.
133 if (fAnalysis) return fAnalysis->Notify();
137 //______________________________________________________________________________
138 Bool_t AliAnalysisSelector::Process(Long64_t entry)
141 static Int_t count = 0;
143 if (fAnalysis->GetDebugLevel() > 1) {
144 cout << "->AliAnalysisSelector::Process()" << endl;
146 static Bool_t init=kTRUE;
147 static Int_t nobjCount = 0;
149 nobjCount = TProcessID::GetObjectCount();
152 TProcessID::SetObjectCount(nobjCount);
153 Int_t returnCode = fAnalysis->GetEntry(entry);
154 if (returnCode <= 0) {
155 cout << "Error retrieving event:" << entry << " Skipping ..." << endl;
156 fAnalysis->CountEvent(1,0,1,0);
158 Abort("Bad stream to file. Trying next image.", kAbortFile);
161 fAnalysis->ExecAnalysis();
162 fAnalysis->CountEvent(1,1,0,0);
164 if (fAnalysis->GetDebugLevel() > 1) {
165 cout << "<-AliAnalysisSelector::Process()" << endl;
170 //______________________________________________________________________________
171 void AliAnalysisSelector::RestoreAnalysisManager()
173 // Restores analysis manager from the input list.
177 while ((obj=next())) {
178 if (obj->IsA() == AliAnalysisManager::Class()) {
179 fAnalysis = (AliAnalysisManager*)obj;
180 fAnalysis->SetSelector(this);
181 if (fAnalysis->GetDebugLevel()>1) {
182 cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
188 Error("SlaveBegin", "Analysis manager not found in the input list");
194 //______________________________________________________________________________
195 void AliAnalysisSelector::SlaveTerminate()
197 // The SlaveTerminate() function is called after all entries or objects
198 // have been processed. When running with PROOF SlaveTerminate() is called
199 // on each slave server.
200 gROOT->SetMustClean(kTRUE);
201 if (fStatus == -1) return; // TSelector won't abort...
202 if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return;
203 if (fAnalysis->GetDebugLevel() > 1) {
204 cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
206 fAnalysis->PackOutput(fOutput);
207 if (fAnalysis->GetDebugLevel() > 1) {
208 cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
212 //______________________________________________________________________________
213 void AliAnalysisSelector::Terminate()
215 // The Terminate() function is the last function to be called during
216 // a query. It always runs on the client, it can be used to present
217 // the results graphically or save the results to file.
218 gROOT->SetMustClean(kTRUE);
219 if (fStatus == -1) return; // TSelector won't abort...
221 Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!");
224 // No Terminate() in case of event mixing
225 if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return;
226 if (fAnalysis->GetDebugLevel() > 1) {
227 cout << "->AliAnalysisSelector::Terminate()" << endl;
229 fAnalysis->UnpackOutput(fOutput);
230 fAnalysis->Terminate();
231 if (fAnalysis->GetDebugLevel() > 1) {
232 cout << "<-AliAnalysisSelector::Terminate()" << endl;