Corrected protection.
[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
933fd60f 23#include <TTree.h>
26772015 24#include <TList.h>
25#include <TNamed.h>
fb0cfe69 26#include <TFile.h>
397596ed 27
28#include "AliAODInputHandler.h"
29#include "AliAODEvent.h"
30
31ClassImp(AliAODInputHandler)
32
c2b6979d 33static Option_t *gAODDataType = "AOD";
34
397596ed 35//______________________________________________________________________________
36AliAODInputHandler::AliAODInputHandler() :
90e04a88 37 AliInputEventHandler(),
4195c9c9 38 fEvent(0),
04a79fa0 39 fMCEvent(new AliMCEvent()),
1f842495 40 fFriends(new TList()),
41 fMergeEvents(kFALSE),
42 fFileToMerge(0),
43 fTreeToMerge(0),
04daa8bf 44 fAODEventToMerge(0),
45 fMergeOffset(0)
397596ed 46{
26772015 47 // Default constructor
397596ed 48}
49
50//______________________________________________________________________________
26772015 51AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
52 AliInputEventHandler(name, title),
53 fEvent(0),
04a79fa0 54 fMCEvent(new AliMCEvent()),
1f842495 55 fFriends(new TList()),
56 fMergeEvents(kFALSE),
57 fFileToMerge(0),
58 fTreeToMerge(0),
04daa8bf 59 fAODEventToMerge(0),
60 fMergeOffset(0)
397596ed 61{
26772015 62 // Constructor
397596ed 63}
64
65//______________________________________________________________________________
26772015 66AliAODInputHandler::~AliAODInputHandler()
397596ed 67{
26772015 68// Destructor
69 fFriends->Delete();
397596ed 70}
71
26772015 72
b890a10d 73Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* opt)
397596ed 74{
300d5701 75 // Initialisation necessary for each new tree
1f842495 76 if (!fMergeEvents) {
77 fTree = tree;
78 TIter next(fFriends);
79 TNamed* obj;
80
81 if (!fTree) return kFALSE;
82 fTree->GetEntry(0);
83 TString aodTreeFName,aodFriendTreeFName;
84
85 while((obj = (TNamed*)next())) {
86 if (fTree->GetTree()) {
87 aodTreeFName = (fTree->GetTree()->GetCurrentFile())->GetName();
88 aodFriendTreeFName = aodTreeFName;
89 aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
90 aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
91 (fTree->GetTree())->AddFriend("aodTree", aodFriendTreeFName.Data());
92 } else {
93 aodTreeFName = (fTree->GetCurrentFile())->GetName();
94 aodFriendTreeFName = aodTreeFName;
95 aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
96 aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
97 fTree->AddFriend("aodTree", aodFriendTreeFName.Data());
98 }
99 }
100 } else {
101 // Friends have to be merged
102 TNamed* filename = (TNamed*) (fFriends->At(0));
103 fFileToMerge = new TFile(filename->GetName());
104 if (fFileToMerge) {
105 fFileToMerge->GetObject("aodTree", fTreeToMerge);
106 if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
107 fAODEventToMerge->ReadFromTree(fTreeToMerge);
ced57103 108 }
4195c9c9 109 }
1f842495 110
111
d329cad3 112
113
114 SwitchOffBranches();
115 SwitchOnBranches();
4195c9c9 116
397596ed 117 // Get pointer to AOD event
316cf4cc 118 if (!fEvent) fEvent = new AliAODEvent();
300d5701 119
933fd60f 120 fEvent->ReadFromTree(fTree);
b890a10d 121
122 if (fMixingHandler) fMixingHandler->Init(tree, opt);
04a79fa0 123
397596ed 124 return kTRUE;
125}
126
1f842495 127Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
fbb264e0 128{
129 //
04a79fa0 130 TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
131 if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
04daa8bf 132 if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
1f842495 133
0c6c629b 134 fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
b890a10d 135
136 if (fMixingHandler) fMixingHandler->BeginEvent(entry);
0c6c629b 137
fbb264e0 138 return kTRUE;
139}
140
b890a10d 141Bool_t AliAODInputHandler::Notify(const char* path)
142{
143 // Notifaction of directory change
144 if (fMixingHandler) fMixingHandler->Notify(path);
145 return kTRUE;
146}
147
148Bool_t AliAODInputHandler::FinishEvent()
149{
150 // Finish event
151 if (fMixingHandler) fMixingHandler->FinishEvent();
152 return kTRUE;
153}
154
26772015 155void AliAODInputHandler::AddFriend(char* filename)
156{
157 // Add a friend tree
158 TNamed* obj = new TNamed(filename, filename);
159 fFriends->Add(obj);
160}
c2b6979d 161
162Option_t *AliAODInputHandler::GetDataType() const
163{
164// Returns handled data type.
165 return gAODDataType;
166}