]>
Commit | Line | Data |
---|---|---|
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 | ||
c2e40c93 | 24 | #include <Riostream.h> |
25 | #include <TProcessID.h> | |
c52c2132 | 26 | |
27 | #include "AliAnalysisManager.h" | |
28 | #include "AliAnalysisTask.h" | |
29 | #include "AliAnalysisDataContainer.h" | |
30 | #include "AliAnalysisSelector.h" | |
31 | ||
32 | ClassImp(AliAnalysisSelector) | |
33 | ||
1f87e9fb | 34 | //______________________________________________________________________________ |
35 | AliAnalysisSelector::AliAnalysisSelector() | |
36 | :TSelector(), | |
37 | fInitialized(kFALSE), | |
38 | fAnalysis(NULL) | |
39 | { | |
40 | // Dummy ctor. | |
41 | fAnalysis = AliAnalysisManager::GetAnalysisManager(); | |
42 | if (fAnalysis) fAnalysis->SetSelector(this); | |
43 | } | |
44 | ||
c52c2132 | 45 | //______________________________________________________________________________ |
46 | AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr) | |
47 | :TSelector(), | |
48 | fInitialized(kFALSE), | |
49 | fAnalysis(mgr) | |
50 | { | |
51 | // Constructor. Called by AliAnalysisManager which registers itself on the | |
52 | // selector running on the master. | |
1f87e9fb | 53 | mgr->SetSelector(this); |
c52c2132 | 54 | } |
55 | ||
56 | //______________________________________________________________________________ | |
57 | AliAnalysisSelector::~AliAnalysisSelector() | |
58 | { | |
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; | |
62 | } | |
63 | ||
64 | //______________________________________________________________________________ | |
65 | void AliAnalysisSelector::Init(TTree *tree) | |
66 | { | |
67 | // Called after Begin/SlaveBegin, assumes that fAnalysis is already initialized. | |
68 | // Is Init called on workers in case of PROOF. | |
69 | if (!fAnalysis) { | |
70 | Error("Init", "Analysis manager NULL !"); | |
2d626244 | 71 | Abort("Cannot initialize without analysis manager. Aborting."); |
72 | SetStatus(-1); | |
c52c2132 | 73 | return; |
74 | } | |
cd463514 | 75 | if (fAnalysis->GetDebugLevel()>1) { |
981f2614 | 76 | cout << "->AliAnalysisSelector->Init()" << endl; |
77 | } | |
c52c2132 | 78 | if (!tree) { |
79 | Error("Init", "Input tree is NULL !"); | |
2d626244 | 80 | Abort("Cannot initialize without tree. Aborting."); |
81 | SetStatus(-1); | |
c52c2132 | 82 | return; |
83 | } | |
2d626244 | 84 | fInitialized = fAnalysis->Init(tree); |
85 | if (!fInitialized) { | |
86 | Error("Init", "Some error occured during analysis manager initialization. Aborting."); | |
87 | Abort("Error during AliAnalysisManager::Init()"); | |
88 | SetStatus(-1); | |
89 | return; | |
90 | } | |
cd463514 | 91 | if (fAnalysis->GetDebugLevel()>1) { |
981f2614 | 92 | cout << "<-AliAnalysisSelector->Init()" << endl; |
93 | } | |
c52c2132 | 94 | } |
95 | ||
96 | //______________________________________________________________________________ | |
97 | void AliAnalysisSelector::Begin(TTree *) | |
98 | { | |
99 | // Assembly the input list. | |
100 | RestoreAnalysisManager(); | |
cd463514 | 101 | if (fAnalysis && fAnalysis->GetDebugLevel()>1) { |
36e82a52 | 102 | cout << "->AliAnalysisSelector->Begin: Analysis manager restored" << endl; |
103 | } | |
c52c2132 | 104 | } |
105 | ||
106 | //______________________________________________________________________________ | |
107 | void AliAnalysisSelector::SlaveBegin(TTree *tree) | |
108 | { | |
109 | // Called on each worker. We "unpack" analysis manager here and call InitAnalysis. | |
110 | RestoreAnalysisManager(); | |
981f2614 | 111 | if (fAnalysis) { |
cd463514 | 112 | if (fAnalysis->GetDebugLevel()>1) { |
981f2614 | 113 | cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl; |
114 | } | |
115 | fAnalysis->SlaveBegin(tree); | |
cd463514 | 116 | if (fAnalysis->GetDebugLevel()>1) { |
981f2614 | 117 | cout << "<-AliAnalysisSelector->SlaveBegin()" << endl; |
118 | } | |
119 | } | |
36e82a52 | 120 | } |
c52c2132 | 121 | |
981f2614 | 122 | //______________________________________________________________________________ |
123 | Bool_t AliAnalysisSelector::Notify() | |
124 | { | |
125 | // The Notify() function is called when a new file is opened. This | |
126 | // can be either for a new TTree in a TChain or when when a new TTree | |
127 | // is started when using PROOF. It is normaly not necessary to make changes | |
128 | // to the generated code, but the routine can be extended by the | |
129 | // user if needed. The return value is currently not used. | |
d8a5ee94 | 130 | if (fAnalysis) return fAnalysis->Notify(); |
131 | return kFALSE; | |
36e82a52 | 132 | } |
981f2614 | 133 | |
c52c2132 | 134 | //______________________________________________________________________________ |
135 | Bool_t AliAnalysisSelector::Process(Long64_t entry) | |
136 | { | |
137 | // Event loop. | |
4747b4a7 | 138 | static Int_t count = 0; |
139 | count++; | |
cd463514 | 140 | if (fAnalysis->GetDebugLevel() > 1) { |
981f2614 | 141 | cout << "->AliAnalysisSelector::Process()" << endl; |
36e82a52 | 142 | } |
1ee5d9a3 | 143 | static Bool_t init=kTRUE; |
144 | static Int_t nobjCount = 0; | |
145 | if(init) { | |
146 | nobjCount = TProcessID::GetObjectCount(); | |
147 | init=kFALSE; | |
148 | } | |
149 | TProcessID::SetObjectCount(nobjCount); | |
8e57d9c4 | 150 | Int_t returnCode = fAnalysis->GetEntry(entry); |
f5cbe261 | 151 | if (returnCode <= 0) { |
152 | cout << "Error retrieving event:" << entry << " Skipping ..." << endl; | |
153 | fAnalysis->CountEvent(1,0,1,0); | |
1d0b4d65 | 154 | // Try to skip file |
155 | Abort("Bad stream to file. Trying next image.", kAbortFile); | |
156 | return kFALSE; | |
f5cbe261 | 157 | } else { |
158 | fAnalysis->ExecAnalysis(); | |
c390e055 | 159 | fAnalysis->CountEvent(1,1,0,0); |
f5cbe261 | 160 | } |
cd463514 | 161 | if (fAnalysis->GetDebugLevel() > 1) { |
981f2614 | 162 | cout << "<-AliAnalysisSelector::Process()" << endl; |
163 | } | |
c52c2132 | 164 | return kTRUE; |
165 | } | |
166 | ||
167 | //______________________________________________________________________________ | |
168 | void AliAnalysisSelector::RestoreAnalysisManager() | |
169 | { | |
170 | // Restores analysis manager from the input list. | |
171 | if (!fAnalysis) { | |
172 | TIter next(fInput); | |
173 | TObject *obj; | |
174 | while ((obj=next())) { | |
175 | if (obj->IsA() == AliAnalysisManager::Class()) { | |
176 | fAnalysis = (AliAnalysisManager*)obj; | |
8d7d3b59 | 177 | fAnalysis->SetSelector(this); |
cd463514 | 178 | if (fAnalysis->GetDebugLevel()>1) { |
981f2614 | 179 | cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl; |
180 | } | |
c52c2132 | 181 | break; |
182 | } | |
183 | } | |
184 | if (!fAnalysis) { | |
185 | Error("SlaveBegin", "Analysis manager not found in the input list"); | |
186 | return; | |
187 | } | |
188 | } | |
189 | } | |
190 | ||
191 | //______________________________________________________________________________ | |
192 | void AliAnalysisSelector::SlaveTerminate() | |
193 | { | |
194 | // The SlaveTerminate() function is called after all entries or objects | |
195 | // have been processed. When running with PROOF SlaveTerminate() is called | |
196 | // on each slave server. | |
2d626244 | 197 | if (fStatus == -1) return; // TSelector won't abort... |
aee5ee44 | 198 | if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return; |
cd463514 | 199 | if (fAnalysis->GetDebugLevel() > 1) { |
981f2614 | 200 | cout << "->AliAnalysisSelector::SlaveTerminate()" << endl; |
c52c2132 | 201 | } |
202 | fAnalysis->PackOutput(fOutput); | |
cd463514 | 203 | if (fAnalysis->GetDebugLevel() > 1) { |
981f2614 | 204 | cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl; |
205 | } | |
c52c2132 | 206 | } |
207 | ||
208 | //______________________________________________________________________________ | |
209 | void AliAnalysisSelector::Terminate() | |
210 | { | |
211 | // The Terminate() function is the last function to be called during | |
212 | // a query. It always runs on the client, it can be used to present | |
213 | // the results graphically or save the results to file. | |
2d626244 | 214 | if (fStatus == -1) return; // TSelector won't abort... |
c52c2132 | 215 | if (!fAnalysis) { |
36e82a52 | 216 | Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!"); |
c52c2132 | 217 | return; |
218 | } | |
aee5ee44 | 219 | // No Terminate() in case of event mixing |
220 | if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return; | |
cd463514 | 221 | if (fAnalysis->GetDebugLevel() > 1) { |
981f2614 | 222 | cout << "->AliAnalysisSelector::Terminate()" << endl; |
c52c2132 | 223 | } |
224 | fAnalysis->UnpackOutput(fOutput); | |
225 | fAnalysis->Terminate(); | |
cd463514 | 226 | if (fAnalysis->GetDebugLevel() > 1) { |
981f2614 | 227 | cout << "<-AliAnalysisSelector::Terminate()" << endl; |
228 | } | |
c52c2132 | 229 | } |