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