]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisSelector.cxx
- New class AliAnalysisDataWrapper used for streaming output results from PROOF to
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisSelector.cxx
CommitLineData
c52c2132 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/* $Id$ */
17// Author: Andrei Gheata, 31/05/2006
18
19//==============================================================================
20// AliAnalysisSelector - A transparent selector to be created by
21// AliAnalysisManager to handle analysis.
22//==============================================================================
23
24#include "Riostream.h"
25
26#include "AliAnalysisManager.h"
27#include "AliAnalysisTask.h"
28#include "AliAnalysisDataContainer.h"
29#include "AliAnalysisSelector.h"
30
31ClassImp(AliAnalysisSelector)
32
33//______________________________________________________________________________
34AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
35 :TSelector(),
36 fInitialized(kFALSE),
37 fAnalysis(mgr)
38{
39// Constructor. Called by AliAnalysisManager which registers itself on the
40// selector running on the master.
41}
42
43//______________________________________________________________________________
44AliAnalysisSelector::~AliAnalysisSelector()
45{
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;
49}
50
51//______________________________________________________________________________
52void AliAnalysisSelector::Init(TTree *tree)
53{
54// Called after Begin/SlaveBegin, assumes that fAnalysis is already initialized.
55// Is Init called on workers in case of PROOF.
56 if (!fAnalysis) {
57 Error("Init", "Analysis manager NULL !");
58 return;
59 }
981f2614 60 if (fAnalysis->GetDebugLevel()>1) {
61 cout << "->AliAnalysisSelector->Init()" << endl;
62 }
c52c2132 63 if (!tree) {
64 Error("Init", "Input tree is NULL !");
65 return;
66 }
67 fAnalysis->Init(tree);
68 fInitialized = kTRUE;
981f2614 69 if (fAnalysis->GetDebugLevel()>1) {
70 cout << "<-AliAnalysisSelector->Init()" << endl;
71 }
c52c2132 72}
73
74//______________________________________________________________________________
75void AliAnalysisSelector::Begin(TTree *)
76{
77// Assembly the input list.
78 RestoreAnalysisManager();
981f2614 79 if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
80 cout << "->AliAnalysisSelector->Init: Analysis manager restored" << endl;
81 }
c52c2132 82}
83
84//______________________________________________________________________________
85void AliAnalysisSelector::SlaveBegin(TTree *tree)
86{
87// Called on each worker. We "unpack" analysis manager here and call InitAnalysis.
88 RestoreAnalysisManager();
981f2614 89 if (fAnalysis) {
90 if (fAnalysis->GetDebugLevel()>1) {
91 cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl;
92 }
93 fAnalysis->SlaveBegin(tree);
94 if (fAnalysis->GetDebugLevel()>1) {
95 cout << "<-AliAnalysisSelector->SlaveBegin()" << endl;
96 }
97 }
c52c2132 98}
99
981f2614 100//______________________________________________________________________________
101Bool_t AliAnalysisSelector::Notify()
102{
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();
109}
110
c52c2132 111//______________________________________________________________________________
112Bool_t AliAnalysisSelector::Process(Long64_t entry)
113{
114// Event loop.
115 if (fAnalysis->GetDebugLevel() >1 ) {
981f2614 116 cout << "->AliAnalysisSelector::Process()" << endl;
c52c2132 117 }
118 fAnalysis->GetEntry(entry); // Not needed anymore in version 2
119 fAnalysis->ExecAnalysis();
981f2614 120 if (fAnalysis->GetDebugLevel() >1 ) {
121 cout << "<-AliAnalysisSelector::Process()" << endl;
122 }
c52c2132 123 return kTRUE;
124}
125
126//______________________________________________________________________________
127void AliAnalysisSelector::RestoreAnalysisManager()
128{
129// Restores analysis manager from the input list.
130 if (!fAnalysis) {
131 TIter next(fInput);
132 TObject *obj;
133 while ((obj=next())) {
134 if (obj->IsA() == AliAnalysisManager::Class()) {
135 fAnalysis = (AliAnalysisManager*)obj;
981f2614 136 if (fAnalysis->GetDebugLevel()>1) {
137 cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
138 }
c52c2132 139 break;
140 }
141 }
142 if (!fAnalysis) {
143 Error("SlaveBegin", "Analysis manager not found in the input list");
144 return;
145 }
146 }
147}
148
149//______________________________________________________________________________
150void AliAnalysisSelector::SlaveTerminate()
151{
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 ) {
981f2614 156 cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
c52c2132 157 }
158 fAnalysis->PackOutput(fOutput);
981f2614 159 if (fAnalysis->GetDebugLevel() >1 ) {
160 cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
161 }
c52c2132 162}
163
164//______________________________________________________________________________
165void AliAnalysisSelector::Terminate()
166{
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.
170 if (!fAnalysis) {
171 Error("Terminate","AliAnalysisSelector::Terminate: No analysisManager!!!");
172 return;
173 }
174 if (fAnalysis->GetDebugLevel() >1 ) {
981f2614 175 cout << "->AliAnalysisSelector::Terminate()" << endl;
c52c2132 176 }
177 fAnalysis->UnpackOutput(fOutput);
178 fAnalysis->Terminate();
981f2614 179 if (fAnalysis->GetDebugLevel() >1 ) {
180 cout << "<-AliAnalysisSelector::Terminate()" << endl;
181 }
c52c2132 182}