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->Begin: 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) return fAnalysis->Notify();
112 //______________________________________________________________________________
113 Bool_t AliAnalysisSelector::Process(Long64_t entry)
116 if (fAnalysis->GetDebugLevel() >1 ) {
117 cout << "->AliAnalysisSelector::Process()" << endl;
119 fAnalysis->GetEntry(entry);
120 fAnalysis->ExecAnalysis();
121 if (fAnalysis->GetDebugLevel() >1 ) {
122 cout << "<-AliAnalysisSelector::Process()" << endl;
127 //______________________________________________________________________________
128 void AliAnalysisSelector::RestoreAnalysisManager()
130 // Restores analysis manager from the input list.
134 while ((obj=next())) {
135 if (obj->IsA() == AliAnalysisManager::Class()) {
136 fAnalysis = (AliAnalysisManager*)obj;
137 if (fAnalysis->GetDebugLevel()>1) {
138 cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
144 Error("SlaveBegin", "Analysis manager not found in the input list");
150 //______________________________________________________________________________
151 void AliAnalysisSelector::SlaveTerminate()
153 // The SlaveTerminate() function is called after all entries or objects
154 // have been processed. When running with PROOF SlaveTerminate() is called
155 // on each slave server.
156 if (fAnalysis->GetDebugLevel() >1 ) {
157 cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
159 fAnalysis->PackOutput(fOutput);
160 if (fAnalysis->GetDebugLevel() >1 ) {
161 cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
165 //______________________________________________________________________________
166 void AliAnalysisSelector::Terminate()
168 // The Terminate() function is the last function to be called during
169 // a query. It always runs on the client, it can be used to present
170 // the results graphically or save the results to file.
172 Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!");
175 if (fAnalysis->GetDebugLevel() >1 ) {
176 cout << "->AliAnalysisSelector::Terminate()" << endl;
178 fAnalysis->UnpackOutput(fOutput);
179 fAnalysis->Terminate();
180 if (fAnalysis->GetDebugLevel() >1 ) {
181 cout << "<-AliAnalysisSelector::Terminate()" << endl;