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);
117 Bool_t AliESDInputHandler::FinishEvent()
120 if(fEvent)fEvent->Reset();
124 Bool_t AliESDInputHandler::Notify(const char* path)
126 // Notify a directory change
127 AliInfo(Form("Directory change %s \n", path));
130 // Get HLTesdTree from current file
131 TTree* cTree = fTree;
132 if (fTree->GetTree()) cTree = fTree->GetTree();
133 TFile* cFile = cTree->GetCurrentFile();
134 cFile->GetObject("HLTesdTree", fHLTTree);
137 if (!fHLTEvent) fHLTEvent = new AliESDEvent();
138 fHLTEvent->ReadFromTree(fHLTTree);
142 if (!fUseTags) return (kTRUE);
146 TString fileName(path);
147 if(fileName.Contains("#AliESDs.root")){
150 else if (fileName.Contains("AliESDs.root")){
151 fileName.ReplaceAll("AliESDs.root", "");
153 else if(fileName.Contains("#AliAOD.root")){
156 else if(fileName.Contains("AliAOD.root")){
157 fileName.ReplaceAll("AliAOD.root", "");
159 else if(fileName.Contains("#galice.root")){
160 // For running with galice and kinematics alone...
163 else if(fileName.Contains("galice.root")){
164 // For running with galice and kinematics alone...
165 fileName.ReplaceAll("galice.root", "");
169 TString pathName("./");
170 if (fileName.Length() != 0) {
174 printf("AliESDInputHandler::Notify() Path: %s\n", pathName.Data());
179 fRunTag = new AliRunTag();
182 delete fTreeT; fTreeT = 0;
190 fChainT = new TChain("T");
195 const char* tagPattern = "ESD.tag.root";
196 const char* name = 0x0;
199 TFile* file = fTree->GetCurrentFile();
200 TArchiveFile* arch = file->GetArchive();
201 TObjArray* arr = arch->GetMembers();
204 while ((file = (TFile*) next())) {
205 name = file->GetName();
206 if (strstr(name,tagPattern)) {
207 tagFilename = pathName.Data();
210 fChainT->Add(tagFilename);
211 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
213 } // archive file loop
215 void * dirp = gSystem->OpenDirectory(pathName.Data());
216 while((name = gSystem->GetDirEntry(dirp))) {
217 if (strstr(name,tagPattern)) {
218 tagFilename = pathName.Data();
221 fChainT->Add(tagFilename);
222 AliInfo(Form("Adding %s to tag chain \n", tagFilename.Data()));
226 fChainT->SetBranchAddress("AliTAG",&fRunTag);
227 fChainT->GetEntry(0);
233 Option_t *AliESDInputHandler::GetDataType() const
235 // Returns handled data type.
239 Int_t AliESDInputHandler::GetNEventAcceptedInFile()
241 // Get number of events in file accepted by the tag cuts
242 // return -1 if no info is available
244 TList *luo = fTree->GetUserInfo();
246 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
249 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
250 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
251 if (fTagCutSumm) break;
254 AliInfo(Form("No tag summary map in input tree\n"));
259 TObjString *ostr = 0;
260 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
261 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
263 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
267 iTagInfo = strdup(ostr->GetString().Data());
269 Int_t iAcc = atoi(strtok(iTagInfo, ","));
271 AliInfo(Form("Got %i accepted events for file %s", iAcc, fTree->GetCurrentFile()->GetName()));
277 Int_t AliESDInputHandler::GetNEventRejectedInFile()
279 // Get number of events in file rejected by the tag cuts
280 // return -1 if no info is available
282 TList *luo = fTree->GetUserInfo();
284 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
287 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
288 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
289 if (fTagCutSumm) break;
292 AliInfo(Form("No tag summary map in input tree\n"));
297 TObjString *ostr = 0;
298 if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
299 ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
301 AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
305 iTagInfo = strdup(ostr->GetString().Data());
307 strtok(iTagInfo, ",");
308 Int_t iRej = atoi(strtok(NULL, ","));
310 AliInfo(Form("Got %i accepted events for file %s", iRej, fTree->GetCurrentFile()->GetName()));
316 Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
318 // Get number of events in the full chain
319 // Count accepted and rejected events
320 // return kFALSE if no info is available
322 TList *luo = fTree->GetUserInfo();
324 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
327 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
328 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
329 if (fTagCutSumm) break;
332 AliInfo(Form("No tag summary map in input tree\n"));
337 TMapIter *tIter = new TMapIter(fTagCutSumm);
339 Int_t iTotList=0, iAccList=0, iRejList=0;
342 while ((cobj = tIter->Next())) {
343 TObjString *kstr = (TObjString *) cobj;
344 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
345 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
347 iTagInfo = strdup(vstr->GetString().Data());
349 Int_t iAcc = atoi(strtok(iTagInfo, ","));
350 Int_t iRej = atoi(strtok(NULL, ","));
354 iTotList += (iAcc+iRej);
358 *aAccepted = iAccList;
359 *aRejected = iRejList;
364 Int_t AliESDInputHandler::GetNFilesEmpty()
366 // Count number of files in which all events were de-selected
367 // For such files Notify() will NOT be called
368 // return -1 if no info is available
370 TList *luo = fTree->GetUserInfo();
372 AliInfo(Form("No user info in input tree - no tag cut summary\n"));
375 for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
376 fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
377 if (fTagCutSumm) break;
380 AliInfo(Form("No tag summary map in input tree\n"));
385 TMapIter *tIter = new TMapIter(fTagCutSumm);
387 Int_t iFilesEmpty = 0;
390 while ((cobj = tIter->Next())) {
391 TObjString *kstr = (TObjString *) cobj;
392 TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
393 // printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
395 iTagInfo = strdup(vstr->GetString().Data());
397 Int_t iAcc = atoi(strtok(iTagInfo, ","));
398 Int_t iRej = atoi(strtok(NULL, ","));
400 if ((iAcc == 0) && ((iRej+iAcc)>0))