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