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(),
63 // default constructor
66 //______________________________________________________________________________
67 AliESDInputHandler::~AliESDInputHandler()
73 //______________________________________________________________________________
74 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
75 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fAnalysisType(0),
76 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
81 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
83 // Initialisation necessary for each new tree
87 if (!fTree) return kFALSE;
90 // Get pointer to ESD event
94 if (!fEvent) fEvent = new AliESDEvent();
95 fEvent->ReadFromTree(fTree);
96 fNEvents = fTree->GetEntries();
97 if (fTree->GetBranch("ESDfriend.")) {
98 fTree->SetBranchAddress("ESDfriend.", &fFriend);
104 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
107 // Copy from old to new format if necessary
108 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
110 ((AliESDEvent*)fEvent)->CopyFromOldESD();
115 fHLTTree->GetEntry(entry);
123 fIsSelected = fEventCuts->IsSelected((AliESDEvent*)fEvent);
126 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
131 Bool_t AliESDInputHandler::FinishEvent()
134 if(fEvent)fEvent->Reset();
138 Bool_t AliESDInputHandler::Notify(const char* path)
140 // Notify a directory change
141 AliInfo(Form("Directory change %s \n", path));
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);
151 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
152 fHLTEvent->ReadFromTree(fHLTTree);
156 if (!fUseTags) return (kTRUE);
160 TString fileName(path);
161 if(fileName.Contains("#AliESDs.root")){
164 else if (fileName.Contains("AliESDs.root")){
165 fileName.ReplaceAll("AliESDs.root", "");
167 else if(fileName.Contains("#AliAOD.root")){
170 else if(fileName.Contains("AliAOD.root")){
171 fileName.ReplaceAll("AliAOD.root", "");
173 else if(fileName.Contains("#galice.root")){
174 // For running with galice and kinematics alone...
177 else if(fileName.Contains("galice.root")){
178 // For running with galice and kinematics alone...
179 fileName.ReplaceAll("galice.root", "");
183 TString pathName("./");
184 if (fileName.Length() != 0) {
188 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
193 fRunTag = new AliRunTag();
196 delete fTreeT; fTreeT = 0;
204 fChainT = new TChain("T");
209 const char* tagPattern = "ESD.tag.root";
210 const char* name = 0x0;
213 TFile* file = fTree->GetCurrentFile();
214 TArchiveFile* arch = file->GetArchive();
215 TObjArray* arr = arch->GetMembers();
218 while ((file = (TFile*) next())) {
219 name = file->GetName();
220 if (strstr(name,tagPattern)) {
221 tagFilename = pathName.Data();
224 fChainT->Add(tagFilename);
225 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
227 } // archive file loop
229 void * dirp = gSystem->OpenDirectory(pathName.Data());
230 while((name = gSystem->GetDirEntry(dirp))) {
231 if (strstr(name,tagPattern)) {
232 tagFilename = pathName.Data();
235 fChainT->Add(tagFilename);
236 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
240 fChainT->SetBranchAddress("AliTAG",&fRunTag);
241 fChainT->GetEntry(0);
247 Option_t *AliESDInputHandler::GetDataType() const
249 // Returns handled data type.
253 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
255 // Get number of events in file accepted by the tag cuts
256 // return -1 if no info is available
258 TList *luo = fTree->GetUserInfo();
260 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
263 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
264 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
265 if (fTagCutSumm) break;
268 AliInfo(Form("No tag summary map in input tree\n"));
273 TObjString *ostr = 0;
274 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
275 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
277 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
281 iTagInfo = strdup(ostr->GetString().Data());
283 Int_t iAcc = atoi(strtok(iTagInfo, ","));
285 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
291 Int_t AliESDInputHandler::GetNEventRejectedInFile()
293 // Get number of events in file rejected by the tag cuts
294 // return -1 if no info is available
296 TList *luo = fTree->GetUserInfo();
298 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
301 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
302 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
303 if (fTagCutSumm) break;
306 AliInfo(Form("No tag summary map in input tree\n"));
311 TObjString *ostr = 0;
312 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
313 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
315 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
319 iTagInfo = strdup(ostr->GetString().Data());
321 strtok(iTagInfo, ",");
322 Int_t iRej = atoi(strtok(NULL, ","));
324 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
330 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
332 // Get number of events in the full chain
333 // Count accepted and rejected events
334 // return kFALSE if no info is available
336 TList *luo = fTree->GetUserInfo();
338 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
341 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
342 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
343 if (fTagCutSumm) break;
346 AliInfo(Form("No tag summary map in input tree\n"));
351 TMapIter *tIter = new TMapIter(fTagCutSumm);
353 Int_t iTotList=0, iAccList=0, iRejList=0;
356 while ((cobj = tIter->Next())) {
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());
361 iTagInfo = strdup(vstr->GetString().Data());
363 Int_t iAcc = atoi(strtok(iTagInfo, ","));
364 Int_t iRej = atoi(strtok(NULL, ","));
368 iTotList += (iAcc+iRej);
372 *aAccepted = iAccList;
373 *aRejected = iRejList;
378 Int_t AliESDInputHandler::GetNFilesEmpty()
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
384 TList *luo = fTree->GetUserInfo();
386 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
389 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
390 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
391 if (fTagCutSumm) break;
394 AliInfo(Form("No tag summary map in input tree\n"));
399 TMapIter *tIter = new TMapIter(fTagCutSumm);
401 Int_t iFilesEmpty = 0;
404 while ((cobj = tIter->Next())) {
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());
409 iTagInfo = strdup(vstr->GetString().Data());
411 Int_t iAcc = atoi(strtok(iTagInfo, ","));
412 Int_t iRej = atoi(strtok(NULL, ","));
414 if ((iAcc == 0) && ((iRej+iAcc)>0))