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"
38 #include "AliRunTag.h"
39 #include "AliEventTag.h"
42 ClassImp(AliESDInputHandler)
44 static Option_t *gESDDataType = "ESD";
46 //______________________________________________________________________________
47 AliESDInputHandler::AliESDInputHandler() :
48 AliInputEventHandler(),
61 // default constructor
64 //______________________________________________________________________________
65 AliESDInputHandler::~AliESDInputHandler()
71 //______________________________________________________________________________
72 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
73 AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0),
74 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
79 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
81 // Initialisation necessary for each new tree
85 if (!fTree) return kFALSE;
88 // Get pointer to ESD event
92 if (!fEvent) fEvent = new AliESDEvent();
93 fEvent->ReadFromTree(fTree);
94 fNEvents = fTree->GetEntries();
100 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
102 // Copy from old to new format if necessary
103 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
105 ((AliESDEvent*)fEvent)->CopyFromOldESD();
110 fHLTTree->GetEntry(entry);
118 fIsSelected = fEventCuts->IsSelected(fEvent);
123 Bool_t AliESDInputHandler::FinishEvent()
126 if(fEvent)fEvent->Reset();
130 Bool_t AliESDInputHandler::Notify(const char* path)
132 // Notify a directory change
133 AliInfo(Form("Directory change %s \n", path));
136 // Get HLTesdTree from current file
137 TTree* cTree = fTree;
138 if (fTree->GetTree()) cTree = fTree->GetTree();
139 TFile* cFile = cTree->GetCurrentFile();
140 cFile->GetObject("HLTesdTree", fHLTTree);
143 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
144 fHLTEvent->ReadFromTree(fHLTTree);
148 if (!fUseTags) return (kTRUE);
152 TString fileName(path);
153 if(fileName.Contains("#AliESDs.root")){
156 else if (fileName.Contains("AliESDs.root")){
157 fileName.ReplaceAll("AliESDs.root", "");
159 else if(fileName.Contains("#AliAOD.root")){
162 else if(fileName.Contains("AliAOD.root")){
163 fileName.ReplaceAll("AliAOD.root", "");
165 else if(fileName.Contains("#galice.root")){
166 // For running with galice and kinematics alone...
169 else if(fileName.Contains("galice.root")){
170 // For running with galice and kinematics alone...
171 fileName.ReplaceAll("galice.root", "");
175 TString pathName("./");
176 if (fileName.Length() != 0) {
180 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
185 fRunTag = new AliRunTag();
188 delete fTreeT; fTreeT = 0;
196 fChainT = new TChain("T");
201 const char* tagPattern = "ESD.tag.root";
202 const char* name = 0x0;
205 TFile* file = fTree->GetCurrentFile();
206 TArchiveFile* arch = file->GetArchive();
207 TObjArray* arr = arch->GetMembers();
210 while ((file = (TFile*) next())) {
211 name = file->GetName();
212 if (strstr(name,tagPattern)) {
213 tagFilename = pathName.Data();
216 fChainT->Add(tagFilename);
217 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
219 } // archive file loop
221 void * dirp = gSystem->OpenDirectory(pathName.Data());
222 while((name = gSystem->GetDirEntry(dirp))) {
223 if (strstr(name,tagPattern)) {
224 tagFilename = pathName.Data();
227 fChainT->Add(tagFilename);
228 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
232 fChainT->SetBranchAddress("AliTAG",&fRunTag);
233 fChainT->GetEntry(0);
239 Option_t *AliESDInputHandler::GetDataType() const
241 // Returns handled data type.
245 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
247 // Get number of events in file accepted by the tag cuts
248 // return -1 if no info is available
250 TList *luo = fTree->GetUserInfo();
252 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
255 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
256 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
257 if (fTagCutSumm) break;
260 AliInfo(Form("No tag summary map in input tree\n"));
265 TObjString *ostr = 0;
266 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
267 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
269 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
273 iTagInfo = strdup(ostr->GetString().Data());
275 Int_t iAcc = atoi(strtok(iTagInfo, ","));
277 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
283 Int_t AliESDInputHandler::GetNEventRejectedInFile()
285 // Get number of events in file rejected by the tag cuts
286 // return -1 if no info is available
288 TList *luo = fTree->GetUserInfo();
290 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
293 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
294 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
295 if (fTagCutSumm) break;
298 AliInfo(Form("No tag summary map in input tree\n"));
303 TObjString *ostr = 0;
304 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
305 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
307 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
311 iTagInfo = strdup(ostr->GetString().Data());
313 strtok(iTagInfo, ",");
314 Int_t iRej = atoi(strtok(NULL, ","));
316 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
322 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
324 // Get number of events in the full chain
325 // Count accepted and rejected events
326 // return kFALSE if no info is available
328 TList *luo = fTree->GetUserInfo();
330 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
333 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
334 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
335 if (fTagCutSumm) break;
338 AliInfo(Form("No tag summary map in input tree\n"));
343 TMapIter *tIter = new TMapIter(fTagCutSumm);
345 Int_t iTotList=0, iAccList=0, iRejList=0;
348 while ((cobj = tIter->Next())) {
349 TObjString *kstr = (TObjString *) cobj;
350 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
351 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
353 iTagInfo = strdup(vstr->GetString().Data());
355 Int_t iAcc = atoi(strtok(iTagInfo, ","));
356 Int_t iRej = atoi(strtok(NULL, ","));
360 iTotList += (iAcc+iRej);
364 *aAccepted = iAccList;
365 *aRejected = iRejList;
370 Int_t AliESDInputHandler::GetNFilesEmpty()
372 // Count number of files in which all events were de-selected
373 // For such files Notify() will NOT be called
374 // return -1 if no info is available
376 TList *luo = fTree->GetUserInfo();
378 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
381 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
382 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
383 if (fTagCutSumm) break;
386 AliInfo(Form("No tag summary map in input tree\n"));
391 TMapIter *tIter = new TMapIter(fTagCutSumm);
393 Int_t iFilesEmpty = 0;
396 while ((cobj = tIter->Next())) {
397 TObjString *kstr = (TObjString *) cobj;
398 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
399 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
401 iTagInfo = strdup(vstr->GetString().Data());
403 Int_t iAcc = atoi(strtok(iTagInfo, ","));
404 Int_t iRej = atoi(strtok(NULL, ","));
406 if ((iAcc == 0) && ((iRej+iAcc)>0))