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