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 fFriendFileName("AliESDfriends.root")
66 // default constructor
69 //______________________________________________________________________________
70 AliESDInputHandler::~AliESDInputHandler()
75 //______________________________________________________________________________
76 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
77 AliInputEventHandler(name, title), fEvent(0x0), fFriend(0x0), fESDpid(0x0), fAnalysisType(0),
78 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0), fReadFriends(1), fFriendFileName("AliESDfriends.root")
83 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
86 // Initialisation necessary for each new tree
91 if (!fTree) return kFALSE;
95 if (!fEvent) fEvent = new AliESDEvent();
96 fEvent->ReadFromTree(fTree);
97 fNEvents = fTree->GetEntries();
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);
127 Bool_t AliESDInputHandler::FinishEvent()
130 if(fEvent)fEvent->Reset();
134 Bool_t AliESDInputHandler::Notify(const char* path)
136 // Notify a directory change
137 AliInfo(Form("Directory change %s \n", path));
139 // Handle the friends first
141 if (!fTree->FindBranch("ESDfriend.") && fReadFriends) {
142 // Try to add ESDfriend. branch as friend
143 TString esdTreeFName, esdFriendTreeFName;
144 esdTreeFName = (fTree->GetCurrentFile())->GetName();
145 esdFriendTreeFName = esdTreeFName;
146 if(esdFriendTreeFName.Contains("#AliESDs.root")) {
147 TString name = fFriendFileName;
149 esdFriendTreeFName.ReplaceAll("#AliESDs.root", name.Data());
151 esdFriendTreeFName.ReplaceAll("AliESDs.root", fFriendFileName.Data());
154 TTree* cTree = fTree->GetTree();
155 if (!cTree) cTree = fTree;
157 cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data());
158 cTree->SetBranchStatus("ESDfriend.", 1);
159 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
160 cTree->SetBranchAddress("ESDfriend.", &fFriend);
166 fFriend = (AliESDfriend*)(fEvent->FindListObject("AliESDfriend"));
171 // Get HLTesdTree from current file
172 TTree* cTree = fTree;
173 if (fTree->GetTree()) cTree = fTree->GetTree();
174 TFile* cFile = cTree->GetCurrentFile();
175 cFile->GetObject("HLTesdTree", fHLTTree);
178 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
179 fHLTEvent->ReadFromTree(fHLTTree);
186 if (!fUseTags) return (kTRUE);
190 TString fileName(path);
191 if(fileName.Contains("#AliESDs.root")){
194 else if (fileName.Contains("AliESDs.root")){
195 fileName.ReplaceAll("AliESDs.root", "");
197 else if(fileName.Contains("#AliAOD.root")){
200 else if(fileName.Contains("AliAOD.root")){
201 fileName.ReplaceAll("AliAOD.root", "");
203 else if(fileName.Contains("#galice.root")){
204 // For running with galice and kinematics alone...
207 else if(fileName.Contains("galice.root")){
208 // For running with galice and kinematics alone...
209 fileName.ReplaceAll("galice.root", "");
213 TString pathName("./");
214 if (fileName.Length() != 0) {
218 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
223 fRunTag = new AliRunTag();
226 delete fTreeT; fTreeT = 0;
234 fChainT = new TChain("T");
239 const char* tagPattern = "ESD.tag.root";
240 const char* name = 0x0;
243 TFile* file = fTree->GetCurrentFile();
244 TArchiveFile* arch = file->GetArchive();
245 TObjArray* arr = arch->GetMembers();
248 while ((file = (TFile*) next())) {
249 name = file->GetName();
250 if (strstr(name,tagPattern)) {
251 tagFilename = pathName.Data();
254 fChainT->Add(tagFilename);
255 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
257 } // archive file loop
259 void * dirp = gSystem->OpenDirectory(pathName.Data());
260 while((name = gSystem->GetDirEntry(dirp))) {
261 if (strstr(name,tagPattern)) {
262 tagFilename = pathName.Data();
265 fChainT->Add(tagFilename);
266 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
270 fChainT->SetBranchAddress("AliTAG",&fRunTag);
271 fChainT->GetEntry(0);
277 Option_t *AliESDInputHandler::GetDataType() const
279 // Returns handled data type.
283 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
285 // Get number of events in file accepted 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 Int_t iAcc = atoi(strtok(iTagInfo, ","));
315 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
321 Int_t AliESDInputHandler::GetNEventRejectedInFile()
323 // Get number of events in file rejected by the tag cuts
324 // return -1 if no info is available
326 TList *luo = fTree->GetUserInfo();
328 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
331 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
332 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
333 if (fTagCutSumm) break;
336 AliInfo(Form("No tag summary map in input tree\n"));
341 TObjString *ostr = 0;
342 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
343 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
345 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
349 iTagInfo = strdup(ostr->GetString().Data());
351 strtok(iTagInfo, ",");
352 Int_t iRej = atoi(strtok(NULL, ","));
354 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
360 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
362 // Get number of events in the full chain
363 // Count accepted and rejected events
364 // return kFALSE if no info is available
366 TList *luo = fTree->GetUserInfo();
368 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
371 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
372 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
373 if (fTagCutSumm) break;
376 AliInfo(Form("No tag summary map in input tree\n"));
381 TMapIter *tIter = new TMapIter(fTagCutSumm);
383 Int_t iTotList=0, iAccList=0, iRejList=0;
386 while ((cobj = tIter->Next())) {
387 TObjString *kstr = (TObjString *) cobj;
388 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
389 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
391 iTagInfo = strdup(vstr->GetString().Data());
393 Int_t iAcc = atoi(strtok(iTagInfo, ","));
394 Int_t iRej = atoi(strtok(NULL, ","));
398 iTotList += (iAcc+iRej);
402 *aAccepted = iAccList;
403 *aRejected = iRejList;
408 Int_t AliESDInputHandler::GetNFilesEmpty()
410 // Count number of files in which all events were de-selected
411 // For such files Notify() will NOT be called
412 // return -1 if no info is available
414 TList *luo = fTree->GetUserInfo();
416 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
419 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
420 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
421 if (fTagCutSumm) break;
424 AliInfo(Form("No tag summary map in input tree\n"));
429 TMapIter *tIter = new TMapIter(fTagCutSumm);
431 Int_t iFilesEmpty = 0;
434 while ((cobj = tIter->Next())) {
435 TObjString *kstr = (TObjString *) cobj;
436 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
437 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
439 iTagInfo = strdup(vstr->GetString().Data());
441 Int_t iAcc = atoi(strtok(iTagInfo, ","));
442 Int_t iRej = atoi(strtok(NULL, ","));
444 if ((iAcc == 0) && ((iRej+iAcc)>0))