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()
76 //______________________________________________________________________________
77 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
78 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
79 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(1), fFriendFileName("AliESDfriends.root")
84 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
86 // Initialisation necessary for each new tree
90 if (!fTree) return kFALSE;
93 // Get pointer to ESD event
97 if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
98 // Try to add ESDfriend. branch as friend
99 TString esdTreeFName, esdFriendTreeFName;
100 TTree* theTree = fTree->GetTree();
101 if (!theTree) theTree = tree;
102 esdTreeFName = (theTree->GetCurrentFile())->GetName();
103 esdFriendTreeFName = esdTreeFName;
104 esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
105 theTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
108 if (!fEvent) fEvent = new AliESDEvent();
109 fEvent->ReadFromTree(fTree);
110 fNEvents = fTree->GetEntries();
111 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
115 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
118 // Copy from old to new format if necessary
119 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
121 ((AliESDEvent*)fEvent)->CopyFromOldESD();
126 fHLTTree->GetEntry(entry);
134 fIsSelected = fEventCuts->IsSelected((AliESDEvent*)fEvent);
137 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
142 Bool_t AliESDInputHandler::FinishEvent()
145 if(fEvent)fEvent->Reset();
149 Bool_t AliESDInputHandler::Notify(const char* path)
151 // Notify a directory change
152 AliInfo(Form("Directory change %s \n", path));
155 // Get HLTesdTree from current file
156 TTree* cTree = fTree;
157 if (fTree->GetTree()) cTree = fTree->GetTree();
158 TFile* cFile = cTree->GetCurrentFile();
159 cFile->GetObject("HLTesdTree", fHLTTree);
162 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
163 fHLTEvent->ReadFromTree(fHLTTree);
167 if (!fUseTags) return (kTRUE);
171 TString fileName(path);
172 if(fileName.Contains("#AliESDs.root")){
175 else if (fileName.Contains("AliESDs.root")){
176 fileName.ReplaceAll("AliESDs.root", "");
178 else if(fileName.Contains("#AliAOD.root")){
181 else if(fileName.Contains("AliAOD.root")){
182 fileName.ReplaceAll("AliAOD.root", "");
184 else if(fileName.Contains("#galice.root")){
185 // For running with galice and kinematics alone...
188 else if(fileName.Contains("galice.root")){
189 // For running with galice and kinematics alone...
190 fileName.ReplaceAll("galice.root", "");
194 TString pathName("./");
195 if (fileName.Length() != 0) {
199 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
204 fRunTag = new AliRunTag();
207 delete fTreeT; fTreeT = 0;
215 fChainT = new TChain("T");
220 const char* tagPattern = "ESD.tag.root";
221 const char* name = 0x0;
224 TFile* file = fTree->GetCurrentFile();
225 TArchiveFile* arch = file->GetArchive();
226 TObjArray* arr = arch->GetMembers();
229 while ((file = (TFile*) next())) {
230 name = file->GetName();
231 if (strstr(name,tagPattern)) {
232 tagFilename = pathName.Data();
235 fChainT->Add(tagFilename);
236 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
238 } // archive file loop
240 void * dirp = gSystem->OpenDirectory(pathName.Data());
241 while((name = gSystem->GetDirEntry(dirp))) {
242 if (strstr(name,tagPattern)) {
243 tagFilename = pathName.Data();
246 fChainT->Add(tagFilename);
247 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
251 fChainT->SetBranchAddress("AliTAG",&fRunTag);
252 fChainT->GetEntry(0);
258 Option_t *AliESDInputHandler::GetDataType() const
260 // Returns handled data type.
264 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
266 // Get number of events in file accepted by the tag cuts
267 // return -1 if no info is available
269 TList *luo = fTree->GetUserInfo();
271 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
274 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
275 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
276 if (fTagCutSumm) break;
279 AliInfo(Form("No tag summary map in input tree\n"));
284 TObjString *ostr = 0;
285 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
286 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
288 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
292 iTagInfo = strdup(ostr->GetString().Data());
294 Int_t iAcc = atoi(strtok(iTagInfo, ","));
296 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
302 Int_t AliESDInputHandler::GetNEventRejectedInFile()
304 // Get number of events in file rejected by the tag cuts
305 // return -1 if no info is available
307 TList *luo = fTree->GetUserInfo();
309 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
312 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
313 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
314 if (fTagCutSumm) break;
317 AliInfo(Form("No tag summary map in input tree\n"));
322 TObjString *ostr = 0;
323 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
324 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
326 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
330 iTagInfo = strdup(ostr->GetString().Data());
332 strtok(iTagInfo, ",");
333 Int_t iRej = atoi(strtok(NULL, ","));
335 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
341 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
343 // Get number of events in the full chain
344 // Count accepted and rejected events
345 // return kFALSE if no info is available
347 TList *luo = fTree->GetUserInfo();
349 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
352 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
353 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
354 if (fTagCutSumm) break;
357 AliInfo(Form("No tag summary map in input tree\n"));
362 TMapIter *tIter = new TMapIter(fTagCutSumm);
364 Int_t iTotList=0, iAccList=0, iRejList=0;
367 while ((cobj = tIter->Next())) {
368 TObjString *kstr = (TObjString *) cobj;
369 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
370 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
372 iTagInfo = strdup(vstr->GetString().Data());
374 Int_t iAcc = atoi(strtok(iTagInfo, ","));
375 Int_t iRej = atoi(strtok(NULL, ","));
379 iTotList += (iAcc+iRej);
383 *aAccepted = iAccList;
384 *aRejected = iRejList;
389 Int_t AliESDInputHandler::GetNFilesEmpty()
391 // Count number of files in which all events were de-selected
392 // For such files Notify() will NOT be called
393 // return -1 if no info is available
395 TList *luo = fTree->GetUserInfo();
397 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
400 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
401 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
402 if (fTagCutSumm) break;
405 AliInfo(Form("No tag summary map in input tree\n"));
410 TMapIter *tIter = new TMapIter(fTagCutSumm);
412 Int_t iFilesEmpty = 0;
415 while ((cobj = tIter->Next())) {
416 TObjString *kstr = (TObjString *) cobj;
417 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
418 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
420 iTagInfo = strdup(vstr->GetString().Data());
422 Int_t iAcc = atoi(strtok(iTagInfo, ","));
423 Int_t iRej = atoi(strtok(NULL, ","));
425 if ((iAcc == 0) && ((iRej+iAcc)>0))