b81460ad |
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" |
cd17c2ba |
28 | #include "AliVEvent.h" |
b81460ad |
29 | #include "AliAODHandler.h" |
cd17c2ba |
30 | #include "AliMultiEventInputHandler.h" |
b81460ad |
31 | #include "AliLog.h" |
32 | |
33 | |
3c329509 |
34 | ClassImp(AliAnalysisTaskME); |
b81460ad |
35 | |
36 | //////////////////////////////////////////////////////////////////////// |
37 | |
38 | AliAnalysisTaskME::AliAnalysisTaskME(): |
39 | AliAnalysisTask(), |
40 | fDebug(0), |
41 | fEntry(0), |
42 | fFreshBufferOnly(kFALSE), |
43 | fInputHandler(0x0), |
44 | fOutputAOD(0x0), |
3c329509 |
45 | fTreeA(0x0), |
46 | fOfflineTriggerMask(0) |
b81460ad |
47 | { |
48 | // Default constructor |
49 | } |
50 | |
51 | AliAnalysisTaskME::AliAnalysisTaskME(const char* name): |
52 | AliAnalysisTask(name, "AnalysisTaskME"), |
53 | fDebug(0), |
54 | fEntry(0), |
55 | fFreshBufferOnly(kFALSE), |
56 | fInputHandler(0x0), |
57 | fOutputAOD(0x0), |
3c329509 |
58 | fTreeA(0x0), |
59 | fOfflineTriggerMask(0) |
b81460ad |
60 | { |
61 | // Default constructor |
62 | DefineInput (0, TChain::Class()); |
63 | DefineOutput(0, TTree::Class()); |
64 | } |
65 | |
66 | AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj): |
67 | AliAnalysisTask(obj), |
68 | fDebug(0), |
69 | fEntry(0), |
70 | fFreshBufferOnly(kFALSE), |
71 | fInputHandler(0x0), |
72 | fOutputAOD(0x0), |
3c329509 |
73 | fTreeA(0x0), |
74 | fOfflineTriggerMask(0) |
b81460ad |
75 | { |
76 | // Copy constructor |
77 | fDebug = obj.fDebug; |
78 | fEntry = obj.fEntry; |
79 | fInputHandler = obj.fInputHandler; |
80 | fOutputAOD = obj.fOutputAOD; |
3c329509 |
81 | fTreeA = obj.fTreeA; |
82 | fOfflineTriggerMask = obj.fOfflineTriggerMask; |
b81460ad |
83 | } |
84 | |
85 | |
86 | AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other) |
87 | { |
88 | // Assignment |
89 | AliAnalysisTask::operator=(other); |
90 | fDebug = other.fDebug; |
91 | fEntry = other.fEntry; |
92 | fFreshBufferOnly = other.fFreshBufferOnly; |
93 | fInputHandler = other.fInputHandler; |
94 | fOutputAOD = other.fOutputAOD; |
95 | fTreeA = other.fTreeA; |
3c329509 |
96 | fOfflineTriggerMask = other.fOfflineTriggerMask; |
b81460ad |
97 | return *this; |
98 | } |
99 | |
100 | |
101 | void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/) |
102 | { |
103 | // Connect the input data |
104 | if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n"); |
105 | // |
106 | // Multi AOD |
107 | // |
cd17c2ba |
108 | fInputHandler = dynamic_cast<AliMultiEventInputHandler*> |
b81460ad |
109 | ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler()); |
94d4e23c |
110 | if (fInputHandler == 0) { |
cd17c2ba |
111 | AliFatal("Event Handler has to be MultiEventInputHandler !"); |
94d4e23c |
112 | } else { |
113 | // Check that we have an event pool |
114 | if (!fInputHandler->GetEventPool()) { |
115 | fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool()); |
116 | if (!fInputHandler->GetEventPool()) |
cd17c2ba |
117 | AliFatal("MultiEventInputHandler has no EventPool connected !"); |
94d4e23c |
118 | } |
119 | } |
b81460ad |
120 | } |
121 | |
122 | void AliAnalysisTaskME::CreateOutputObjects() |
123 | { |
124 | // Create the output container |
125 | // |
126 | // Default AOD |
127 | if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n"); |
128 | |
129 | AliAODHandler* handler = (AliAODHandler*) |
130 | ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler()); |
131 | |
132 | if (handler) { |
133 | fOutputAOD = handler->GetAOD(); |
134 | fTreeA = handler->GetTree(); |
135 | } else { |
136 | AliWarning("No AOD Event Handler connected.") ; |
137 | } |
138 | UserCreateOutputObjects(); |
139 | } |
140 | |
141 | void AliAnalysisTaskME::Exec(Option_t* option) |
142 | { |
143 | // |
144 | // Exec analysis of one event |
e7d9460a |
145 | |
b81460ad |
146 | if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n"); |
147 | if( fInputHandler ) |
148 | fEntry = fInputHandler->GetReadEntry(); |
149 | if ( !((Entry()-1)%100) && fDebug > 0) |
150 | AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry())); |
15917707 |
151 | |
152 | AliAODHandler* outputHandler = (AliAODHandler*) |
153 | ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler()); |
3c329509 |
154 | // |
155 | // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG) |
156 | UInt_t isSelected = AliVEvent::kAny; |
157 | if( fInputHandler && fInputHandler->GetEventSelection()) { |
158 | // Get the actual offline trigger mask for the event and AND it with the |
159 | // requested mask. If no mask requested select by default the event. |
160 | if (fOfflineTriggerMask) |
161 | isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected(); |
162 | } |
163 | if (!isSelected) { |
164 | if (fDebug > 1) AliInfo("Event rejected \n"); |
165 | fInputHandler->EventSkipped(); |
166 | return; |
167 | } |
b81460ad |
168 | // Call the user analysis |
3c329509 |
169 | |
b81460ad |
170 | if (fInputHandler->IsBufferReady()) { |
171 | if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly) |
172 | { |
cd17c2ba |
173 | if (outputHandler) outputHandler->SetFillAOD(kTRUE); |
b81460ad |
174 | UserExec(option); |
175 | PostData(0, fTreeA); |
15917707 |
176 | } else { |
cd17c2ba |
177 | if (outputHandler) outputHandler->SetFillAOD(kFALSE); |
b81460ad |
178 | } |
e7d9460a |
179 | } else { |
180 | AliInfo(Form("Waiting for buffer to be ready !\n")); |
b81460ad |
181 | } |
182 | } |
183 | |
184 | const char* AliAnalysisTaskME::CurrentFileName() |
185 | { |
186 | // Returns the current file name |
187 | if(fInputHandler ) |
188 | return fInputHandler->GetTree()->GetCurrentFile()->GetName(); |
189 | else return ""; |
190 | } |
191 | |
c8fe2783 |
192 | void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname) |
b81460ad |
193 | { |
194 | // Add a new branch to the aod tree |
195 | AliAODHandler* handler = (AliAODHandler*) |
196 | ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler()); |
197 | if (handler) { |
c8fe2783 |
198 | handler->AddBranch(cname, addobj, fname); |
b81460ad |
199 | } |
200 | } |
201 | |
cd17c2ba |
202 | AliVEvent* AliAnalysisTaskME::GetEvent(Int_t iev) |
b81460ad |
203 | { |
204 | // Get an event from the input handler |
205 | return (fInputHandler->GetEvent(iev)); |
206 | } |
207 | |