]>
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 | ||
24 | #include "Riostream.h" | |
25 | ||
26 | #include "AliAnalysisManager.h" | |
27 | #include "AliAnalysisTask.h" | |
28 | #include "AliAnalysisDataContainer.h" | |
29 | #include "AliAnalysisSelector.h" | |
30 | ||
31 | ClassImp(AliAnalysisSelector) | |
32 | ||
33 | //______________________________________________________________________________ | |
34 | AliAnalysisSelector::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 | //______________________________________________________________________________ | |
44 | AliAnalysisSelector::~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 | //______________________________________________________________________________ | |
52 | void 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 | //______________________________________________________________________________ | |
75 | void 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 | //______________________________________________________________________________ | |
85 | void 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 | //______________________________________________________________________________ |
101 | Bool_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. | |
d8a5ee94 | 108 | if (fAnalysis) return fAnalysis->Notify(); |
109 | return kFALSE; | |
981f2614 | 110 | } |
111 | ||
c52c2132 | 112 | //______________________________________________________________________________ |
113 | Bool_t AliAnalysisSelector::Process(Long64_t entry) | |
114 | { | |
115 | // Event loop. | |
116 | if (fAnalysis->GetDebugLevel() >1 ) { | |
981f2614 | 117 | cout << "->AliAnalysisSelector::Process()" << endl; |
c52c2132 | 118 | } |
119 | fAnalysis->GetEntry(entry); // Not needed anymore in version 2 | |
120 | fAnalysis->ExecAnalysis(); | |
981f2614 | 121 | if (fAnalysis->GetDebugLevel() >1 ) { |
122 | cout << "<-AliAnalysisSelector::Process()" << endl; | |
123 | } | |
c52c2132 | 124 | return kTRUE; |
125 | } | |
126 | ||
127 | //______________________________________________________________________________ | |
128 | void AliAnalysisSelector::RestoreAnalysisManager() | |
129 | { | |
130 | // Restores analysis manager from the input list. | |
131 | if (!fAnalysis) { | |
132 | TIter next(fInput); | |
133 | TObject *obj; | |
134 | while ((obj=next())) { | |
135 | if (obj->IsA() == AliAnalysisManager::Class()) { | |
136 | fAnalysis = (AliAnalysisManager*)obj; | |
981f2614 | 137 | if (fAnalysis->GetDebugLevel()>1) { |
138 | cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl; | |
139 | } | |
c52c2132 | 140 | break; |
141 | } | |
142 | } | |
143 | if (!fAnalysis) { | |
144 | Error("SlaveBegin", "Analysis manager not found in the input list"); | |
145 | return; | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | //______________________________________________________________________________ | |
151 | void AliAnalysisSelector::SlaveTerminate() | |
152 | { | |
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 ) { | |
981f2614 | 157 | cout << "->AliAnalysisSelector::SlaveTerminate()" << endl; |
c52c2132 | 158 | } |
159 | fAnalysis->PackOutput(fOutput); | |
981f2614 | 160 | if (fAnalysis->GetDebugLevel() >1 ) { |
161 | cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl; | |
162 | } | |
c52c2132 | 163 | } |
164 | ||
165 | //______________________________________________________________________________ | |
166 | void AliAnalysisSelector::Terminate() | |
167 | { | |
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. | |
171 | if (!fAnalysis) { | |
172 | Error("Terminate","AliAnalysisSelector::Terminate: No analysisManager!!!"); | |
173 | return; | |
174 | } | |
175 | if (fAnalysis->GetDebugLevel() >1 ) { | |
981f2614 | 176 | cout << "->AliAnalysisSelector::Terminate()" << endl; |
c52c2132 | 177 | } |
178 | fAnalysis->UnpackOutput(fOutput); | |
179 | fAnalysis->Terminate(); | |
981f2614 | 180 | if (fAnalysis->GetDebugLevel() >1 ) { |
181 | cout << "<-AliAnalysisSelector::Terminate()" << endl; | |
182 | } | |
c52c2132 | 183 | } |