]>
Commit | Line | Data |
---|---|---|
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 | ||
31 | ClassImp(AliAODInputHandler) | |
32 | ||
c2b6979d | 33 | static Option_t *gAODDataType = "AOD"; |
34 | ||
397596ed | 35 | //______________________________________________________________________________ |
36 | AliAODInputHandler::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), | |
44 | fAODEventToMerge(0) | |
397596ed | 45 | { |
26772015 | 46 | // Default constructor |
397596ed | 47 | } |
48 | ||
49 | //______________________________________________________________________________ | |
26772015 | 50 | AliAODInputHandler::AliAODInputHandler(const char* name, const char* title): |
51 | AliInputEventHandler(name, title), | |
52 | fEvent(0), | |
04a79fa0 | 53 | fMCEvent(new AliMCEvent()), |
1f842495 | 54 | fFriends(new TList()), |
55 | fMergeEvents(kFALSE), | |
56 | fFileToMerge(0), | |
57 | fTreeToMerge(0), | |
58 | fAODEventToMerge(0) | |
397596ed | 59 | { |
26772015 | 60 | // Constructor |
397596ed | 61 | } |
62 | ||
63 | //______________________________________________________________________________ | |
26772015 | 64 | AliAODInputHandler::~AliAODInputHandler() |
397596ed | 65 | { |
26772015 | 66 | // Destructor |
67 | fFriends->Delete(); | |
397596ed | 68 | } |
69 | ||
26772015 | 70 | |
300d5701 | 71 | Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* /*opt*/) |
397596ed | 72 | { |
300d5701 | 73 | // Initialisation necessary for each new tree |
1f842495 | 74 | if (!fMergeEvents) { |
75 | fTree = tree; | |
76 | TIter next(fFriends); | |
77 | TNamed* obj; | |
78 | ||
79 | if (!fTree) return kFALSE; | |
80 | fTree->GetEntry(0); | |
81 | TString aodTreeFName,aodFriendTreeFName; | |
82 | ||
83 | while((obj = (TNamed*)next())) { | |
84 | if (fTree->GetTree()) { | |
85 | aodTreeFName = (fTree->GetTree()->GetCurrentFile())->GetName(); | |
86 | aodFriendTreeFName = aodTreeFName; | |
87 | aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName()); | |
88 | aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName()); | |
89 | (fTree->GetTree())->AddFriend("aodTree", aodFriendTreeFName.Data()); | |
90 | } else { | |
91 | aodTreeFName = (fTree->GetCurrentFile())->GetName(); | |
92 | aodFriendTreeFName = aodTreeFName; | |
93 | aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName()); | |
94 | aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName()); | |
95 | fTree->AddFriend("aodTree", aodFriendTreeFName.Data()); | |
96 | } | |
97 | } | |
98 | } else { | |
99 | // Friends have to be merged | |
100 | TNamed* filename = (TNamed*) (fFriends->At(0)); | |
101 | fFileToMerge = new TFile(filename->GetName()); | |
102 | if (fFileToMerge) { | |
103 | fFileToMerge->GetObject("aodTree", fTreeToMerge); | |
104 | if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent(); | |
105 | fAODEventToMerge->ReadFromTree(fTreeToMerge); | |
ced57103 | 106 | } |
4195c9c9 | 107 | } |
1f842495 | 108 | |
109 | ||
d329cad3 | 110 | |
111 | ||
112 | SwitchOffBranches(); | |
113 | SwitchOnBranches(); | |
4195c9c9 | 114 | |
397596ed | 115 | // Get pointer to AOD event |
316cf4cc | 116 | if (!fEvent) fEvent = new AliAODEvent(); |
300d5701 | 117 | |
933fd60f | 118 | fEvent->ReadFromTree(fTree); |
04a79fa0 | 119 | |
397596ed | 120 | return kTRUE; |
121 | } | |
122 | ||
1f842495 | 123 | Bool_t AliAODInputHandler::BeginEvent(Long64_t entry) |
fbb264e0 | 124 | { |
125 | // | |
04a79fa0 | 126 | TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles")); |
127 | if (mcParticles) fMCEvent->SetParticleArray(mcParticles); | |
1f842495 | 128 | if (fTreeToMerge) fTreeToMerge->GetEntry(entry); |
129 | ||
fbb264e0 | 130 | return kTRUE; |
131 | } | |
132 | ||
26772015 | 133 | void AliAODInputHandler::AddFriend(char* filename) |
134 | { | |
135 | // Add a friend tree | |
136 | TNamed* obj = new TNamed(filename, filename); | |
137 | fFriends->Add(obj); | |
138 | } | |
c2b6979d | 139 | |
140 | Option_t *AliAODInputHandler::GetDataType() const | |
141 | { | |
142 | // Returns handled data type. | |
143 | return gAODDataType; | |
144 | } |