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 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
86 // Initialisation necessary for each new tree
91 if (!fTree) return kFALSE;
95 if (!fEvent) fEvent = new AliESDEvent();
96 fEvent->ReadFromTree(fTree);
97 fNEvents = fTree->GetEntries();
101 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
104 // Copy from old to new format if necessary
105 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
107 ((AliESDEvent*)fEvent)->CopyFromOldESD();
112 fHLTTree->GetEntry(entry);
120 fIsSelectedResult = fEventCuts->GetSelectionMask((AliESDEvent*)fEvent);
123 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
127 Bool_t AliESDInputHandler::FinishEvent()
130 if(fEvent)fEvent->Reset();
134 Bool_t AliESDInputHandler::Notify(const char* path)
136 // Notify a directory change
137 AliInfo(Form("Directory change %s \n", path));
139 // Handle the friends first
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;
146 esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
148 TTree* cTree = fTree->GetTree();
149 if (!cTree) cTree = fTree;
151 cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
152 cTree->SetBranchStatus("ESDfriend.", 1);
153 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
154 cTree->SetBranchAddress("ESDfriend.", &fFriend);
160 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
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);
172 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
173 fHLTEvent->ReadFromTree(fHLTTree);
180 if (!fUseTags) return (kTRUE);
184 TString fileName(path);
185 if(fileName.Contains("#AliESDs.root")){
188 else if (fileName.Contains("AliESDs.root")){
189 fileName.ReplaceAll("AliESDs.root", "");
191 else if(fileName.Contains("#AliAOD.root")){
194 else if(fileName.Contains("AliAOD.root")){
195 fileName.ReplaceAll("AliAOD.root", "");
197 else if(fileName.Contains("#galice.root")){
198 // For running with galice and kinematics alone...
201 else if(fileName.Contains("galice.root")){
202 // For running with galice and kinematics alone...
203 fileName.ReplaceAll("galice.root", "");
207 TString pathName("./");
208 if (fileName.Length() != 0) {
212 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
217 fRunTag = new AliRunTag();
220 delete fTreeT; fTreeT = 0;
228 fChainT = new TChain("T");
233 const char* tagPattern = "ESD.tag.root";
234 const char* name = 0x0;
237 TFile* file = fTree->GetCurrentFile();
238 TArchiveFile* arch = file->GetArchive();
239 TObjArray* arr = arch->GetMembers();
242 while ((file = (TFile*) next())) {
243 name = file->GetName();
244 if (strstr(name,tagPattern)) {
245 tagFilename = pathName.Data();
248 fChainT->Add(tagFilename);
249 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
251 } // archive file loop
253 void * dirp = gSystem->OpenDirectory(pathName.Data());
254 while((name = gSystem->GetDirEntry(dirp))) {
255 if (strstr(name,tagPattern)) {
256 tagFilename = pathName.Data();
259 fChainT->Add(tagFilename);
260 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
264 fChainT->SetBranchAddress("AliTAG",&fRunTag);
265 fChainT->GetEntry(0);
271 Option_t *AliESDInputHandler::GetDataType() const
273 // Returns handled data type.
277 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
279 // Get number of events in file accepted by the tag cuts
280 // return -1 if no info is available
282 TList *luo = fTree->GetUserInfo();
284 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
287 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
288 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
289 if (fTagCutSumm) break;
292 AliInfo(Form("No tag summary map in input tree\n"));
297 TObjString *ostr = 0;
298 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
299 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
301 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
305 iTagInfo = strdup(ostr->GetString().Data());
307 Int_t iAcc = atoi(strtok(iTagInfo, ","));
309 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
315 Int_t AliESDInputHandler::GetNEventRejectedInFile()
317 // Get number of events in file rejected by the tag cuts
318 // return -1 if no info is available
320 TList *luo = fTree->GetUserInfo();
322 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
325 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
326 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
327 if (fTagCutSumm) break;
330 AliInfo(Form("No tag summary map in input tree\n"));
335 TObjString *ostr = 0;
336 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
337 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
339 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
343 iTagInfo = strdup(ostr->GetString().Data());
345 strtok(iTagInfo, ",");
346 Int_t iRej = atoi(strtok(NULL, ","));
348 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
354 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
356 // Get number of events in the full chain
357 // Count accepted and rejected events
358 // return kFALSE if no info is available
360 TList *luo = fTree->GetUserInfo();
362 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
365 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
366 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
367 if (fTagCutSumm) break;
370 AliInfo(Form("No tag summary map in input tree\n"));
375 TMapIter *tIter = new TMapIter(fTagCutSumm);
377 Int_t iTotList=0, iAccList=0, iRejList=0;
380 while ((cobj = tIter->Next())) {
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());
385 iTagInfo = strdup(vstr->GetString().Data());
387 Int_t iAcc = atoi(strtok(iTagInfo, ","));
388 Int_t iRej = atoi(strtok(NULL, ","));
392 iTotList += (iAcc+iRej);
396 *aAccepted = iAccList;
397 *aRejected = iRejList;
402 Int_t AliESDInputHandler::GetNFilesEmpty()
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
408 TList *luo = fTree->GetUserInfo();
410 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
413 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
414 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
415 if (fTagCutSumm) break;
418 AliInfo(Form("No tag summary map in input tree\n"));
423 TMapIter *tIter = new TMapIter(fTagCutSumm);
425 Int_t iFilesEmpty = 0;
428 while ((cobj = tIter->Next())) {
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());
433 iTagInfo = strdup(vstr->GetString().Data());
435 Int_t iAcc = atoi(strtok(iTagInfo, ","));
436 Int_t iRej = atoi(strtok(NULL, ","));
438 if ((iAcc == 0) && ((iRej+iAcc)>0))