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