]>
Commit | Line | Data |
---|---|---|
ec4af4c1 | 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 | // Implementation of the Virtual Event Handler Interface for AOD | |
20 | // Author: Andreas Morsch, CERN | |
21 | //------------------------------------------------------------------------- | |
22 | ||
052994fb | 23 | |
ec4af4c1 | 24 | #include <TTree.h> |
e910dd36 | 25 | #include <TFile.h> |
7970f4ac | 26 | #include <TString.h> |
e910dd36 | 27 | |
ec4af4c1 | 28 | #include "AliAODHandler.h" |
29 | #include "AliAODEvent.h" | |
30 | ||
31 | ClassImp(AliAODHandler) | |
32 | ||
33 | //______________________________________________________________________________ | |
34 | AliAODHandler::AliAODHandler() : | |
f3214a54 | 35 | AliVEventHandler(), |
78f7f935 | 36 | fIsStandard(kTRUE), |
ec4af4c1 | 37 | fAODEvent(NULL), |
e910dd36 | 38 | fTreeA(NULL), |
39 | fFileA(NULL), | |
7970f4ac | 40 | fFileName("") |
ec4af4c1 | 41 | { |
42 | // default constructor | |
43 | } | |
44 | ||
45 | //______________________________________________________________________________ | |
46 | AliAODHandler::AliAODHandler(const char* name, const char* title): | |
f3214a54 | 47 | AliVEventHandler(name, title), |
78f7f935 | 48 | fIsStandard(kTRUE), |
ec4af4c1 | 49 | fAODEvent(NULL), |
e910dd36 | 50 | fTreeA(NULL), |
51 | fFileA(NULL), | |
7970f4ac | 52 | fFileName("") |
ec4af4c1 | 53 | { |
54 | } | |
55 | ||
56 | //______________________________________________________________________________ | |
57 | AliAODHandler::~AliAODHandler() | |
58 | { | |
6989bff3 | 59 | delete fAODEvent; |
60 | if(fFileA){ | |
61 | // is already handled in TerminateIO | |
62 | fFileA->Close(); | |
63 | delete fFileA; | |
64 | } | |
65 | delete fTreeA; | |
6989bff3 | 66 | // destructor |
ec4af4c1 | 67 | } |
68 | ||
7970f4ac | 69 | //______________________________________________________________________________ |
300d5701 | 70 | Bool_t AliAODHandler::Init(Option_t* opt) |
ec4af4c1 | 71 | { |
6989bff3 | 72 | // Initialize IO |
73 | // | |
74 | // Create the AODevent object | |
75 | if(!fAODEvent){ | |
ec4af4c1 | 76 | fAODEvent = new AliAODEvent(); |
78f7f935 | 77 | if (fIsStandard) fAODEvent->CreateStdContent(); |
6989bff3 | 78 | } |
79 | // | |
80 | // File opening according to execution mode | |
7970f4ac | 81 | TString option(opt); |
82 | option.ToLower(); | |
83 | if (option.Contains("proof")) { | |
6989bff3 | 84 | // proof |
7970f4ac | 85 | if (option.Contains("special")) { |
86 | // File for tree already opened on slave -> merging via files | |
87 | fFileA = gFile; | |
88 | CreateTree(1); | |
89 | } else { | |
90 | // Merging in memory | |
91 | CreateTree(0); | |
92 | } | |
6989bff3 | 93 | } else { |
94 | // local and grid | |
26b9ac7a | 95 | TDirectory *owd = gDirectory; |
7970f4ac | 96 | fFileA = new TFile(fFileName.Data(), "RECREATE"); |
6989bff3 | 97 | CreateTree(1); |
26b9ac7a | 98 | owd->cd(); |
6989bff3 | 99 | } |
100 | return kTRUE; | |
ec4af4c1 | 101 | } |
102 | ||
5f380da9 | 103 | Bool_t AliAODHandler::FinishEvent() |
ec4af4c1 | 104 | { |
105 | // Fill data structures | |
f4e5f8d5 | 106 | fAODEvent->MakeEntriesReferencable(); |
ec4af4c1 | 107 | FillTree(); |
78f7f935 | 108 | if (fIsStandard) fAODEvent->ResetStd(); |
ec4af4c1 | 109 | return kTRUE; |
110 | } | |
111 | ||
7970f4ac | 112 | //______________________________________________________________________________ |
ec4af4c1 | 113 | Bool_t AliAODHandler::Terminate() |
114 | { | |
115 | // Terminate | |
116 | AddAODtoTreeUserInfo(); | |
117 | return kTRUE; | |
118 | } | |
119 | ||
7970f4ac | 120 | //______________________________________________________________________________ |
ec4af4c1 | 121 | Bool_t AliAODHandler::TerminateIO() |
122 | { | |
123 | // Terminate IO | |
21501411 | 124 | if (fFileA) { |
125 | fFileA->Close(); | |
126 | delete fFileA; | |
127 | } | |
ec4af4c1 | 128 | return kTRUE; |
129 | } | |
130 | ||
7970f4ac | 131 | //______________________________________________________________________________ |
954526ed | 132 | void AliAODHandler::CreateTree(Int_t flag) |
ec4af4c1 | 133 | { |
134 | // Creates the AOD Tree | |
f3214a54 | 135 | fTreeA = new TTree("aodTree", "AliAOD tree"); |
ec4af4c1 | 136 | fTreeA->Branch(fAODEvent->GetList()); |
954526ed | 137 | if (flag == 0) fTreeA->SetDirectory(0); |
ec4af4c1 | 138 | } |
139 | ||
7970f4ac | 140 | //______________________________________________________________________________ |
ec4af4c1 | 141 | void AliAODHandler::FillTree() |
142 | { | |
143 | // Fill the AOD Tree | |
144 | fTreeA->Fill(); | |
145 | } | |
146 | ||
7970f4ac | 147 | //______________________________________________________________________________ |
ec4af4c1 | 148 | void AliAODHandler::AddAODtoTreeUserInfo() |
149 | { | |
150 | // Add aod event to tree user info | |
151 | fTreeA->GetUserInfo()->Add(fAODEvent); | |
152 | } | |
490e9023 | 153 | |
7970f4ac | 154 | //______________________________________________________________________________ |
0134949d | 155 | void AliAODHandler::AddBranch(const char* cname, void* addobj) |
490e9023 | 156 | { |
157 | // Add a new branch to the aod | |
158 | TDirectory *owd = gDirectory; | |
159 | if (fFileA) { | |
160 | fFileA->cd(); | |
161 | } | |
0134949d | 162 | char** apointer = (char**) addobj; |
163 | TObject* obj = (TObject*) *apointer; | |
164 | fTreeA->Branch(obj->GetName(), cname, addobj); | |
165 | fAODEvent->AddObject(obj); | |
490e9023 | 166 | owd->cd(); |
167 | } | |
7970f4ac | 168 | |
169 | //______________________________________________________________________________ | |
170 | void AliAODHandler::SetOutputFileName(const char* fname) | |
171 | { | |
172 | // Set file name. | |
173 | fFileName = fname; | |
174 | } | |
175 | ||
176 | //______________________________________________________________________________ | |
177 | const char *AliAODHandler::GetOutputFileName() | |
178 | { | |
179 | // Get file name. | |
180 | return fFileName.Data(); | |
181 | } |