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>
27 #include "AliAnalysisManager.h"
28 #include "AliAnalysisTask.h"
29 #include "AliAnalysisDataContainer.h"
30 #include "AliAnalysisSelector.h"
32 ClassImp(AliAnalysisSelector)
34 //______________________________________________________________________________
35 AliAnalysisSelector::AliAnalysisSelector()
41 fAnalysis = AliAnalysisManager::GetAnalysisManager();
42 if (fAnalysis) fAnalysis->SetSelector(this);
45 //______________________________________________________________________________
46 AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
51 // Constructor. Called by AliAnalysisManager which registers itself on the
52 // selector running on the master.
53 mgr->SetSelector(this);
56 //______________________________________________________________________________
57 AliAnalysisSelector::~AliAnalysisSelector()
59 // Dtor. The analysis manager object is sent in the input list and duplicated
60 // on the workers - it needs to be deleted (?)
61 // if (fAnalysis) delete fAnalysis;
64 //______________________________________________________________________________
65 void AliAnalysisSelector::Init(TTree *tree)
67 // Called after Begin/SlaveBegin, assumes that fAnalysis is already initialized.
68 // Is Init called on workers in case of PROOF.
70 Error("Init", "Analysis manager NULL !");
71 Abort("Cannot initialize without analysis manager. Aborting.");
75 if (fAnalysis->GetDebugLevel()>1) {
76 cout << "->AliAnalysisSelector->Init()" << endl;
79 Error("Init", "Input tree is NULL !");
80 Abort("Cannot initialize without tree. Aborting.");
84 fInitialized = fAnalysis->Init(tree);
86 Error("Init", "Some error occured during analysis manager initialization. Aborting.");
87 Abort("Error during AliAnalysisManager::Init()");
91 if (fAnalysis->GetDebugLevel()>1) {
92 cout << "<-AliAnalysisSelector->Init()" << endl;
96 //______________________________________________________________________________
97 void AliAnalysisSelector::Begin(TTree *)
99 // Assembly the input list.
100 RestoreAnalysisManager();
101 if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
102 cout << "->AliAnalysisSelector->Begin: Analysis manager restored" << endl;
106 //______________________________________________________________________________
107 void AliAnalysisSelector::SlaveBegin(TTree *tree)
109 // Called on each worker. We "unpack" analysis manager here and call InitAnalysis.
110 TObject::SetObjectStat(kFALSE);
111 RestoreAnalysisManager();
113 if (fAnalysis->GetDebugLevel()>1) {
114 cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl;
116 fAnalysis->SlaveBegin(tree);
117 if (fAnalysis->GetDebugLevel()>1) {
118 cout << "<-AliAnalysisSelector->SlaveBegin()" << endl;
123 //______________________________________________________________________________
124 Bool_t AliAnalysisSelector::Notify()
126 // The Notify() function is called when a new file is opened. This
127 // can be either for a new TTree in a TChain or when when a new TTree
128 // is started when using PROOF. It is normaly not necessary to make changes
129 // to the generated code, but the routine can be extended by the
130 // user if needed. The return value is currently not used.
131 if (fAnalysis) return fAnalysis->Notify();
135 //______________________________________________________________________________
136 Bool_t AliAnalysisSelector::Process(Long64_t entry)
139 static Int_t count = 0;
141 if (fAnalysis->GetDebugLevel() > 1) {
142 cout << "->AliAnalysisSelector::Process()" << endl;
144 Int_t nobjCount = TProcessID::GetObjectCount();
145 Int_t returnCode = fAnalysis->GetEntry(entry);
146 if (returnCode <= 0) {
147 cout << "Error retrieving event:" << entry << " Skipping ..." << endl;
148 fAnalysis->CountEvent(1,0,1,0);
150 Abort("Bad stream to file. Trying next image.", kAbortFile);
153 fAnalysis->ExecAnalysis();
154 if (returnCode<100000000) fAnalysis->CountEvent(1,1,0,0);
156 TProcessID::SetObjectCount(nobjCount);
157 if (fAnalysis->GetDebugLevel() > 1) {
158 cout << "<-AliAnalysisSelector::Process()" << endl;
163 //______________________________________________________________________________
164 void AliAnalysisSelector::RestoreAnalysisManager()
166 // Restores analysis manager from the input list.
170 while ((obj=next())) {
171 if (obj->IsA() == AliAnalysisManager::Class()) {
172 fAnalysis = (AliAnalysisManager*)obj;
173 fAnalysis->SetSelector(this);
174 if (fAnalysis->GetDebugLevel()>1) {
175 cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
181 Error("SlaveBegin", "Analysis manager not found in the input list");
187 //______________________________________________________________________________
188 void AliAnalysisSelector::SlaveTerminate()
190 // The SlaveTerminate() function is called after all entries or objects
191 // have been processed. When running with PROOF SlaveTerminate() is called
192 // on each slave server.
193 if (fStatus == -1) return; // TSelector won't abort...
194 if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return;
195 if (fAnalysis->GetDebugLevel() > 1) {
196 cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
198 fAnalysis->PackOutput(fOutput);
199 if (fAnalysis->GetDebugLevel() > 1) {
200 cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
204 //______________________________________________________________________________
205 void AliAnalysisSelector::Terminate()
207 // The Terminate() function is the last function to be called during
208 // a query. It always runs on the client, it can be used to present
209 // the results graphically or save the results to file.
210 if (fStatus == -1) return; // TSelector won't abort...
212 Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!");
215 // No Terminate() in case of event mixing
216 if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return;
217 if (fAnalysis->GetDebugLevel() > 1) {
218 cout << "->AliAnalysisSelector::Terminate()" << endl;
220 fAnalysis->UnpackOutput(fOutput);
221 fAnalysis->Terminate();
222 if (fAnalysis->GetDebugLevel() > 1) {
223 cout << "<-AliAnalysisSelector::Terminate()" << endl;