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 reading the RecPoint Trees in parallel
20 // Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
26 #include <TArchiveFile.h>
27 #include <TSystemDirectory.h>
29 #include <TObjString.h>
30 #include <TProcessID.h>
32 #include "AliESDInputHandlerRP.h"
33 #include "AliESDEvent.h"
37 ClassImp(AliESDInputHandlerRP)
39 //______________________________________________________________________________
40 AliESDInputHandlerRP::AliESDInputHandlerRP() :
42 fRTrees( new TList()),
43 fRFiles( new TList()),
44 fDetectors(new TList()),
51 fPathName(new TString("./")),
54 // Default constructor
58 //______________________________________________________________________________
59 AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
60 AliESDInputHandler(name, title),
61 fRTrees( new TList()),
62 fRFiles( new TList()),
63 fDetectors(new TList()),
70 fPathName(new TString("./")),
76 //______________________________________________________________________________
77 AliESDInputHandlerRP::~AliESDInputHandlerRP()
82 Bool_t AliESDInputHandlerRP::Init(Option_t* opt)
87 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
89 TIter next(fDetectors);
92 while ((det = (TNamed*) next()))
95 file = TFile::Open(Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName()));
97 file = TFile::Open(Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName()));
99 if (!file) AliFatal(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
103 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
105 AliFatal(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
109 // Reset the event number
112 // Get number of events from esd tree
113 fNEvent = fTree->GetEntries();
115 printf("AliESDInputHandler::Init() %d\n",__LINE__);
119 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
121 // Begin the next event
122 // Delegate first to base class
123 AliESDInputHandler::BeginEvent(entry);
127 entry = fEventNumber;
129 fEventNumber = entry;
132 if (entry >= fNEvent) {
133 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvent));
136 return LoadEvent(entry);
139 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
141 // Load the event number iev
143 // Calculate the file number
144 Int_t inew = iev / fEventsPerFile;
145 if (inew != fFileNumber) {
147 if (!OpenFile(fFileNumber)){
153 sprintf(folder, "Event%d", iev);
159 while ((file = (TFile*) next()))
161 file->GetObject(folder, fDirR);
163 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
167 fDirR ->GetObject("TreeR", tree);
173 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
178 fExtension = Form("%d", i);
184 TIter next(fDetectors);
187 while ((det = (TNamed*) next()))
190 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
192 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
194 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
200 Bool_t AliESDInputHandlerRP::Notify(const char *path)
202 // Notify about directory change
203 // The directory is taken from the 'path' argument
205 // Get path to directory
206 TString fileName(path);
207 if(fileName.Contains("AliESDs.root")){
208 fileName.ReplaceAll("AliESDs.root", "");
210 // If this is an archive it will contain a #
211 if(fileName.Contains("#")){
212 fileName.ReplaceAll("#", "");
215 // At this point we have a path to the directory or to the archive
216 *fPathName = fileName;
218 // Now filter the files containing RecPoints *.RecPoints.*
220 if (fPathName->Contains(".zip")) fIsArchive = kTRUE;
222 TSeqCollection* members;
226 TFile* file = TFile::Open(fPathName->Data());
227 TArchiveFile* arch = file->GetArchive();
228 members = arch->GetMembers();
231 TSystemDirectory dir(".", fPathName->Data());
232 members = dir.GetListOfFiles();
238 while ( (entry = (TFile*) next()) )
240 printf("File %s \n", entry->GetName());
241 TString name(entry->GetName());
242 TObjArray* tokens = name.Tokenize(".");
243 Int_t ntok = tokens->GetEntries();
244 if (ntok <= 1) continue;
245 TString str = ((TObjString*) tokens->At(1))->GetString();
246 if (!(strcmp(str.Data(), "RecPoints"))){
247 TString det = ((TObjString*) tokens->At(0))->GetString();
248 printf("Name %s \n", det.Data());
249 TNamed* ent = new TNamed(det.Data(), det.Data());
250 ent->SetUniqueID(ien++);
251 fDetectors->Add(ent);
256 // Now we have the path and the list of detectors
258 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
268 Bool_t AliESDInputHandlerRP::FinishEvent()
270 // Clean-up after each event
271 delete fDirR; fDirR = 0;
272 AliESDInputHandler::FinishEvent();
276 void AliESDInputHandlerRP::ResetIO()
278 // Delete trees and files
284 TTree* AliESDInputHandlerRP::GetTreeR(char* det)
286 // Return pointer to RecPoint tree for detector det
287 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
289 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
292 Int_t ien = entry->GetUniqueID();
293 return ((TTree*) (fRTrees->At(ien)));