]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTaskME.cxx
Consider physics selection when building the buffer.
[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 "AliVEvent.h"
29 #include "AliAODHandler.h"
30 #include "AliMultiEventInputHandler.h"
31 #include "AliLog.h"
32
33
34 ClassImp(AliAnalysisTaskME);
35
36 ////////////////////////////////////////////////////////////////////////
37
38 AliAnalysisTaskME::AliAnalysisTaskME():
39     AliAnalysisTask(),
40     fDebug(0),
41     fEntry(0),
42     fFreshBufferOnly(kFALSE),
43     fInputHandler(0x0),
44     fOutputAOD(0x0),
45     fTreeA(0x0),
46     fOfflineTriggerMask(0)
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),
58     fTreeA(0x0),
59     fOfflineTriggerMask(0)
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),
73     fTreeA(0x0),
74     fOfflineTriggerMask(0)
75 {
76 // Copy constructor
77     fDebug        = obj.fDebug;
78     fEntry        = obj.fEntry;
79     fInputHandler = obj.fInputHandler;
80     fOutputAOD    = obj.fOutputAOD;
81     fTreeA        = obj.fTreeA; 
82     fOfflineTriggerMask = obj.fOfflineTriggerMask;
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;    
96     fOfflineTriggerMask = other.fOfflineTriggerMask;
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 //
108     fInputHandler = dynamic_cast<AliMultiEventInputHandler*> 
109         ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
110     if (fInputHandler == 0) {
111         AliFatal("Event Handler has to be MultiEventInputHandler !");
112     } else {
113         // Check that we have an event pool
114         if (!fInputHandler->GetEventPool()) {
115             fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
116             if (!fInputHandler->GetEventPool()) 
117                 AliFatal("MultiEventInputHandler has no EventPool connected !");
118         }
119     }
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
145
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()));
151
152     AliAODHandler* outputHandler = (AliAODHandler*) 
153         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());         
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     }
168 // Call the user analysis    
169     
170     if (fInputHandler->IsBufferReady()) {
171         if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
172         {
173             if (outputHandler) outputHandler->SetFillAOD(kTRUE);
174             UserExec(option);
175             PostData(0, fTreeA);
176         } else {
177             if (outputHandler) outputHandler->SetFillAOD(kFALSE);
178         }
179     } else {
180         AliInfo(Form("Waiting for buffer to be ready !\n"));
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
192 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
193 {
194     // Add a new branch to the aod tree
195     AliAODHandler* handler = (AliAODHandler*) 
196         ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
197     if (handler) {
198         handler->AddBranch(cname, addobj, fname);
199     }
200 }
201
202 AliVEvent*  AliAnalysisTaskME::GetEvent(Int_t iev)
203 {
204     // Get an event from the input handler
205     return (fInputHandler->GetEvent(iev));
206 }
207