]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisSelector.cxx
- New class AliAnalysisDataWrapper used for streaming output results from PROOF to
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisSelector.cxx
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    }
60    if (fAnalysis->GetDebugLevel()>1) {
61       cout << "->AliAnalysisSelector->Init()" << endl;
62    }   
63    if (!tree) {
64       Error("Init", "Input tree is NULL !");
65       return;
66    }
67    fAnalysis->Init(tree);
68    fInitialized = kTRUE;
69    if (fAnalysis->GetDebugLevel()>1) {
70       cout << "<-AliAnalysisSelector->Init()" << endl;
71    }   
72 }
73
74 //______________________________________________________________________________
75 void AliAnalysisSelector::Begin(TTree *)
76 {
77 // Assembly the input list.
78    RestoreAnalysisManager();
79    if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
80       cout << "->AliAnalysisSelector->Init: Analysis manager restored" << endl;
81    }   
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();
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    }   
98 }      
99
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.
108    if (fAnalysis) fAnalysis->Notify();
109 }   
110
111 //______________________________________________________________________________
112 Bool_t AliAnalysisSelector::Process(Long64_t entry)
113 {
114 // Event loop.
115    if (fAnalysis->GetDebugLevel() >1 ) {
116       cout << "->AliAnalysisSelector::Process()" << endl;
117    }   
118    fAnalysis->GetEntry(entry); // Not needed anymore in version 2
119    fAnalysis->ExecAnalysis();
120    if (fAnalysis->GetDebugLevel() >1 ) {
121       cout << "<-AliAnalysisSelector::Process()" << endl;
122    }   
123    return kTRUE;
124 }   
125
126 //______________________________________________________________________________
127 void 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;
136             if (fAnalysis->GetDebugLevel()>1) {
137                cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
138             }   
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 //______________________________________________________________________________
150 void 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 ) {
156       cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
157    }   
158    fAnalysis->PackOutput(fOutput);
159    if (fAnalysis->GetDebugLevel() >1 ) {
160       cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
161    }   
162 }  
163
164 //______________________________________________________________________________
165 void 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 ) {
175       cout << "->AliAnalysisSelector::Terminate()" << endl;
176    }   
177    fAnalysis->UnpackOutput(fOutput);
178    fAnalysis->Terminate();   
179    if (fAnalysis->GetDebugLevel() >1 ) {
180       cout << "<-AliAnalysisSelector::Terminate()" << endl;
181    }   
182 }