]>
Commit | Line | Data |
---|---|---|
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 ESD input | |
20 | // Author: Andreas Morsch, CERN | |
21 | //------------------------------------------------------------------------- | |
22 | ||
23 | #include <TTree.h> | |
24 | #include <TChain.h> | |
25 | #include <TFile.h> | |
26 | #include <TArchiveFile.h> | |
27 | #include <TObjArray.h> | |
28 | #include <TSystem.h> | |
29 | #include <TString.h> | |
30 | #include <TObjString.h> | |
31 | #include <TProcessID.h> | |
32 | ||
33 | #include "AliESDInputHandler.h" | |
34 | #include "AliESDEvent.h" | |
35 | #include "AliESD.h" | |
36 | #include "AliRunTag.h" | |
37 | #include "AliEventTag.h" | |
38 | #include "AliLog.h" | |
39 | ||
40 | ClassImp(AliESDInputHandler) | |
41 | ||
42 | static Option_t *gESDDataType = "ESD"; | |
43 | ||
44 | //______________________________________________________________________________ | |
45 | AliESDInputHandler::AliESDInputHandler() : | |
46 | AliInputEventHandler(), | |
47 | fEvent(0x0), | |
48 | fAnalysisType(0), | |
49 | fNEvents(0), | |
50 | fHLTEvent(0x0), | |
51 | fHLTTree(0x0), | |
52 | fUseHLT(kFALSE), | |
53 | fUseTags(kFALSE), | |
54 | fChainT(0), | |
55 | fTreeT(0), | |
56 | fRunTag(0) | |
57 | { | |
58 | // default constructor | |
59 | } | |
60 | ||
61 | //______________________________________________________________________________ | |
62 | AliESDInputHandler::~AliESDInputHandler() | |
63 | { | |
64 | // destructor | |
65 | // delete fEvent; | |
66 | } | |
67 | ||
68 | //______________________________________________________________________________ | |
69 | AliESDInputHandler::AliESDInputHandler(const char* name, const char* title): | |
70 | AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0), | |
71 | fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0) | |
72 | { | |
73 | // Constructor | |
74 | } | |
75 | ||
76 | Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt) | |
77 | { | |
78 | // Initialisation necessary for each new tree | |
79 | fAnalysisType = opt; | |
80 | fTree = tree; | |
81 | ||
82 | if (!fTree) return kFALSE; | |
83 | fTree->GetEntry(0); | |
84 | ||
85 | // Get pointer to ESD event | |
86 | SwitchOffBranches(); | |
87 | SwitchOnBranches(); | |
88 | ||
89 | if (!fEvent) fEvent = new AliESDEvent(); | |
90 | fEvent->ReadFromTree(fTree); | |
91 | fNEvents = fTree->GetEntries(); | |
92 | ||
93 | ||
94 | return kTRUE; | |
95 | } | |
96 | ||
97 | Bool_t AliESDInputHandler::BeginEvent(Long64_t entry) | |
98 | { | |
99 | // Copy from old to new format if necessary | |
100 | AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld(); | |
101 | if (old) { | |
102 | ((AliESDEvent*)fEvent)->CopyFromOldESD(); | |
103 | old->Reset(); | |
104 | } | |
105 | ||
106 | if (fHLTTree) { | |
107 | fHLTTree->GetEntry(entry); | |
108 | } | |
109 | ||
110 | return kTRUE; | |
111 | } | |
112 | ||
113 | Bool_t AliESDInputHandler::FinishEvent() | |
114 | { | |
115 | // Finish the event | |
116 | if(fEvent)fEvent->Reset(); | |
117 | return kTRUE; | |
118 | } | |
119 | ||
120 | Bool_t AliESDInputHandler::Notify(const char* path) | |
121 | { | |
122 | // Notify a directory change | |
123 | AliInfo(Form("Directory change %s \n", path)); | |
124 | // | |
125 | if (fUseHLT) { | |
126 | // Get HLTesdTree from current file | |
127 | TTree* cTree = fTree; | |
128 | if (fTree->GetTree()) cTree = fTree->GetTree(); | |
129 | TFile* cFile = cTree->GetCurrentFile(); | |
130 | cFile->GetObject("HLTesdTree", fHLTTree); | |
131 | ||
132 | if (fHLTTree) { | |
133 | if (!fHLTEvent) fHLTEvent = new AliESDEvent(); | |
134 | fHLTEvent->ReadFromTree(fHLTTree); | |
135 | } | |
136 | } | |
137 | ||
138 | if (!fUseTags) return (kTRUE); | |
139 | ||
140 | Bool_t zip = kFALSE; | |
141 | ||
142 | TString fileName(path); | |
143 | if(fileName.Contains("#AliESDs.root")){ | |
144 | zip = kTRUE; | |
145 | } | |
146 | else if (fileName.Contains("AliESDs.root")){ | |
147 | fileName.ReplaceAll("AliESDs.root", ""); | |
148 | } | |
149 | else if(fileName.Contains("#AliAOD.root")){ | |
150 | zip = kTRUE; | |
151 | } | |
152 | else if(fileName.Contains("AliAOD.root")){ | |
153 | fileName.ReplaceAll("AliAOD.root", ""); | |
154 | } | |
155 | else if(fileName.Contains("#galice.root")){ | |
156 | // For running with galice and kinematics alone... | |
157 | zip = kTRUE; | |
158 | } | |
159 | else if(fileName.Contains("galice.root")){ | |
160 | // For running with galice and kinematics alone... | |
161 | fileName.ReplaceAll("galice.root", ""); | |
162 | } | |
163 | ||
164 | ||
165 | TString pathName("./"); | |
166 | if (fileName.Length() != 0) { | |
167 | pathName = fileName; | |
168 | } | |
169 | ||
170 | printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data()); | |
171 | ||
172 | if (fRunTag) { | |
173 | fRunTag->Clear(); | |
174 | } else { | |
175 | fRunTag = new AliRunTag(); | |
176 | } | |
177 | ||
178 | delete fTreeT; fTreeT = 0; | |
179 | ||
180 | if (fChainT) { | |
181 | delete fChainT; | |
182 | fChainT = 0; | |
183 | } | |
184 | ||
185 | if (!fChainT) { | |
186 | fChainT = new TChain("T"); | |
187 | } | |
188 | ||
189 | ||
190 | ||
191 | const char* tagPattern = "ESD.tag.root"; | |
192 | const char* name = 0x0; | |
193 | TString tagFilename; | |
194 | if (zip) { | |
195 | TFile* file = fTree->GetCurrentFile(); | |
196 | TArchiveFile* arch = file->GetArchive(); | |
197 | TObjArray* arr = arch->GetMembers(); | |
198 | TIter next(arr); | |
199 | ||
200 | while ((file = (TFile*) next())) { | |
201 | name = file->GetName(); | |
202 | if (strstr(name,tagPattern)) { | |
203 | tagFilename = pathName.Data(); | |
204 | tagFilename += "#"; | |
205 | tagFilename += name; | |
206 | fChainT->Add(tagFilename); | |
207 | AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data())); | |
208 | }//pattern check | |
209 | } // archive file loop | |
210 | } else { | |
211 | void * dirp = gSystem->OpenDirectory(pathName.Data()); | |
212 | while((name = gSystem->GetDirEntry(dirp))) { | |
213 | if (strstr(name,tagPattern)) { | |
214 | tagFilename = pathName.Data(); | |
215 | tagFilename += "/"; | |
216 | tagFilename += name; | |
217 | fChainT->Add(tagFilename); | |
218 | AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data())); | |
219 | }//pattern check | |
220 | }//directory loop | |
221 | } | |
222 | fChainT->SetBranchAddress("AliTAG",&fRunTag); | |
223 | fChainT->GetEntry(0); | |
224 | return kTRUE; | |
225 | } | |
226 | ||
227 | ||
228 | ||
229 | Option_t *AliESDInputHandler::GetDataType() const | |
230 | { | |
231 | // Returns handled data type. | |
232 | return gESDDataType; | |
233 | } |