]>
Commit | Line | Data |
---|---|---|
d3dd3d14 | 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 | ||
933fd60f | 23 | #include <TTree.h> |
1aa09fd1 | 24 | #include <TChain.h> |
25 | #include <TFile.h> | |
26 | #include <TArchiveFile.h> | |
27 | #include <TObjArray.h> | |
28 | #include <TSystem.h> | |
300d5701 | 29 | #include <TString.h> |
30 | #include <TObjString.h> | |
80e1b60a | 31 | #include <TProcessID.h> |
f0f29480 | 32 | #include <TMap.h> |
d3dd3d14 | 33 | |
34 | #include "AliESDInputHandler.h" | |
35 | #include "AliESDEvent.h" | |
36 | #include "AliESD.h" | |
1aa09fd1 | 37 | #include "AliRunTag.h" |
38 | #include "AliEventTag.h" | |
300d5701 | 39 | #include "AliLog.h" |
d3dd3d14 | 40 | |
41 | ClassImp(AliESDInputHandler) | |
42 | ||
c2b6979d | 43 | static Option_t *gESDDataType = "ESD"; |
44 | ||
d3dd3d14 | 45 | //______________________________________________________________________________ |
6989bff3 | 46 | AliESDInputHandler::AliESDInputHandler() : |
47 | AliInputEventHandler(), | |
0cd61c1d | 48 | fEvent(0x0), |
1aa09fd1 | 49 | fAnalysisType(0), |
4d2a7370 | 50 | fNEvents(0), |
6ccd727b | 51 | fHLTEvent(0x0), |
52 | fHLTTree(0x0), | |
53 | fUseHLT(kFALSE), | |
f0f29480 | 54 | fTagCutSumm(0x0), |
1aa09fd1 | 55 | fUseTags(kFALSE), |
56 | fChainT(0), | |
57 | fTreeT(0), | |
58 | fRunTag(0) | |
d3dd3d14 | 59 | { |
60 | // default constructor | |
61 | } | |
62 | ||
63 | //______________________________________________________________________________ | |
64 | AliESDInputHandler::~AliESDInputHandler() | |
65 | { | |
1aa09fd1 | 66 | // destructor |
6989bff3 | 67 | // delete fEvent; |
d3dd3d14 | 68 | } |
69 | ||
70 | //______________________________________________________________________________ | |
71 | AliESDInputHandler::AliESDInputHandler(const char* name, const char* title): | |
f16ba708 | 72 | AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0), |
f0f29480 | 73 | fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0) |
d3dd3d14 | 74 | { |
e12e402c | 75 | // Constructor |
d3dd3d14 | 76 | } |
77 | ||
1aa09fd1 | 78 | Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt) |
d3dd3d14 | 79 | { |
300d5701 | 80 | // Initialisation necessary for each new tree |
1aa09fd1 | 81 | fAnalysisType = opt; |
82 | fTree = tree; | |
300d5701 | 83 | |
6073f8c9 | 84 | if (!fTree) return kFALSE; |
6ccd727b | 85 | fTree->GetEntry(0); |
86 | ||
d3dd3d14 | 87 | // Get pointer to ESD event |
300d5701 | 88 | SwitchOffBranches(); |
3858dd64 | 89 | SwitchOnBranches(); |
300d5701 | 90 | |
efea3f54 | 91 | if (!fEvent) fEvent = new AliESDEvent(); |
60996693 | 92 | fEvent->ReadFromTree(fTree); |
4d2a7370 | 93 | fNEvents = fTree->GetEntries(); |
6ccd727b | 94 | |
50aaaf00 | 95 | |
d3dd3d14 | 96 | return kTRUE; |
97 | } | |
98 | ||
6ccd727b | 99 | Bool_t AliESDInputHandler::BeginEvent(Long64_t entry) |
d3dd3d14 | 100 | { |
101 | // Copy from old to new format if necessary | |
d7749dec | 102 | AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld(); |
103 | if (old) { | |
d3dd3d14 | 104 | ((AliESDEvent*)fEvent)->CopyFromOldESD(); |
105 | old->Reset(); | |
d7749dec | 106 | } |
6ccd727b | 107 | |
108 | if (fHLTTree) { | |
109 | fHLTTree->GetEntry(entry); | |
110 | } | |
111 | ||
f0ee78b0 | 112 | fNewEvent = kTRUE; |
113 | ||
d7749dec | 114 | return kTRUE; |
d3dd3d14 | 115 | } |
116 | ||
e12e402c | 117 | Bool_t AliESDInputHandler::FinishEvent() |
118 | { | |
119 | // Finish the event | |
120 | if(fEvent)fEvent->Reset(); | |
121 | return kTRUE; | |
6989bff3 | 122 | } |
123 | ||
1aa09fd1 | 124 | Bool_t AliESDInputHandler::Notify(const char* path) |
125 | { | |
126 | // Notify a directory change | |
a5112f7d | 127 | AliInfo(Form("Directory change %s \n", path)); |
128 | // | |
50aaaf00 | 129 | if (fUseHLT) { |
130 | // Get HLTesdTree from current file | |
131 | TTree* cTree = fTree; | |
132 | if (fTree->GetTree()) cTree = fTree->GetTree(); | |
133 | TFile* cFile = cTree->GetCurrentFile(); | |
134 | cFile->GetObject("HLTesdTree", fHLTTree); | |
135 | ||
136 | if (fHLTTree) { | |
137 | if (!fHLTEvent) fHLTEvent = new AliESDEvent(); | |
138 | fHLTEvent->ReadFromTree(fHLTTree); | |
139 | } | |
140 | } | |
141 | ||
1aa09fd1 | 142 | if (!fUseTags) return (kTRUE); |
143 | ||
144 | Bool_t zip = kFALSE; | |
145 | ||
146 | TString fileName(path); | |
147 | if(fileName.Contains("#AliESDs.root")){ | |
1aa09fd1 | 148 | zip = kTRUE; |
149 | } | |
150 | else if (fileName.Contains("AliESDs.root")){ | |
151 | fileName.ReplaceAll("AliESDs.root", ""); | |
152 | } | |
153 | else if(fileName.Contains("#AliAOD.root")){ | |
1aa09fd1 | 154 | zip = kTRUE; |
155 | } | |
156 | else if(fileName.Contains("AliAOD.root")){ | |
157 | fileName.ReplaceAll("AliAOD.root", ""); | |
158 | } | |
159 | else if(fileName.Contains("#galice.root")){ | |
160 | // For running with galice and kinematics alone... | |
1aa09fd1 | 161 | zip = kTRUE; |
162 | } | |
163 | else if(fileName.Contains("galice.root")){ | |
164 | // For running with galice and kinematics alone... | |
165 | fileName.ReplaceAll("galice.root", ""); | |
166 | } | |
167 | ||
1aa09fd1 | 168 | |
be4763e2 | 169 | TString pathName("./"); |
170 | if (fileName.Length() != 0) { | |
171 | pathName = fileName; | |
172 | } | |
173 | ||
174 | printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data()); | |
6ccd727b | 175 | |
1aa09fd1 | 176 | if (fRunTag) { |
177 | fRunTag->Clear(); | |
178 | } else { | |
179 | fRunTag = new AliRunTag(); | |
180 | } | |
181 | ||
182 | delete fTreeT; fTreeT = 0; | |
6ccd727b | 183 | |
1aa09fd1 | 184 | if (fChainT) { |
185 | delete fChainT; | |
186 | fChainT = 0; | |
187 | } | |
188 | ||
189 | if (!fChainT) { | |
190 | fChainT = new TChain("T"); | |
191 | } | |
192 | ||
193 | ||
194 | ||
195 | const char* tagPattern = "ESD.tag.root"; | |
196 | const char* name = 0x0; | |
197 | TString tagFilename; | |
198 | if (zip) { | |
8ac5c1d7 | 199 | TFile* file = fTree->GetCurrentFile(); |
1aa09fd1 | 200 | TArchiveFile* arch = file->GetArchive(); |
201 | TObjArray* arr = arch->GetMembers(); | |
202 | TIter next(arr); | |
203 | ||
7cec0871 | 204 | while ((file = (TFile*) next())) { |
1aa09fd1 | 205 | name = file->GetName(); |
206 | if (strstr(name,tagPattern)) { | |
be4763e2 | 207 | tagFilename = pathName.Data(); |
1aa09fd1 | 208 | tagFilename += "#"; |
209 | tagFilename += name; | |
210 | fChainT->Add(tagFilename); | |
211 | AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data())); | |
212 | }//pattern check | |
213 | } // archive file loop | |
214 | } else { | |
be4763e2 | 215 | void * dirp = gSystem->OpenDirectory(pathName.Data()); |
1aa09fd1 | 216 | while((name = gSystem->GetDirEntry(dirp))) { |
217 | if (strstr(name,tagPattern)) { | |
be4763e2 | 218 | tagFilename = pathName.Data(); |
1aa09fd1 | 219 | tagFilename += "/"; |
220 | tagFilename += name; | |
221 | fChainT->Add(tagFilename); | |
222 | AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data())); | |
223 | }//pattern check | |
224 | }//directory loop | |
225 | } | |
226 | fChainT->SetBranchAddress("AliTAG",&fRunTag); | |
227 | fChainT->GetEntry(0); | |
228 | return kTRUE; | |
229 | } | |
230 | ||
231 | ||
c2b6979d | 232 | |
233 | Option_t *AliESDInputHandler::GetDataType() const | |
234 | { | |
235 | // Returns handled data type. | |
236 | return gESDDataType; | |
237 | } | |
f0f29480 | 238 | |
239 | Int_t AliESDInputHandler::GetNEventAcceptedInFile() | |
240 | { | |
241 | // Get number of events in file accepted by the tag cuts | |
242 | // return -1 if no info is available | |
243 | if (!fTagCutSumm) { | |
244 | TList *luo = fTree->GetUserInfo(); | |
245 | if (!luo) { | |
246 | AliInfo(Form("No user info in input tree - no tag cut summary\n")); | |
247 | return -1; | |
248 | } | |
249 | for (int iluo=0; iluo<luo->GetEntries(); iluo++) { | |
250 | fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo)); | |
251 | if (fTagCutSumm) break; | |
252 | } | |
253 | if (!fTagCutSumm) { | |
254 | AliInfo(Form("No tag summary map in input tree\n")); | |
255 | return -1; | |
256 | } | |
257 | } | |
258 | ||
259 | TObjString *ostr = 0; | |
260 | if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName())) | |
261 | ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName()); | |
262 | else { | |
263 | AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName())); | |
264 | return -1; | |
265 | } | |
266 | char *iTagInfo; | |
267 | iTagInfo = strdup(ostr->GetString().Data()); | |
268 | ||
269 | Int_t iAcc = atoi(strtok(iTagInfo, ",")); | |
270 | ||
271 | AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName())); | |
272 | ||
273 | free(iTagInfo); | |
274 | ||
275 | return iAcc; | |
276 | } | |
277 | Int_t AliESDInputHandler::GetNEventRejectedInFile() | |
278 | { | |
279 | // Get number of events in file rejected by the tag cuts | |
280 | // return -1 if no info is available | |
281 | if (!fTagCutSumm) { | |
282 | TList *luo = fTree->GetUserInfo(); | |
283 | if (!luo) { | |
284 | AliInfo(Form("No user info in input tree - no tag cut summary\n")); | |
285 | return -1; | |
286 | } | |
287 | for (int iluo=0; iluo<luo->GetEntries(); iluo++) { | |
288 | fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo)); | |
289 | if (fTagCutSumm) break; | |
290 | } | |
291 | if (!fTagCutSumm) { | |
292 | AliInfo(Form("No tag summary map in input tree\n")); | |
293 | return -1; | |
294 | } | |
295 | } | |
296 | ||
297 | TObjString *ostr = 0; | |
298 | if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName())) | |
299 | ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName()); | |
300 | else { | |
301 | AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName())); | |
302 | return -1; | |
303 | } | |
304 | char *iTagInfo; | |
305 | iTagInfo = strdup(ostr->GetString().Data()); | |
306 | ||
307 | strtok(iTagInfo, ","); | |
308 | Int_t iRej = atoi(strtok(NULL, ",")); | |
309 | ||
310 | AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName())); | |
311 | ||
312 | free(iTagInfo); | |
313 | ||
314 | return iRej; | |
315 | } | |
c334d0d3 | 316 | Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected) |
317 | { | |
318 | // Get number of events in the full chain | |
319 | // Count accepted and rejected events | |
320 | // return kFALSE if no info is available | |
321 | if (!fTagCutSumm) { | |
322 | TList *luo = fTree->GetUserInfo(); | |
323 | if (!luo) { | |
324 | AliInfo(Form("No user info in input tree - no tag cut summary\n")); | |
325 | return kFALSE; | |
326 | } | |
327 | for (int iluo=0; iluo<luo->GetEntries(); iluo++) { | |
328 | fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo)); | |
329 | if (fTagCutSumm) break; | |
330 | } | |
331 | if (!fTagCutSumm) { | |
332 | AliInfo(Form("No tag summary map in input tree\n")); | |
333 | return kFALSE; | |
334 | } | |
335 | } | |
336 | ||
337 | TMapIter *tIter = new TMapIter(fTagCutSumm); | |
338 | ||
339 | Int_t iTotList=0, iAccList=0, iRejList=0; | |
340 | ||
341 | TObject *cobj; | |
9a587f77 | 342 | while ((cobj = tIter->Next())) { |
c334d0d3 | 343 | TObjString *kstr = (TObjString *) cobj; |
344 | TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data()); | |
345 | // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data()); | |
346 | char *iTagInfo; | |
347 | iTagInfo = strdup(vstr->GetString().Data()); | |
348 | ||
349 | Int_t iAcc = atoi(strtok(iTagInfo, ",")); | |
350 | Int_t iRej = atoi(strtok(NULL, ",")); | |
351 | ||
352 | iAccList += iAcc; | |
353 | iRejList += iRej; | |
354 | iTotList += (iAcc+iRej); | |
355 | } | |
356 | ||
357 | *aTotal = iTotList; | |
358 | *aAccepted = iAccList; | |
359 | *aRejected = iRejList; | |
360 | ||
361 | return kTRUE; | |
362 | } | |
363 | ||
364 | Int_t AliESDInputHandler::GetNFilesEmpty() | |
365 | { | |
366 | // Count number of files in which all events were de-selected | |
367 | // For such files Notify() will NOT be called | |
368 | // return -1 if no info is available | |
369 | if (!fTagCutSumm) { | |
370 | TList *luo = fTree->GetUserInfo(); | |
371 | if (!luo) { | |
372 | AliInfo(Form("No user info in input tree - no tag cut summary\n")); | |
373 | return -1; | |
374 | } | |
375 | for (int iluo=0; iluo<luo->GetEntries(); iluo++) { | |
376 | fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo)); | |
377 | if (fTagCutSumm) break; | |
378 | } | |
379 | if (!fTagCutSumm) { | |
380 | AliInfo(Form("No tag summary map in input tree\n")); | |
381 | return -1; | |
382 | } | |
383 | } | |
384 | ||
385 | TMapIter *tIter = new TMapIter(fTagCutSumm); | |
386 | ||
387 | Int_t iFilesEmpty = 0; | |
388 | ||
389 | TObject *cobj; | |
9a587f77 | 390 | while ((cobj = tIter->Next())) { |
c334d0d3 | 391 | TObjString *kstr = (TObjString *) cobj; |
392 | TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data()); | |
393 | // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data()); | |
394 | char *iTagInfo; | |
395 | iTagInfo = strdup(vstr->GetString().Data()); | |
396 | ||
397 | Int_t iAcc = atoi(strtok(iTagInfo, ",")); | |
398 | Int_t iRej = atoi(strtok(NULL, ",")); | |
399 | ||
400 | if ((iAcc == 0) && ((iRej+iAcc)>0)) | |
401 | iFilesEmpty++; | |
402 | } | |
403 | ||
404 | return iFilesEmpty; | |
405 | ||
406 | } |