]>
Commit | Line | Data |
---|---|---|
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 | #include <TProcessID.h> | |
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 !"); | |
59 | return; | |
60 | } | |
61 | if (fAnalysis->GetDebugLevel()>0) { | |
62 | cout << "->AliAnalysisSelector->Init()" << endl; | |
63 | } | |
64 | if (!tree) { | |
65 | Error("Init", "Input tree is NULL !"); | |
66 | return; | |
67 | } | |
68 | fAnalysis->Init(tree); | |
69 | fInitialized = kTRUE; | |
70 | if (fAnalysis->GetDebugLevel()>0) { | |
71 | cout << "<-AliAnalysisSelector->Init()" << endl; | |
72 | } | |
73 | } | |
74 | ||
75 | //______________________________________________________________________________ | |
76 | void AliAnalysisSelector::Begin(TTree *) | |
77 | { | |
78 | // Assembly the input list. | |
79 | RestoreAnalysisManager(); | |
80 | if (fAnalysis && fAnalysis->GetDebugLevel()>0) { | |
81 | cout << "->AliAnalysisSelector->Begin: Analysis manager restored" << endl; | |
82 | } | |
83 | } | |
84 | ||
85 | //______________________________________________________________________________ | |
86 | void AliAnalysisSelector::SlaveBegin(TTree *tree) | |
87 | { | |
88 | // Called on each worker. We "unpack" analysis manager here and call InitAnalysis. | |
89 | RestoreAnalysisManager(); | |
90 | if (fAnalysis) { | |
91 | if (fAnalysis->GetDebugLevel()>0) { | |
92 | cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl; | |
93 | } | |
94 | fAnalysis->SlaveBegin(tree); | |
95 | if (fAnalysis->GetDebugLevel()>0) { | |
96 | cout << "<-AliAnalysisSelector->SlaveBegin()" << endl; | |
97 | } | |
98 | } | |
99 | } | |
100 | ||
101 | //______________________________________________________________________________ | |
102 | Bool_t AliAnalysisSelector::Notify() | |
103 | { | |
104 | // The Notify() function is called when a new file is opened. This | |
105 | // can be either for a new TTree in a TChain or when when a new TTree | |
106 | // is started when using PROOF. It is normaly not necessary to make changes | |
107 | // to the generated code, but the routine can be extended by the | |
108 | // user if needed. The return value is currently not used. | |
109 | if (fAnalysis) return fAnalysis->Notify(); | |
110 | return kFALSE; | |
111 | } | |
112 | ||
113 | //______________________________________________________________________________ | |
114 | Bool_t AliAnalysisSelector::Process(Long64_t entry) | |
115 | { | |
116 | // Event loop. | |
117 | if (fAnalysis->GetDebugLevel() > 0) { | |
118 | cout << "->AliAnalysisSelector::Process()" << endl; | |
119 | } | |
120 | Int_t nobjCount = TProcessID::GetObjectCount(); | |
121 | fAnalysis->GetEntry(entry); | |
122 | fAnalysis->ExecAnalysis(); | |
123 | TProcessID::SetObjectCount(nobjCount); | |
124 | if (fAnalysis->GetDebugLevel() > 0) { | |
125 | cout << "<-AliAnalysisSelector::Process()" << endl; | |
126 | } | |
127 | return kTRUE; | |
128 | } | |
129 | ||
130 | //______________________________________________________________________________ | |
131 | void AliAnalysisSelector::RestoreAnalysisManager() | |
132 | { | |
133 | // Restores analysis manager from the input list. | |
134 | if (!fAnalysis) { | |
135 | TIter next(fInput); | |
136 | TObject *obj; | |
137 | while ((obj=next())) { | |
138 | if (obj->IsA() == AliAnalysisManager::Class()) { | |
139 | fAnalysis = (AliAnalysisManager*)obj; | |
140 | fAnalysis->SetSelector(this); | |
141 | if (fAnalysis->GetDebugLevel()>0) { | |
142 | cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl; | |
143 | } | |
144 | break; | |
145 | } | |
146 | } | |
147 | if (!fAnalysis) { | |
148 | Error("SlaveBegin", "Analysis manager not found in the input list"); | |
149 | return; | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | //______________________________________________________________________________ | |
155 | void AliAnalysisSelector::SlaveTerminate() | |
156 | { | |
157 | // The SlaveTerminate() function is called after all entries or objects | |
158 | // have been processed. When running with PROOF SlaveTerminate() is called | |
159 | // on each slave server. | |
160 | if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return; | |
161 | if (fAnalysis->GetDebugLevel() > 0) { | |
162 | cout << "->AliAnalysisSelector::SlaveTerminate()" << endl; | |
163 | } | |
164 | fAnalysis->PackOutput(fOutput); | |
165 | if (fAnalysis->GetDebugLevel() > 0) { | |
166 | cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl; | |
167 | } | |
168 | } | |
169 | ||
170 | //______________________________________________________________________________ | |
171 | void AliAnalysisSelector::Terminate() | |
172 | { | |
173 | // The Terminate() function is the last function to be called during | |
174 | // a query. It always runs on the client, it can be used to present | |
175 | // the results graphically or save the results to file. | |
176 | if (!fAnalysis) { | |
177 | Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!"); | |
178 | return; | |
179 | } | |
180 | // No Terminate() in case of event mixing | |
181 | if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return; | |
182 | if (fAnalysis->GetDebugLevel() > 0) { | |
183 | cout << "->AliAnalysisSelector::Terminate()" << endl; | |
184 | } | |
185 | fAnalysis->UnpackOutput(fOutput); | |
186 | fAnalysis->Terminate(); | |
187 | if (fAnalysis->GetDebugLevel() > 0) { | |
188 | cout << "<-AliAnalysisSelector::Terminate()" << endl; | |
189 | } | |
190 | } |