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