1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Event handler for ESD input
20 // Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
26 #include <TArchiveFile.h>
27 #include <TObjArray.h>
30 #include <TObjString.h>
31 #include <TProcessID.h>
34 #include "AliESDInputHandler.h"
35 #include "AliESDEvent.h"
36 #include "AliESDfriend.h"
39 #include "AliRunTag.h"
40 #include "AliEventTag.h"
43 ClassImp(AliESDInputHandler)
45 static Option_t *gESDDataType = "ESD";
47 //______________________________________________________________________________
48 AliESDInputHandler::AliESDInputHandler() :
49 AliInputEventHandler(),
64 fFriendFileName("AliESDfriends.root")
66 // default constructor
69 //______________________________________________________________________________
70 AliESDInputHandler::~AliESDInputHandler()
75 //______________________________________________________________________________
76 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
77 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
78 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(0), fFriendFileName("AliESDfriends.root")
83 //______________________________________________________________________________
84 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
87 // Initialisation necessary for each new tree
92 if (!fTree) return kFALSE;
96 if (!fEvent) fEvent = new AliESDEvent();
97 fEvent->ReadFromTree(fTree);
98 fNEvents = fTree->GetEntries();
102 //______________________________________________________________________________
103 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
106 // Copy from old to new format if necessary
107 static Bool_t called = kFALSE;
108 if (!called && fEventCuts && IsUserCallSelectionMask())
109 AliInfo(Form("The ESD input handler expects that the first task calls AliESDInputHandler::CheckSelectionMask() %s", fEventCuts->ClassName()));
110 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
112 ((AliESDEvent*)fEvent)->CopyFromOldESD();
117 fHLTTree->GetEntry(entry);
124 fIsSelectedResult = 0;
125 if (fEventCuts && !IsUserCallSelectionMask())
126 fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
129 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
134 //______________________________________________________________________________
135 void AliESDInputHandler::CheckSelectionMask()
137 // This method can be called by a task only if IsUserCallSelectionMask is true.
138 if (!fEventCuts || !IsUserCallSelectionMask()) return;
139 fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
142 //______________________________________________________________________________
143 Bool_t AliESDInputHandler::FinishEvent()
146 if(fEvent)fEvent->Reset();
150 //______________________________________________________________________________
151 Bool_t AliESDInputHandler::Notify(const char* path)
153 // Notify a directory change
154 AliInfo(Form("Directory change %s \n", path));
156 // Handle the friends first
158 if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
159 // Try to add ESDfriend. branch as friend
160 TString esdTreeFName, esdFriendTreeFName;
161 esdTreeFName = (fTree->GetCurrentFile())->GetName();
162 esdFriendTreeFName = esdTreeFName;
163 esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
165 TTree* cTree = fTree->GetTree();
166 if (!cTree) cTree = fTree;
168 cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
169 cTree->SetBranchStatus("ESDfriend.", 1);
170 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
171 cTree->SetBranchAddress("ESDfriend.", &fFriend);
177 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
180 // Get HLTesdTree from current file
181 TTree* cTree = fTree;
182 if (fTree->GetTree()) cTree = fTree->GetTree();
183 TFile* cFile = cTree->GetCurrentFile();
184 cFile->GetObject("HLTesdTree", fHLTTree);
187 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
188 fHLTEvent->ReadFromTree(fHLTTree);
192 if (!fUseTags) return (kTRUE);
196 TString fileName(path);
197 if(fileName.Contains("#AliESDs.root")){
200 else if (fileName.Contains("AliESDs.root")){
201 fileName.ReplaceAll("AliESDs.root", "");
203 else if(fileName.Contains("#AliAOD.root")){
206 else if(fileName.Contains("AliAOD.root")){
207 fileName.ReplaceAll("AliAOD.root", "");
209 else if(fileName.Contains("#galice.root")){
210 // For running with galice and kinematics alone...
213 else if(fileName.Contains("galice.root")){
214 // For running with galice and kinematics alone...
215 fileName.ReplaceAll("galice.root", "");
219 TString pathName("./");
220 if (fileName.Length() != 0) {
224 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
229 fRunTag = new AliRunTag();
232 delete fTreeT; fTreeT = 0;
240 fChainT = new TChain("T");
245 const char* tagPattern = "ESD.tag.root";
246 const char* name = 0x0;
249 TFile* file = fTree->GetCurrentFile();
250 TArchiveFile* arch = file->GetArchive();
251 TObjArray* arr = arch->GetMembers();
254 while ((file = (TFile*) next())) {
255 name = file->GetName();
256 if (strstr(name,tagPattern)) {
257 tagFilename = pathName.Data();
260 fChainT->Add(tagFilename);
261 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
263 } // archive file loop
265 void * dirp = gSystem->OpenDirectory(pathName.Data());
266 while((name = gSystem->GetDirEntry(dirp))) {
267 if (strstr(name,tagPattern)) {
268 tagFilename = pathName.Data();
271 fChainT->Add(tagFilename);
272 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
276 fChainT->SetBranchAddress("AliTAG",&fRunTag);
277 fChainT->GetEntry(0);
281 //______________________________________________________________________________
282 Option_t *AliESDInputHandler::GetDataType() const
284 // Returns handled data type.
288 //______________________________________________________________________________
289 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
291 // Get number of events in file accepted by the tag cuts
292 // return -1 if no info is available
294 TList *luo = fTree->GetUserInfo();
296 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
299 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
300 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
301 if (fTagCutSumm) break;
304 AliInfo(Form("No tag summary map in input tree\n"));
309 TObjString *ostr = 0;
310 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
311 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
313 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
317 iTagInfo = strdup(ostr->GetString().Data());
319 Int_t iAcc = atoi(strtok(iTagInfo, ","));
321 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
328 //______________________________________________________________________________
329 Int_t AliESDInputHandler::GetNEventRejectedInFile()
331 // Get number of events in file rejected by the tag cuts
332 // return -1 if no info is available
334 TList *luo = fTree->GetUserInfo();
336 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
339 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
340 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
341 if (fTagCutSumm) break;
344 AliInfo(Form("No tag summary map in input tree\n"));
349 TObjString *ostr = 0;
350 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
351 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
353 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
357 iTagInfo = strdup(ostr->GetString().Data());
359 strtok(iTagInfo, ",");
360 Int_t iRej = atoi(strtok(NULL, ","));
362 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
369 //______________________________________________________________________________
370 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
372 // Get number of events in the full chain
373 // Count accepted and rejected events
374 // return kFALSE if no info is available
376 TList *luo = fTree->GetUserInfo();
378 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
381 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
382 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
383 if (fTagCutSumm) break;
386 AliInfo(Form("No tag summary map in input tree\n"));
391 TMapIter *tIter = new TMapIter(fTagCutSumm);
393 Int_t iTotList=0, iAccList=0, iRejList=0;
396 while ((cobj = tIter->Next())) {
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());
401 iTagInfo = strdup(vstr->GetString().Data());
403 Int_t iAcc = atoi(strtok(iTagInfo, ","));
404 Int_t iRej = atoi(strtok(NULL, ","));
408 iTotList += (iAcc+iRej);
412 *aAccepted = iAccList;
413 *aRejected = iRejList;
418 //______________________________________________________________________________
419 Int_t AliESDInputHandler::GetNFilesEmpty()
421 // Count number of files in which all events were de-selected
422 // For such files Notify() will NOT be called
423 // return -1 if no info is available
425 TList *luo = fTree->GetUserInfo();
427 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
430 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
431 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
432 if (fTagCutSumm) break;
435 AliInfo(Form("No tag summary map in input tree\n"));
440 TMapIter *tIter = new TMapIter(fTagCutSumm);
442 Int_t iFilesEmpty = 0;
445 while ((cobj = tIter->Next())) {
446 TObjString *kstr = (TObjString *) cobj;
447 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
448 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
450 iTagInfo = strdup(vstr->GetString().Data());
452 Int_t iAcc = atoi(strtok(iTagInfo, ","));
453 Int_t iRej = atoi(strtok(NULL, ","));
455 if ((iAcc == 0) && ((iRej+iAcc)>0))