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()));
101 if (!file) AliFatal(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
106 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
108 AliFatal(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
112 // Reset the event number
115 // Get number of events from esd tree
116 printf("AliESDInputHandlerRP::Init() %d %d\n",__LINE__, fNEvents);
120 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
122 // Begin the next event
126 entry = fEventNumber;
128 fEventNumber = entry;
131 if (entry >= fNEvents) {
132 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvents));
138 // Delegate to base class
139 return AliESDInputHandler::BeginEvent(entry);
143 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
145 // Load the event number iev
147 // Calculate the file number
148 Int_t inew = iev / fEventsPerFile;
149 if (inew != fFileNumber) {
151 if (!OpenFile(fFileNumber)){
157 sprintf(folder, "Event%d", iev);
163 while ((file = (TFile*) next()))
165 file->GetObject(folder, fDirR);
168 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
172 fDirR->GetObject("TreeR", tree);
173 fRDirs ->AddAt(fDirR, idx );
174 fRTrees->AddAt(tree, idx++);
179 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
184 fExtension = Form("%d", i);
190 TIter next(fDetectors);
193 while ((det = (TNamed*) next()))
196 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
198 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
200 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
206 Bool_t AliESDInputHandlerRP::Notify(const char *path)
208 // Notify about directory change
209 // The directory is taken from the 'path' argument
211 AliInfo(Form("Directory change %s \n", path));
212 // Get path to directory
213 TString fileName(path);
215 if(fileName.Contains("#")){
216 // If this is an archive it will contain a #
218 } else if(fileName.Contains("AliESDs.root")){
219 fileName.ReplaceAll("AliESDs.root", "");
223 // At this point we have a path to the directory or to the archive anchor
224 *fPathName = fileName;
226 // Now filter the files containing RecPoints *.RecPoints.*
228 TSeqCollection* members;
233 TFile* file = TFile::Open(fPathName->Data());
234 TArchiveFile* arch = file->GetArchive();
235 members = arch->GetMembers();
237 // Directory or alien archive
238 if (fileName.BeginsWith("alien:")) {
239 TFile* file = TFile::Open(Form("%s/root_archive.zip", fPathName->Data()));
240 TArchiveFile* arch = file->GetArchive();
241 members = arch->GetMembers();
243 TString wd = gSystem->WorkingDirectory();
244 TSystemDirectory dir(".", fPathName->Data());
245 members = dir.GetListOfFiles();
253 fDetectors->Delete();
255 while ( (entry = (TFile*) next()) )
257 TString name(entry->GetName());
258 TObjArray* tokens = name.Tokenize(".");
259 Int_t ntok = tokens->GetEntries();
260 if (ntok <= 1) continue;
261 TString str = ((TObjString*) tokens->At(1))->GetString();
262 if (!(strcmp(str.Data(), "RecPoints"))){
263 TString det = ((TObjString*) tokens->At(0))->GetString();
264 printf("Found file with RecPoints for %s \n", det.Data());
265 TNamed* ent = new TNamed(det.Data(), det.Data());
266 fRTrees->AddAt(0, ien);
267 ent->SetUniqueID(ien++);
268 fDetectors->Add(ent);
270 if(tokens) delete tokens;
274 // Now we have the path and the list of detectors
276 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
286 Bool_t AliESDInputHandlerRP::FinishEvent()
288 // Clean-up after each event
290 AliESDInputHandler::FinishEvent();
294 void AliESDInputHandlerRP::ResetIO()
296 // Delete trees and files
297 fRFiles->Clear("nodelete");
301 TTree* AliESDInputHandlerRP::GetTreeR(const char* det)
303 // Return pointer to RecPoint tree for detector det
304 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
306 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
309 Int_t ien = entry->GetUniqueID();
310 return ((TTree*) (fRTrees->At(ien)));