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 <TObjArray.h>
31 #include <TProcessID.h>
34 #include "AliESDInputHandlerRP.h"
35 #include "AliESDEvent.h"
39 ClassImp(AliESDInputHandlerRP)
41 //______________________________________________________________________________
42 AliESDInputHandlerRP::AliESDInputHandlerRP() :
44 fRTrees( new TObjArray()),
45 fRDirs ( new TObjArray()),
46 fRFiles( new TList()),
47 fDetectors(new TList()),
53 fPathName(new TString("./")),
56 // Default constructor
60 //______________________________________________________________________________
61 AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
62 AliESDInputHandler(name, title),
63 fRTrees( new TObjArray()),
64 fRDirs ( new TObjArray()),
65 fRFiles( new TList()),
66 fDetectors(new TList()),
72 fPathName(new TString("./")),
78 //______________________________________________________________________________
79 AliESDInputHandlerRP::~AliESDInputHandlerRP()
84 Bool_t AliESDInputHandlerRP::Init(Option_t* opt)
89 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
91 TIter next(fDetectors);
94 while ((det = (TNamed*) next()))
97 file = TFile::Open(Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName()));
99 file = TFile::Open(Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName()));
102 AliError(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
109 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
111 AliError(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
116 // Reset the event number
119 // Get number of events from esd tree
120 printf("AliESDInputHandlerRP::Init() %d %d\n",__LINE__, fNEvents);
122 AliESDInputHandler::Init(opt);
127 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
129 // Begin the next event
133 entry = fEventNumber;
135 fEventNumber = entry;
138 if (entry >= fNEvents) {
139 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5lld %5d\n", entry, fNEvents));
145 // Delegate to base class
146 return AliESDInputHandler::BeginEvent(entry);
150 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
152 // Load the event number iev
154 // Calculate the file number
155 if (fEventsPerFile<=0) return kFALSE;
156 Int_t inew = iev / fEventsPerFile;
157 if (inew != fFileNumber) {
159 if (!OpenFile(fFileNumber)){
165 snprintf(folder, 20, "Event%d", iev);
171 while ((file = (TFile*) next()))
173 file->GetObject(folder, fDirR);
176 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
180 fDirR->GetObject("TreeR", tree);
181 fRDirs ->AddAt(fDirR, idx );
182 fRTrees->AddAt(tree, idx++);
187 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
192 fExtension = Form("%d", i);
198 TIter next(fDetectors);
201 while ((det = (TNamed*) next()))
204 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
206 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
208 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
214 Bool_t AliESDInputHandlerRP::Notify(const char *path)
216 // Notify about directory change
217 // The directory is taken from the 'path' argument
220 // Get path to directory
221 TString fileName(path);
222 if (fileName.IsNull()) return kFALSE;
223 AliInfo(Form("Directory change %s \n", path));
225 TString esdname = gSystem->BaseName(fileName);
226 Int_t index = esdname.Index("#")+1;
227 if (index) esdname.Remove(0,index);
229 if(fileName.Contains("#")){
230 // If this is an archive it will contain a #
232 } else if(fileName.Contains(esdname)){
233 fileName.ReplaceAll(esdname, "");
237 // At this point we have a path to the directory or to the archive anchor
238 *fPathName = fileName;
240 // Now filter the files containing RecPoints *.RecPoints.*
242 TSeqCollection* members;
247 TFile* file = TFile::Open(fPathName->Data());
248 TArchiveFile* arch = file->GetArchive();
249 members = arch->GetMembers();
250 fPathName->ReplaceAll("#", "");
251 fPathName->ReplaceAll(esdname, "");
253 // Directory or alien archive
254 if (fileName.BeginsWith("alien:")) {
255 TFile* file = TFile::Open(Form("%s/root_archive.zip", fPathName->Data()));
256 TArchiveFile* arch = file->GetArchive();
257 members = arch->GetMembers();
259 TString wd = gSystem->WorkingDirectory();
260 TSystemDirectory dir(".", fPathName->Data());
261 members = dir.GetListOfFiles();
269 fDetectors->Delete();
271 while ( (entry = (TFile*) next()) )
273 TString name(entry->GetName());
274 TObjArray* tokens = name.Tokenize(".");
277 ntok = tokens->GetEntries();
281 if (ntok <= 1) continue;
282 TString str = ((TObjString*) tokens->At(1))->GetString();
283 if (!(strcmp(str.Data(), "RecPoints"))){
284 TString det = ((TObjString*) tokens->At(0))->GetString();
285 printf("Found file with RecPoints for %s \n", det.Data());
286 TNamed* ent = new TNamed(det.Data(), det.Data());
287 fRTrees->AddAt(0, ien);
288 ent->SetUniqueID(ien++);
289 fDetectors->Add(ent);
291 if(tokens) delete tokens;
295 // Now we have the path and the list of detectors
297 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
302 if (members) members->Delete();
304 AliESDInputHandler::Notify(path);
309 Bool_t AliESDInputHandlerRP::FinishEvent()
311 // Clean-up after each event
313 AliESDInputHandler::FinishEvent();
317 void AliESDInputHandlerRP::ResetIO()
319 // Delete trees and files
320 fRFiles->Clear("nodelete");
324 TTree* AliESDInputHandlerRP::GetTreeR(const char* det)
326 // Return pointer to RecPoint tree for detector det
327 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
329 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
332 Int_t ien = entry->GetUniqueID();
333 return ((TTree*) (fRTrees->At(ien)));