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 // default constructor
67 //______________________________________________________________________________
68 AliESDInputHandler::~AliESDInputHandler()
74 //______________________________________________________________________________
75 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
76 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
77 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
82 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
84 // Initialisation necessary for each new tree
88 if (!fTree) return kFALSE;
91 // Get pointer to ESD event
95 if (!fEvent) fEvent = new AliESDEvent();
96 fEvent->ReadFromTree(fTree);
97 fNEvents = fTree->GetEntries();
98 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
102 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
105 // Copy from old to new format if necessary
106 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
108 ((AliESDEvent*)fEvent)->CopyFromOldESD();
113 fHLTTree->GetEntry(entry);
121 fIsSelected = fEventCuts->IsSelected((AliESDEvent*)fEvent);
124 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
129 Bool_t AliESDInputHandler::FinishEvent()
132 if(fEvent)fEvent->Reset();
136 Bool_t AliESDInputHandler::Notify(const char* path)
138 // Notify a directory change
139 AliInfo(Form("Directory change %s \n", path));
142 // Get HLTesdTree from current file
143 TTree* cTree = fTree;
144 if (fTree->GetTree()) cTree = fTree->GetTree();
145 TFile* cFile = cTree->GetCurrentFile();
146 cFile->GetObject("HLTesdTree", fHLTTree);
149 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
150 fHLTEvent->ReadFromTree(fHLTTree);
154 if (!fUseTags) return (kTRUE);
158 TString fileName(path);
159 if(fileName.Contains("#AliESDs.root")){
162 else if (fileName.Contains("AliESDs.root")){
163 fileName.ReplaceAll("AliESDs.root", "");
165 else if(fileName.Contains("#AliAOD.root")){
168 else if(fileName.Contains("AliAOD.root")){
169 fileName.ReplaceAll("AliAOD.root", "");
171 else if(fileName.Contains("#galice.root")){
172 // For running with galice and kinematics alone...
175 else if(fileName.Contains("galice.root")){
176 // For running with galice and kinematics alone...
177 fileName.ReplaceAll("galice.root", "");
181 TString pathName("./");
182 if (fileName.Length() != 0) {
186 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
191 fRunTag = new AliRunTag();
194 delete fTreeT; fTreeT = 0;
202 fChainT = new TChain("T");
207 const char* tagPattern = "ESD.tag.root";
208 const char* name = 0x0;
211 TFile* file = fTree->GetCurrentFile();
212 TArchiveFile* arch = file->GetArchive();
213 TObjArray* arr = arch->GetMembers();
216 while ((file = (TFile*) next())) {
217 name = file->GetName();
218 if (strstr(name,tagPattern)) {
219 tagFilename = pathName.Data();
222 fChainT->Add(tagFilename);
223 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
225 } // archive file loop
227 void * dirp = gSystem->OpenDirectory(pathName.Data());
228 while((name = gSystem->GetDirEntry(dirp))) {
229 if (strstr(name,tagPattern)) {
230 tagFilename = pathName.Data();
233 fChainT->Add(tagFilename);
234 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
238 fChainT->SetBranchAddress("AliTAG",&fRunTag);
239 fChainT->GetEntry(0);
245 Option_t *AliESDInputHandler::GetDataType() const
247 // Returns handled data type.
251 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
253 // Get number of events in file accepted by the tag cuts
254 // return -1 if no info is available
256 TList *luo = fTree->GetUserInfo();
258 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
261 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
262 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
263 if (fTagCutSumm) break;
266 AliInfo(Form("No tag summary map in input tree\n"));
271 TObjString *ostr = 0;
272 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
273 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
275 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
279 iTagInfo = strdup(ostr->GetString().Data());
281 Int_t iAcc = atoi(strtok(iTagInfo, ","));
283 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
289 Int_t AliESDInputHandler::GetNEventRejectedInFile()
291 // Get number of events in file rejected 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 strtok(iTagInfo, ",");
320 Int_t iRej = atoi(strtok(NULL, ","));
322 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
328 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
330 // Get number of events in the full chain
331 // Count accepted and rejected events
332 // return kFALSE 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 TMapIter *tIter = new TMapIter(fTagCutSumm);
351 Int_t iTotList=0, iAccList=0, iRejList=0;
354 while ((cobj = tIter->Next())) {
355 TObjString *kstr = (TObjString *) cobj;
356 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
357 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
359 iTagInfo = strdup(vstr->GetString().Data());
361 Int_t iAcc = atoi(strtok(iTagInfo, ","));
362 Int_t iRej = atoi(strtok(NULL, ","));
366 iTotList += (iAcc+iRej);
370 *aAccepted = iAccList;
371 *aRejected = iRejList;
376 Int_t AliESDInputHandler::GetNFilesEmpty()
378 // Count number of files in which all events were de-selected
379 // For such files Notify() will NOT be called
380 // return -1 if no info is available
382 TList *luo = fTree->GetUserInfo();
384 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
387 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
388 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
389 if (fTagCutSumm) break;
392 AliInfo(Form("No tag summary map in input tree\n"));
397 TMapIter *tIter = new TMapIter(fTagCutSumm);
399 Int_t iFilesEmpty = 0;
402 while ((cobj = tIter->Next())) {
403 TObjString *kstr = (TObjString *) cobj;
404 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
405 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
407 iTagInfo = strdup(vstr->GetString().Data());
409 Int_t iAcc = atoi(strtok(iTagInfo, ","));
410 Int_t iRej = atoi(strtok(NULL, ","));
412 if ((iAcc == 0) && ((iRej+iAcc)>0))