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"
26 #include "AliAnalysisManager.h"
27 #include "AliAnalysisTask.h"
28 #include "AliAnalysisDataContainer.h"
29 #include "AliAnalysisSelector.h"
31 ClassImp(AliAnalysisSelector)
33 //______________________________________________________________________________
34 AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
39 // Constructor. Called by AliAnalysisManager which registers itself on the
40 // selector running on the master.
43 //______________________________________________________________________________
44 AliAnalysisSelector::~AliAnalysisSelector()
46 // Dtor. The analysis manager object is sent in the input list and duplicated
47 // on the workers - it needs to be deleted (?)
48 // if (fAnalysis) delete fAnalysis;
51 //______________________________________________________________________________
52 void AliAnalysisSelector::Init(TTree *tree)
54 // Called after Begin/SlaveBegin, assumes that fAnalysis is already initialized.
55 // Is Init called on workers in case of PROOF.
57 Error("Init", "Analysis manager NULL !");
60 if (fAnalysis->GetDebugLevel()>1) {
61 cout << "->AliAnalysisSelector->Init()" << endl;
64 Error("Init", "Input tree is NULL !");
67 fAnalysis->Init(tree);
69 if (fAnalysis->GetDebugLevel()>1) {
70 cout << "<-AliAnalysisSelector->Init()" << endl;
74 //______________________________________________________________________________
75 void AliAnalysisSelector::Begin(TTree *)
77 // Assembly the input list.
78 RestoreAnalysisManager();
79 if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
80 cout << "->AliAnalysisSelector->Init: Analysis manager restored" << endl;
84 //______________________________________________________________________________
85 void AliAnalysisSelector::SlaveBegin(TTree *tree)
87 // Called on each worker. We "unpack" analysis manager here and call InitAnalysis.
88 RestoreAnalysisManager();
90 if (fAnalysis->GetDebugLevel()>1) {
91 cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl;
93 fAnalysis->SlaveBegin(tree);
94 if (fAnalysis->GetDebugLevel()>1) {
95 cout << "<-AliAnalysisSelector->SlaveBegin()" << endl;
100 //______________________________________________________________________________
101 Bool_t AliAnalysisSelector::Notify()
103 // The Notify() function is called when a new file is opened. This
104 // can be either for a new TTree in a TChain or when when a new TTree
105 // is started when using PROOF. It is normaly not necessary to make changes
106 // to the generated code, but the routine can be extended by the
107 // user if needed. The return value is currently not used.
108 if (fAnalysis) fAnalysis->Notify();
111 //______________________________________________________________________________
112 Bool_t AliAnalysisSelector::Process(Long64_t entry)
115 if (fAnalysis->GetDebugLevel() >1 ) {
116 cout << "->AliAnalysisSelector::Process()" << endl;
118 fAnalysis->GetEntry(entry); // Not needed anymore in version 2
119 fAnalysis->ExecAnalysis();
120 if (fAnalysis->GetDebugLevel() >1 ) {
121 cout << "<-AliAnalysisSelector::Process()" << endl;
126 //______________________________________________________________________________
127 void AliAnalysisSelector::RestoreAnalysisManager()
129 // Restores analysis manager from the input list.
133 while ((obj=next())) {
134 if (obj->IsA() == AliAnalysisManager::Class()) {
135 fAnalysis = (AliAnalysisManager*)obj;
136 if (fAnalysis->GetDebugLevel()>1) {
137 cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
143 Error("SlaveBegin", "Analysis manager not found in the input list");
149 //______________________________________________________________________________
150 void AliAnalysisSelector::SlaveTerminate()
152 // The SlaveTerminate() function is called after all entries or objects
153 // have been processed. When running with PROOF SlaveTerminate() is called
154 // on each slave server.
155 if (fAnalysis->GetDebugLevel() >1 ) {
156 cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
158 fAnalysis->PackOutput(fOutput);
159 if (fAnalysis->GetDebugLevel() >1 ) {
160 cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
164 //______________________________________________________________________________
165 void AliAnalysisSelector::Terminate()
167 // The Terminate() function is the last function to be called during
168 // a query. It always runs on the client, it can be used to present
169 // the results graphically or save the results to file.
171 Error("Terminate","AliAnalysisSelector::Terminate: No analysisManager!!!");
174 if (fAnalysis->GetDebugLevel() >1 ) {
175 cout << "->AliAnalysisSelector::Terminate()" << endl;
177 fAnalysis->UnpackOutput(fOutput);
178 fAnalysis->Terminate();
179 if (fAnalysis->GetDebugLevel() >1 ) {
180 cout << "<-AliAnalysisSelector::Terminate()" << endl;