1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // Author: Andrei Gheata, 31/05/2006
19 //==============================================================================
20 // AliAnalysisSelector - A transparent selector to be created by
21 // AliAnalysisManager to handle analysis.
22 //==============================================================================
24 #include "Riostream.h"
26 #include "AliAnalysisManager.h"
27 #include "AliAnalysisTask.h"
28 #include "AliAnalysisDataContainer.h"
29 #include "AliAnalysisSelector.h"
31 ClassImp(AliAnalysisSelector)
33 //______________________________________________________________________________
34 AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
39 // Constructor. Called by AliAnalysisManager which registers itself on the
40 // selector running on the master.
43 //______________________________________________________________________________
44 AliAnalysisSelector::~AliAnalysisSelector()
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;
51 //______________________________________________________________________________
52 void AliAnalysisSelector::Init(TTree *tree)
54 // Called after Begin/SlaveBegin, assumes that fAnalysis is already initialized.
55 // Is Init called on workers in case of PROOF.
57 Error("Init", "Analysis manager NULL !");
61 Error("Init", "Input tree is NULL !");
64 fAnalysis->Init(tree);
68 //______________________________________________________________________________
69 void AliAnalysisSelector::Begin(TTree *)
71 // Assembly the input list.
72 RestoreAnalysisManager();
75 //______________________________________________________________________________
76 void AliAnalysisSelector::SlaveBegin(TTree *tree)
78 // Called on each worker. We "unpack" analysis manager here and call InitAnalysis.
79 RestoreAnalysisManager();
80 if (fAnalysis) fAnalysis->SlaveBegin(tree);
83 //______________________________________________________________________________
84 Bool_t AliAnalysisSelector::Process(Long64_t entry)
87 if (fAnalysis->GetDebugLevel() >1 ) {
88 printf("AliAnalysisSelector::Process()\n");
90 fAnalysis->GetEntry(entry); // Not needed anymore in version 2
91 fAnalysis->ExecAnalysis();
95 //______________________________________________________________________________
96 void AliAnalysisSelector::RestoreAnalysisManager()
98 // Restores analysis manager from the input list.
102 while ((obj=next())) {
103 if (obj->IsA() == AliAnalysisManager::Class()) {
104 fAnalysis = (AliAnalysisManager*)obj;
109 Error("SlaveBegin", "Analysis manager not found in the input list");
115 //______________________________________________________________________________
116 void AliAnalysisSelector::SlaveTerminate()
118 // The SlaveTerminate() function is called after all entries or objects
119 // have been processed. When running with PROOF SlaveTerminate() is called
120 // on each slave server.
121 if (fAnalysis->GetDebugLevel() >1 ) {
122 printf("AliAnalysisSelector::SlaveTerminate()\n");
124 fAnalysis->PackOutput(fOutput);
127 //______________________________________________________________________________
128 void AliAnalysisSelector::Terminate()
130 // The Terminate() function is the last function to be called during
131 // a query. It always runs on the client, it can be used to present
132 // the results graphically or save the results to file.
134 Error("Terminate","AliAnalysisSelector::Terminate: No analysisManager!!!");
137 if (fAnalysis->GetDebugLevel() >1 ) {
138 printf("AliAnalysisSelector::Terminate()\n");
140 fAnalysis->UnpackOutput(fOutput);
141 fAnalysis->Terminate();