]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODInputHandler.cxx
Fix for Coverity 14218
[u/mrichter/AliRoot.git] / STEER / AliAODInputHandler.cxx
CommitLineData
397596ed 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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//-------------------------------------------------------------------------
19// Event handler for AOD input
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
3ba74948 23#include <TSystem.h>
933fd60f 24#include <TTree.h>
26772015 25#include <TList.h>
26#include <TNamed.h>
fb0cfe69 27#include <TFile.h>
70908d05 28#include <TH2.h>
397596ed 29
30#include "AliAODInputHandler.h"
31#include "AliAODEvent.h"
70908d05 32#include "AliVCuts.h"
5e6a3170 33#include "AliMCEvent.h"
9006fe9c 34#include "AliAODpidUtil.h"
397596ed 35
36ClassImp(AliAODInputHandler)
37
c2b6979d 38static Option_t *gAODDataType = "AOD";
39
397596ed 40//______________________________________________________________________________
41AliAODInputHandler::AliAODInputHandler() :
90e04a88 42 AliInputEventHandler(),
4195c9c9 43 fEvent(0),
04a79fa0 44 fMCEvent(new AliMCEvent()),
1f842495 45 fFriends(new TList()),
9006fe9c 46 fAODpidUtil(0x0),
1f842495 47 fMergeEvents(kFALSE),
25c90fa8 48 fFriendsConnected(kFALSE),
1f842495 49 fFileToMerge(0),
50 fTreeToMerge(0),
04daa8bf 51 fAODEventToMerge(0),
52 fMergeOffset(0)
397596ed 53{
26772015 54 // Default constructor
70908d05 55 fHistStatistics[0] = fHistStatistics[1] = NULL;
397596ed 56}
57
58//______________________________________________________________________________
26772015 59AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
60 AliInputEventHandler(name, title),
61 fEvent(0),
04a79fa0 62 fMCEvent(new AliMCEvent()),
1f842495 63 fFriends(new TList()),
9006fe9c 64 fAODpidUtil(0x0),
1f842495 65 fMergeEvents(kFALSE),
25c90fa8 66 fFriendsConnected(kFALSE),
1f842495 67 fFileToMerge(0),
68 fTreeToMerge(0),
04daa8bf 69 fAODEventToMerge(0),
70 fMergeOffset(0)
397596ed 71{
26772015 72 // Constructor
70908d05 73 fHistStatistics[0] = fHistStatistics[1] = NULL;
397596ed 74}
75
76//______________________________________________________________________________
26772015 77AliAODInputHandler::~AliAODInputHandler()
397596ed 78{
26772015 79// Destructor
70908d05 80 fFriends->Delete();
81 if (fHistStatistics[0]) {
82 delete fHistStatistics[0];
83 fHistStatistics[0] = 0;
84 }
85 if (fHistStatistics[1]) {
86 delete fHistStatistics[1];
87 fHistStatistics[1] = 0;
88 }
9006fe9c 89 delete fAODpidUtil;
397596ed 90}
91
70908d05 92//______________________________________________________________________________
b890a10d 93Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* opt)
397596ed 94{
300d5701 95 // Initialisation necessary for each new tree
70908d05 96 fTree = tree;
70908d05 97 if (!fTree) return kFALSE;
32e5a29c 98 fTree->GetEntries();
25c90fa8 99 ConnectFriends();
d329cad3 100
25c90fa8 101 SwitchOffBranches();
102 SwitchOnBranches();
4195c9c9 103
25c90fa8 104 // Get pointer to AOD event
105 if (!fEvent) fEvent = new AliAODEvent();
106
107 fEvent->ReadFromTree(fTree);
108
109 if (fMixingHandler) fMixingHandler->Init(tree, opt);
110
111 return kTRUE;
397596ed 112}
113
70908d05 114//______________________________________________________________________________
1f842495 115Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
fbb264e0 116{
5e6a3170 117 // Begin event
04a79fa0 118 TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
119 if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
04daa8bf 120 if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
1f842495 121
0c6c629b 122 fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
b890a10d 123
124 if (fMixingHandler) fMixingHandler->BeginEvent(entry);
0c6c629b 125
fbb264e0 126 return kTRUE;
127}
128
70908d05 129//______________________________________________________________________________
b890a10d 130Bool_t AliAODInputHandler::Notify(const char* path)
131{
132 // Notifaction of directory change
133 if (fMixingHandler) fMixingHandler->Notify(path);
25c90fa8 134 if (!fFriendsConnected) {
135 ConnectFriends();
136 fEvent->ReadFromTree(fTree, "reconnect");
137 }
138 fFriendsConnected = kFALSE;
139
70908d05 140 TTree *ttree = fTree->GetTree();
141 if (!ttree) ttree = fTree;
f4de59f4 142 TString statFname(ttree->GetCurrentFile()->GetName());
143 Int_t indarchive = statFname.Index("#");
144 if (indarchive<0) {
145 statFname = gSystem->DirName(statFname);
146 statFname += "/";
147 } else {
148 statFname.Remove(indarchive+1);
149 }
150 statFname += "EventStat_temp.root";
151 TFile *statFile = 0;
152 if (IsCheckStatistics()) statFile = TFile::Open(statFname, "READ");
70908d05 153 if (statFile) {
154 TList *list = (TList*)statFile->Get("cstatsout");
155 if (list) {
156 AliVCuts *physSel = (AliVCuts*)list->At(0);
157 if (physSel) {
158 TH2F *hAll = dynamic_cast<TH2F*>(physSel->GetStatistics("ALL"));
159 TH2F *hBin0 = dynamic_cast<TH2F*>(physSel->GetStatistics("BIN0"));
160 if (fHistStatistics[0] && hAll) {
161 TList tmplist;
162 tmplist.Add(hAll);
163 fHistStatistics[0]->Merge(&tmplist);
164 tmplist.Clear();
165 tmplist.Add(hBin0);
166 if (fHistStatistics[1] && hBin0) fHistStatistics[1]->Merge(&tmplist);
167 } else {
3ba74948 168 fHistStatistics[0] = static_cast<TH2F*>(hAll->Clone());
169 fHistStatistics[1] = static_cast<TH2F*>(hBin0->Clone());
170 fHistStatistics[0]->SetDirectory(0);
171 fHistStatistics[1]->SetDirectory(0);
70908d05 172 }
173 }
3ba74948 174 delete list;
70908d05 175 }
b8047d30 176 delete statFile;
70908d05 177 }
b890a10d 178 return kTRUE;
179}
180
70908d05 181//______________________________________________________________________________
b890a10d 182Bool_t AliAODInputHandler::FinishEvent()
183{
184 // Finish event
185 if (fMixingHandler) fMixingHandler->FinishEvent();
186 return kTRUE;
187}
188
70908d05 189//______________________________________________________________________________
26772015 190void AliAODInputHandler::AddFriend(char* filename)
191{
192 // Add a friend tree
193 TNamed* obj = new TNamed(filename, filename);
194 fFriends->Add(obj);
195}
c2b6979d 196
70908d05 197//______________________________________________________________________________
c2b6979d 198Option_t *AliAODInputHandler::GetDataType() const
199{
200// Returns handled data type.
201 return gAODDataType;
202}
70908d05 203
204//______________________________________________________________________________
205TObject *AliAODInputHandler::GetStatistics(Option_t *option) const
206{
207// Get the statistics histogram(s) from the physics selection object. This
208// should be called during FinishTaskOutput(). Option can be empty (default
209// statistics histogram) or BIN0.
210 TString opt(option);
211 opt.ToUpper();
212 if (opt=="BIN0") return fHistStatistics[1];
213 return fHistStatistics[0];
214}
25c90fa8 215
216void AliAODInputHandler::ConnectFriends()
217{
218 // Connect the friend trees
219 if (!fMergeEvents) {
220 TIter next(fFriends);
221 TNamed* obj;
222 TString aodTreeFName,aodFriendTreeFName;
223 TTree *ttree = fTree->GetTree();
224 if (!ttree) ttree = fTree;
225 aodTreeFName = ttree->GetCurrentFile()->GetName();
226
227 while((obj = (TNamed*)next())) {
228 aodFriendTreeFName = aodTreeFName;
229 aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
230 aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
231 ttree->AddFriend("aodTree", aodFriendTreeFName.Data());
232 }
233 } else {
234 // Friends have to be merged
235 TNamed* filename = (TNamed*) (fFriends->At(0));
236 fFileToMerge = new TFile(filename->GetName());
237 if (fFileToMerge) {
238 fFileToMerge->GetObject("aodTree", fTreeToMerge);
239 if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
240 fAODEventToMerge->ReadFromTree(fTreeToMerge);
241 }
242 }
243 fFriendsConnected = kTRUE;
244}
245
9006fe9c 246//______________________________________________________________________________
247void AliAODInputHandler::CreatePIDResponse(Bool_t isMC/*=kFALSE*/)
248{
249 //
250 // create the pid response object if it does not exist yet
251 //
252 if (fAODpidUtil) return;
253 fAODpidUtil=new AliAODpidUtil(isMC);
254
255}
256