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"
37 #include "AliRunTag.h"
38 #include "AliEventTag.h"
41 ClassImp(AliESDInputHandler)
43 static Option_t *gESDDataType = "ESD";
45 //______________________________________________________________________________
46 AliESDInputHandler::AliESDInputHandler() :
47 AliInputEventHandler(),
60 // default constructor
63 //______________________________________________________________________________
64 AliESDInputHandler::~AliESDInputHandler()
70 //______________________________________________________________________________
71 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
72 AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0),
73 fNEvents(0), fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
78 Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* opt)
80 // Initialisation necessary for each new tree
84 if (!fTree) return kFALSE;
87 // Get pointer to ESD event
91 if (!fEvent) fEvent = new AliESDEvent();
92 fEvent->ReadFromTree(fTree);
93 fNEvents = fTree->GetEntries();
99 Bool_t AliESDInputHandler::BeginEvent(Long64_t entry)
101 // Copy from old to new format if necessary
102 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
104 ((AliESDEvent*)fEvent)->CopyFromOldESD();
109 fHLTTree->GetEntry(entry);
115 Bool_t AliESDInputHandler::FinishEvent()
118 if(fEvent)fEvent->Reset();
122 Bool_t AliESDInputHandler::Notify(const char* path)
124 // Notify a directory change
125 AliInfo(Form("Directory change %s \n", path));
128 // Get HLTesdTree from current file
129 TTree* cTree = fTree;
130 if (fTree->GetTree()) cTree = fTree->GetTree();
131 TFile* cFile = cTree->GetCurrentFile();
132 cFile->GetObject("HLTesdTree", fHLTTree);
135 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
136 fHLTEvent->ReadFromTree(fHLTTree);
140 if (!fUseTags) return (kTRUE);
144 TString fileName(path);
145 if(fileName.Contains("#AliESDs.root")){
148 else if (fileName.Contains("AliESDs.root")){
149 fileName.ReplaceAll("AliESDs.root", "");
151 else if(fileName.Contains("#AliAOD.root")){
154 else if(fileName.Contains("AliAOD.root")){
155 fileName.ReplaceAll("AliAOD.root", "");
157 else if(fileName.Contains("#galice.root")){
158 // For running with galice and kinematics alone...
161 else if(fileName.Contains("galice.root")){
162 // For running with galice and kinematics alone...
163 fileName.ReplaceAll("galice.root", "");
167 TString pathName("./");
168 if (fileName.Length() != 0) {
172 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
177 fRunTag = new AliRunTag();
180 delete fTreeT; fTreeT = 0;
188 fChainT = new TChain("T");
193 const char* tagPattern = "ESD.tag.root";
194 const char* name = 0x0;
197 TFile* file = fTree->GetCurrentFile();
198 TArchiveFile* arch = file->GetArchive();
199 TObjArray* arr = arch->GetMembers();
202 while ((file = (TFile*) next())) {
203 name = file->GetName();
204 if (strstr(name,tagPattern)) {
205 tagFilename = pathName.Data();
208 fChainT->Add(tagFilename);
209 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
211 } // archive file loop
213 void * dirp = gSystem->OpenDirectory(pathName.Data());
214 while((name = gSystem->GetDirEntry(dirp))) {
215 if (strstr(name,tagPattern)) {
216 tagFilename = pathName.Data();
219 fChainT->Add(tagFilename);
220 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
224 fChainT->SetBranchAddress("AliTAG",&fRunTag);
225 fChainT->GetEntry(0);
231 Option_t *AliESDInputHandler::GetDataType() const
233 // Returns handled data type.
237 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
239 // Get number of events in file accepted by the tag cuts
240 // return -1 if no info is available
242 TList *luo = fTree->GetUserInfo();
244 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
247 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
248 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
249 if (fTagCutSumm) break;
252 AliInfo(Form("No tag summary map in input tree\n"));
257 TObjString *ostr = 0;
258 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
259 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
261 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
265 iTagInfo = strdup(ostr->GetString().Data());
267 Int_t iAcc = atoi(strtok(iTagInfo, ","));
269 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
275 Int_t AliESDInputHandler::GetNEventRejectedInFile()
277 // Get number of events in file rejected by the tag cuts
278 // return -1 if no info is available
280 TList *luo = fTree->GetUserInfo();
282 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
285 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
286 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
287 if (fTagCutSumm) break;
290 AliInfo(Form("No tag summary map in input tree\n"));
295 TObjString *ostr = 0;
296 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
297 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
299 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
303 iTagInfo = strdup(ostr->GetString().Data());
305 strtok(iTagInfo, ",");
306 Int_t iRej = atoi(strtok(NULL, ","));
308 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
314 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
316 // Get number of events in the full chain
317 // Count accepted and rejected events
318 // return kFALSE if no info is available
320 TList *luo = fTree->GetUserInfo();
322 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
325 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
326 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
327 if (fTagCutSumm) break;
330 AliInfo(Form("No tag summary map in input tree\n"));
335 TMapIter *tIter = new TMapIter(fTagCutSumm);
337 Int_t iTotList=0, iAccList=0, iRejList=0;
340 while ((cobj = tIter->Next())) {
341 TObjString *kstr = (TObjString *) cobj;
342 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
343 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
345 iTagInfo = strdup(vstr->GetString().Data());
347 Int_t iAcc = atoi(strtok(iTagInfo, ","));
348 Int_t iRej = atoi(strtok(NULL, ","));
352 iTotList += (iAcc+iRej);
356 *aAccepted = iAccList;
357 *aRejected = iRejList;
362 Int_t AliESDInputHandler::GetNFilesEmpty()
364 // Count number of files in which all events were de-selected
365 // For such files Notify() will NOT be called
366 // return -1 if no info is available
368 TList *luo = fTree->GetUserInfo();
370 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
373 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
374 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
375 if (fTagCutSumm) break;
378 AliInfo(Form("No tag summary map in input tree\n"));
383 TMapIter *tIter = new TMapIter(fTagCutSumm);
385 Int_t iFilesEmpty = 0;
388 while ((cobj = tIter->Next())) {
389 TObjString *kstr = (TObjString *) cobj;
390 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
391 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
393 iTagInfo = strdup(vstr->GetString().Data());
395 Int_t iAcc = atoi(strtok(iTagInfo, ","));
396 Int_t iRej = atoi(strtok(NULL, ","));
398 if ((iAcc == 0) && ((iRej+iAcc)>0))