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 (!fTree->FindBranch("ESDfriend.")) {
96 // Try to add ESDfriend. branch as friend
97 TString esdTreeFName, esdFriendTreeFName;
98 TTree* theTree = fTree->GetTree();
99 if (!theTree) theTree = tree;
100 esdTreeFName = (theTree->GetCurrentFile())->GetName();
101 esdFriendTreeFName = esdTreeFName;
102 esdFriendTreeFName.ReplaceAll("AliESDs.root", "AliESDfriends.root");
103 theTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
106 if (!fEvent) fEvent = new AliESDEvent();
107 fEvent->ReadFromTree(fTree);
108 fNEvents = fTree->GetEntries();
109 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
113 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
116 // Copy from old to new format if necessary
117 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
119 ((AliESDEvent*)fEvent)->CopyFromOldESD();
124 fHLTTree->GetEntry(entry);
132 fIsSelected = fEventCuts->IsSelected((AliESDEvent*)fEvent);
135 ((AliESDEvent*)fEvent)->SetESDfriend(fFriend);
140 Bool_t AliESDInputHandler::FinishEvent()
143 if(fEvent)fEvent->Reset();
147 Bool_t AliESDInputHandler::Notify(const char* path)
149 // Notify a directory change
150 AliInfo(Form("Directory change %s \n", path));
153 // Get HLTesdTree from current file
154 TTree* cTree = fTree;
155 if (fTree->GetTree()) cTree = fTree->GetTree();
156 TFile* cFile = cTree->GetCurrentFile();
157 cFile->GetObject("HLTesdTree", fHLTTree);
160 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
161 fHLTEvent->ReadFromTree(fHLTTree);
165 if (!fUseTags) return (kTRUE);
169 TString fileName(path);
170 if(fileName.Contains("#AliESDs.root")){
173 else if (fileName.Contains("AliESDs.root")){
174 fileName.ReplaceAll("AliESDs.root", "");
176 else if(fileName.Contains("#AliAOD.root")){
179 else if(fileName.Contains("AliAOD.root")){
180 fileName.ReplaceAll("AliAOD.root", "");
182 else if(fileName.Contains("#galice.root")){
183 // For running with galice and kinematics alone...
186 else if(fileName.Contains("galice.root")){
187 // For running with galice and kinematics alone...
188 fileName.ReplaceAll("galice.root", "");
192 TString pathName("./");
193 if (fileName.Length() != 0) {
197 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
202 fRunTag = new AliRunTag();
205 delete fTreeT; fTreeT = 0;
213 fChainT = new TChain("T");
218 const char* tagPattern = "ESD.tag.root";
219 const char* name = 0x0;
222 TFile* file = fTree->GetCurrentFile();
223 TArchiveFile* arch = file->GetArchive();
224 TObjArray* arr = arch->GetMembers();
227 while ((file = (TFile*) next())) {
228 name = file->GetName();
229 if (strstr(name,tagPattern)) {
230 tagFilename = pathName.Data();
233 fChainT->Add(tagFilename);
234 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
236 } // archive file loop
238 void * dirp = gSystem->OpenDirectory(pathName.Data());
239 while((name = gSystem->GetDirEntry(dirp))) {
240 if (strstr(name,tagPattern)) {
241 tagFilename = pathName.Data();
244 fChainT->Add(tagFilename);
245 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
249 fChainT->SetBranchAddress("AliTAG",&fRunTag);
250 fChainT->GetEntry(0);
256 Option_t *AliESDInputHandler::GetDataType() const
258 // Returns handled data type.
262 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
264 // Get number of events in file accepted by the tag cuts
265 // return -1 if no info is available
267 TList *luo = fTree->GetUserInfo();
269 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
272 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
273 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
274 if (fTagCutSumm) break;
277 AliInfo(Form("No tag summary map in input tree\n"));
282 TObjString *ostr = 0;
283 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
284 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
286 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
290 iTagInfo = strdup(ostr->GetString().Data());
292 Int_t iAcc = atoi(strtok(iTagInfo, ","));
294 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
300 Int_t AliESDInputHandler::GetNEventRejectedInFile()
302 // Get number of events in file rejected by the tag cuts
303 // return -1 if no info is available
305 TList *luo = fTree->GetUserInfo();
307 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
310 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
311 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
312 if (fTagCutSumm) break;
315 AliInfo(Form("No tag summary map in input tree\n"));
320 TObjString *ostr = 0;
321 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
322 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
324 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
328 iTagInfo = strdup(ostr->GetString().Data());
330 strtok(iTagInfo, ",");
331 Int_t iRej = atoi(strtok(NULL, ","));
333 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
339 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
341 // Get number of events in the full chain
342 // Count accepted and rejected events
343 // return kFALSE if no info is available
345 TList *luo = fTree->GetUserInfo();
347 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
350 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
351 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
352 if (fTagCutSumm) break;
355 AliInfo(Form("No tag summary map in input tree\n"));
360 TMapIter *tIter = new TMapIter(fTagCutSumm);
362 Int_t iTotList=0, iAccList=0, iRejList=0;
365 while ((cobj = tIter->Next())) {
366 TObjString *kstr = (TObjString *) cobj;
367 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
368 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
370 iTagInfo = strdup(vstr->GetString().Data());
372 Int_t iAcc = atoi(strtok(iTagInfo, ","));
373 Int_t iRej = atoi(strtok(NULL, ","));
377 iTotList += (iAcc+iRej);
381 *aAccepted = iAccList;
382 *aRejected = iRejList;
387 Int_t AliESDInputHandler::GetNFilesEmpty()
389 // Count number of files in which all events were de-selected
390 // For such files Notify() will NOT be called
391 // return -1 if no info is available
393 TList *luo = fTree->GetUserInfo();
395 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
398 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
399 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
400 if (fTagCutSumm) break;
403 AliInfo(Form("No tag summary map in input tree\n"));
408 TMapIter *tIter = new TMapIter(fTagCutSumm);
410 Int_t iFilesEmpty = 0;
413 while ((cobj = tIter->Next())) {
414 TObjString *kstr = (TObjString *) cobj;
415 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
416 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
418 iTagInfo = strdup(vstr->GetString().Data());
420 Int_t iAcc = atoi(strtok(iTagInfo, ","));
421 Int_t iRej = atoi(strtok(NULL, ","));
423 if ((iAcc == 0) && ((iRej+iAcc)>0))