Extending the functionality of the physics selection. Instead of providing a yes...
[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
300d5701 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);
04a79fa0 121
397596ed 122 return kTRUE;
123}
124
1f842495 125Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
fbb264e0 126{
127 //
04a79fa0 128 TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
129 if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
04daa8bf 130 if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
1f842495 131
0c6c629b 132 fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
133
fbb264e0 134 return kTRUE;
135}
136
26772015 137void AliAODInputHandler::AddFriend(char* filename)
138{
139 // Add a friend tree
140 TNamed* obj = new TNamed(filename, filename);
141 fFriends->Add(obj);
142}
c2b6979d 143
144Option_t *AliAODInputHandler::GetDataType() const
145{
146// Returns handled data type.
147 return gAODDataType;
148}