]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskME.cxx
Using GRP instead of local setters
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskME.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  
18 #include <TROOT.h>
19 #include <TSystem.h>
20 #include <TInterpreter.h>
21 #include <TChain.h>
22 #include <TFile.h>
23 #include <TList.h>
24
25 #include "AliAnalysisTaskME.h"
26 #include "AliAnalysisManager.h"
27 #include "AliAODEvent.h"
28 #include "AliAODHandler.h"
29 #include "AliMultiAODInputHandler.h"
30 #include "AliLog.h"
31
32
33 ClassImp(AliAnalysisTaskME)
34
35 ////////////////////////////////////////////////////////////////////////
36
37 AliAnalysisTaskME::AliAnalysisTaskME():
38     AliAnalysisTask(),
39     fDebug(0),
40     fEntry(0),
41     fFreshBufferOnly(kFALSE),
42     fInputHandler(0x0),
43     fOutputAOD(0x0),
44     fTreeA(0x0)
45 {
46   // Default constructor
47 }
48
49 AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
50     AliAnalysisTask(name, "AnalysisTaskME"),
51     fDebug(0),
52     fEntry(0),
53     fFreshBufferOnly(kFALSE),
54     fInputHandler(0x0),
55     fOutputAOD(0x0),
56     fTreeA(0x0)
57 {
58   // Default constructor
59     DefineInput (0, TChain::Class());
60     DefineOutput(0,  TTree::Class());
61 }
62
63 AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
64     AliAnalysisTask(obj),
65     fDebug(0),
66     fEntry(0),
67     fFreshBufferOnly(kFALSE),
68     fInputHandler(0x0),
69     fOutputAOD(0x0),
70     fTreeA(0x0)
71 {
72 // Copy constructor
73     fDebug        = obj.fDebug;
74     fEntry        = obj.fEntry;
75     fInputHandler = obj.fInputHandler;
76     fOutputAOD    = obj.fOutputAOD;
77     fTreeA        = obj.fTreeA;    
78 }
79
80
81 AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
82 {
83 // Assignment
84     AliAnalysisTask::operator=(other);
85     fDebug           = other.fDebug;
86     fEntry           = other.fEntry;
87     fFreshBufferOnly = other.fFreshBufferOnly;
88     fInputHandler    = other.fInputHandler;
89     fOutputAOD       = other.fOutputAOD;
90     fTreeA           = other.fTreeA;    
91     return *this;
92 }
93
94
95 void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
96 {
97 // Connect the input data
98     if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
99 //
100 //  Multi AOD
101 //
102     fInputHandler = dynamic_cast<AliMultiAODInputHandler*> 
103         ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
104     if (fInputHandler == 0) {
105         AliFatal("Event Handler has to be MultiAODInputHandler !");
106     } else {
107         // Check that we have an event pool
108         if (!fInputHandler->GetEventPool()) {
109             fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
110             if (!fInputHandler->GetEventPool()) 
111                 AliFatal("MultiAODInputHandler has no EventPool connected !");
112         }
113     }
114 }
115
116 void AliAnalysisTaskME::CreateOutputObjects()
117 {
118 // Create the output container
119 //
120 //  Default AOD
121     if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
122
123     AliAODHandler* handler = (AliAODHandler*) 
124         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
125     
126     if (handler) {
127         fOutputAOD   = handler->GetAOD();
128         fTreeA = handler->GetTree();
129     } else {
130         AliWarning("No AOD Event Handler connected.") ; 
131     }
132     UserCreateOutputObjects();
133 }
134
135 void AliAnalysisTaskME::Exec(Option_t* option)
136 {
137 //
138 // Exec analysis of one event
139
140     if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
141     if( fInputHandler ) 
142        fEntry = fInputHandler->GetReadEntry();
143     if ( !((Entry()-1)%100) && fDebug > 0) 
144          AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
145          
146 // Call the user analysis    
147     if (fInputHandler->IsBufferReady()) {
148         if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
149         {
150             UserExec(option);
151             PostData(0, fTreeA);
152         }
153     } else {
154         AliInfo(Form("Waiting for buffer to be ready !\n"));
155     }
156 }
157
158 const char* AliAnalysisTaskME::CurrentFileName()
159 {
160 // Returns the current file name    
161     if(fInputHandler )
162         return fInputHandler->GetTree()->GetCurrentFile()->GetName();
163     else return "";
164 }
165
166 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj)
167 {
168     // Add a new branch to the aod tree
169     AliAODHandler* handler = (AliAODHandler*) 
170         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
171     if (handler) {
172         handler->AddBranch(cname, addobj);
173     }
174 }
175
176 AliAODEvent*  AliAnalysisTaskME::GetEvent(Int_t iev)
177 {
178     // Get an event from the input handler
179     return (fInputHandler->GetEvent(iev));
180 }
181