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 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
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 fIsSelected = fEventCuts->IsSelected((AliESDEvent*)fEvent);
123 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
128 Bool_t AliESDInputHandler::FinishEvent()
131 if(fEvent)fEvent->Reset();
135 Bool_t AliESDInputHandler::Notify(const char* path)
137 // Notify a directory change
138 AliInfo(Form("Directory change %s \n", path));
141 // Get HLTesdTree from current file
142 TTree* cTree = fTree;
143 if (fTree->GetTree()) cTree = fTree->GetTree();
144 TFile* cFile = cTree->GetCurrentFile();
145 cFile->GetObject("HLTesdTree", fHLTTree);
148 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
149 fHLTEvent->ReadFromTree(fHLTTree);
153 if (!fUseTags) return (kTRUE);
157 TString fileName(path);
158 if(fileName.Contains("#AliESDs.root")){
161 else if (fileName.Contains("AliESDs.root")){
162 fileName.ReplaceAll("AliESDs.root", "");
164 else if(fileName.Contains("#AliAOD.root")){
167 else if(fileName.Contains("AliAOD.root")){
168 fileName.ReplaceAll("AliAOD.root", "");
170 else if(fileName.Contains("#galice.root")){
171 // For running with galice and kinematics alone...
174 else if(fileName.Contains("galice.root")){
175 // For running with galice and kinematics alone...
176 fileName.ReplaceAll("galice.root", "");
180 TString pathName("./");
181 if (fileName.Length() != 0) {
185 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
190 fRunTag = new AliRunTag();
193 delete fTreeT; fTreeT = 0;
201 fChainT = new TChain("T");
206 const char* tagPattern = "ESD.tag.root";
207 const char* name = 0x0;
210 TFile* file = fTree->GetCurrentFile();
211 TArchiveFile* arch = file->GetArchive();
212 TObjArray* arr = arch->GetMembers();
215 while ((file = (TFile*) next())) {
216 name = file->GetName();
217 if (strstr(name,tagPattern)) {
218 tagFilename = pathName.Data();
221 fChainT->Add(tagFilename);
222 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
224 } // archive file loop
226 void * dirp = gSystem->OpenDirectory(pathName.Data());
227 while((name = gSystem->GetDirEntry(dirp))) {
228 if (strstr(name,tagPattern)) {
229 tagFilename = pathName.Data();
232 fChainT->Add(tagFilename);
233 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
237 fChainT->SetBranchAddress("AliTAG",&fRunTag);
238 fChainT->GetEntry(0);
244 Option_t *AliESDInputHandler::GetDataType() const
246 // Returns handled data type.
250 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
252 // Get number of events in file accepted by the tag cuts
253 // return -1 if no info is available
255 TList *luo = fTree->GetUserInfo();
257 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
260 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
261 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
262 if (fTagCutSumm) break;
265 AliInfo(Form("No tag summary map in input tree\n"));
270 TObjString *ostr = 0;
271 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
272 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
274 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
278 iTagInfo = strdup(ostr->GetString().Data());
280 Int_t iAcc = atoi(strtok(iTagInfo, ","));
282 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
288 Int_t AliESDInputHandler::GetNEventRejectedInFile()
290 // Get number of events in file rejected by the tag cuts
291 // return -1 if no info is available
293 TList *luo = fTree->GetUserInfo();
295 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
298 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
299 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
300 if (fTagCutSumm) break;
303 AliInfo(Form("No tag summary map in input tree\n"));
308 TObjString *ostr = 0;
309 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
310 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
312 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
316 iTagInfo = strdup(ostr->GetString().Data());
318 strtok(iTagInfo, ",");
319 Int_t iRej = atoi(strtok(NULL, ","));
321 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
327 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
329 // Get number of events in the full chain
330 // Count accepted and rejected events
331 // return kFALSE if no info is available
333 TList *luo = fTree->GetUserInfo();
335 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
338 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
339 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
340 if (fTagCutSumm) break;
343 AliInfo(Form("No tag summary map in input tree\n"));
348 TMapIter *tIter = new TMapIter(fTagCutSumm);
350 Int_t iTotList=0, iAccList=0, iRejList=0;
353 while ((cobj = tIter->Next())) {
354 TObjString *kstr = (TObjString *) cobj;
355 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
356 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
358 iTagInfo = strdup(vstr->GetString().Data());
360 Int_t iAcc = atoi(strtok(iTagInfo, ","));
361 Int_t iRej = atoi(strtok(NULL, ","));
365 iTotList += (iAcc+iRej);
369 *aAccepted = iAccList;
370 *aRejected = iRejList;
375 Int_t AliESDInputHandler::GetNFilesEmpty()
377 // Count number of files in which all events were de-selected
378 // For such files Notify() will NOT be called
379 // return -1 if no info is available
381 TList *luo = fTree->GetUserInfo();
383 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
386 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
387 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
388 if (fTagCutSumm) break;
391 AliInfo(Form("No tag summary map in input tree\n"));
396 TMapIter *tIter = new TMapIter(fTagCutSumm);
398 Int_t iFilesEmpty = 0;
401 while ((cobj = tIter->Next())) {
402 TObjString *kstr = (TObjString *) cobj;
403 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
404 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
406 iTagInfo = strdup(vstr->GetString().Data());
408 Int_t iAcc = atoi(strtok(iTagInfo, ","));
409 Int_t iRej = atoi(strtok(NULL, ","));
411 if ((iAcc == 0) && ((iRej+iAcc)>0))