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