1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Event handler for AOD input
20 // Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
28 #include "AliAODInputHandler.h"
29 #include "AliAODEvent.h"
31 ClassImp(AliAODInputHandler)
33 static Option_t *gAODDataType = "AOD";
35 //______________________________________________________________________________
36 AliAODInputHandler::AliAODInputHandler() :
37 AliInputEventHandler(),
39 fMCEvent(new AliMCEvent()),
40 fFriends(new TList()),
47 // Default constructor
50 //______________________________________________________________________________
51 AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
52 AliInputEventHandler(name, title),
54 fMCEvent(new AliMCEvent()),
55 fFriends(new TList()),
65 //______________________________________________________________________________
66 AliAODInputHandler::~AliAODInputHandler()
73 Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* /*opt*/)
75 // Initialisation necessary for each new tree
81 if (!fTree) return kFALSE;
83 TString aodTreeFName,aodFriendTreeFName;
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());
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());
101 // Friends have to be merged
102 TNamed* filename = (TNamed*) (fFriends->At(0));
103 fFileToMerge = new TFile(filename->GetName());
105 fFileToMerge->GetObject("aodTree", fTreeToMerge);
106 if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
107 fAODEventToMerge->ReadFromTree(fTreeToMerge);
117 // Get pointer to AOD event
118 if (!fEvent) fEvent = new AliAODEvent();
120 fEvent->ReadFromTree(fTree);
125 Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
128 TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
129 if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
130 if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
135 void AliAODInputHandler::AddFriend(char* filename)
138 TNamed* obj = new TNamed(filename, filename);
142 Option_t *AliAODInputHandler::GetDataType() const
144 // Returns handled data type.