Additional flags for AOD replication (Roberta Arnaldi, AM)
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.cxx
CommitLineData
5232d0de 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 "AliAnalysisTaskSE.h"
26#include "AliAnalysisManager.h"
27#include "AliESDEvent.h"
28#include "AliESD.h"
29#include "AliAODEvent.h"
3f2431c4 30#include "AliAODHeader.h"
5232d0de 31#include "AliVEvent.h"
32#include "AliAODHandler.h"
3f2431c4 33#include "AliAODInputHandler.h"
5232d0de 34#include "AliMCEventHandler.h"
35#include "AliInputEventHandler.h"
36#include "AliMCEvent.h"
37#include "AliStack.h"
4d0a82af 38#include "AliLog.h"
5232d0de 39
40
41ClassImp(AliAnalysisTaskSE)
42
43////////////////////////////////////////////////////////////////////////
3f2431c4 44Bool_t AliAnalysisTaskSE::fgHeaderCopied = kFALSE;
45AliAODHeader* AliAnalysisTaskSE::fgAODHeader = NULL;
5232d0de 46
47AliAnalysisTaskSE::AliAnalysisTaskSE():
48 AliAnalysisTask(),
49 fDebug(0),
80d13558 50 fEntry(0),
5232d0de 51 fInputEvent(0x0),
80d13558 52 fInputHandler(0x0),
5232d0de 53 fOutputAOD(0x0),
54 fMCEvent(0x0),
55 fTreeA(0x0)
56{
57 // Default constructor
58}
59
60AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
61 AliAnalysisTask(name, "AnalysisTaskSE"),
62 fDebug(0),
80d13558 63 fEntry(0),
5232d0de 64 fInputEvent(0x0),
80d13558 65 fInputHandler(0x0),
5232d0de 66 fOutputAOD(0x0),
67 fMCEvent(0x0),
68 fTreeA(0x0)
69{
70 // Default constructor
71 DefineInput (0, TChain::Class());
72 DefineOutput(0, TTree::Class());
73}
74
26f071d8 75AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
76 AliAnalysisTask(obj),
77 fDebug(0),
80d13558 78 fEntry(0),
26f071d8 79 fInputEvent(0x0),
80d13558 80 fInputHandler(0x0),
26f071d8 81 fOutputAOD(0x0),
82 fMCEvent(0x0),
83 fTreeA(0x0)
84{
85// Copy constructor
80d13558 86 fDebug = obj.fDebug;
87 fEntry = obj.fEntry;
88 fInputEvent = obj.fInputEvent;
89 fInputHandler = obj.fInputHandler;
90 fOutputAOD = obj.fOutputAOD;
91 fMCEvent = obj.fMCEvent;
92 fTreeA = obj.fTreeA;
f0b15803 93 printf("Constructor (3) \n");
26f071d8 94}
95
96
97AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
98{
99// Assignment
100 AliAnalysisTask::operator=(other);
80d13558 101 fDebug = other.fDebug;
102 fEntry = other.fEntry;
103 fInputEvent = other.fInputEvent;
104 fInputHandler = other.fInputHandler;
105 fOutputAOD = other.fOutputAOD;
106 fMCEvent = other.fMCEvent;
107 fTreeA = other.fTreeA;
26f071d8 108 return *this;
109}
5232d0de 110
111
112void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
113{
114// Connect the input data
115 if (fDebug > 1) printf("AnalysisTaskSE::ConnectInputData() \n");
116//
117// ESD
118//
f0b15803 119 fInputHandler = (AliInputEventHandler*)
259b7a8a 120 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
5232d0de 121//
122// Monte Carlo
123//
124 AliMCEventHandler* mcH = 0;
125 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
126 if (mcH) fMCEvent = mcH->MCEvent();
259b7a8a 127
128
129 if (fInputHandler) {
130 fInputEvent = fInputHandler->GetEvent();
131 } else if( fMCEvent ) {
132 AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ;
133 } else {
134 AliError("No Input Event Handler connected") ;
135 return ;
136 }
5232d0de 137}
138
139void AliAnalysisTaskSE::CreateOutputObjects()
140{
141// Create the output container
142//
143// Default AOD
144 if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
145
146 AliAODHandler* handler = (AliAODHandler*)
259b7a8a 147 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
5232d0de 148
3b9a675c 149 if (handler) {
150 fOutputAOD = handler->GetAOD();
151 fTreeA = handler->GetTree();
3f2431c4 152 // Check if AOD Header replication has been required
153 if (!(handler->IsStandard()) &&
154 (handler->NeedsHeaderReplication()) &&
155 !(fgAODHeader))
156 {
157 fgAODHeader = new AliAODHeader;
158 handler->AddBranch("AliAODHeader", &fgAODHeader);
159 }
3b9a675c 160 } else {
161 AliWarning("No AOD Event Handler connected.") ;
162 }
5232d0de 163 UserCreateOutputObjects();
164}
165
166void AliAnalysisTaskSE::Exec(Option_t* option)
167{
168//
169// Exec analysis of one event
259b7a8a 170 if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
171 if( fInputHandler )
172 fEntry = fInputHandler->GetReadEntry();
173 else if( fMCEvent )
174 fEntry = fMCEvent->Header()->GetEvent();
4d0a82af 175 if ( !((Entry()-1)%100) && fDebug > 0)
259b7a8a 176 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
3f2431c4 177
178 AliAODHandler* handler = (AliAODHandler*)
179 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
daa81fe5 180 if (handler) {
181 if (!(handler->IsStandard()) &&
182 (handler->NeedsHeaderReplication()) &&
183 (fgAODHeader))
184 {
185 // Header should be replicated
186 AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
187 if (aodH) {
188 // Input is AOD
189 fgAODHeader = dynamic_cast<AliAODHeader*>(InputEvent()->GetHeader());
190 fgHeaderCopied = kTRUE;
191 }
3f2431c4 192 }
193 }
daa81fe5 194
3f2431c4 195
4d0a82af 196// Call the user analysis
5232d0de 197 UserExec(option);
2d108f6e 198 PostData(0, fTreeA);
199
5232d0de 200}
201
4d0a82af 202const char* AliAnalysisTaskSE::CurrentFileName()
203{
204// Returns the current file name
259b7a8a 205 if( fInputHandler )
206 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
207 else if( fMCEvent )
208 return ((AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()))->TreeK()->GetCurrentFile()->GetName();
8803dcb1 209 else return "";
4d0a82af 210}
5232d0de 211
0134949d 212void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj)
164e94ff 213{
214 // Add a new branch to the aod tree
215 AliAODHandler* handler = (AliAODHandler*)
216 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
217 if (handler) {
3b427089 218 handler->AddBranch(cname, addobj);
164e94ff 219 }
220}