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 fRFiles( new TList()),
46 fDetectors(new TList()),
52 fPathName(new TString("./")),
55 // Default constructor
59 //______________________________________________________________________________
60 AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
61 AliESDInputHandler(name, title),
62 fRTrees( new TObjArray()),
63 fRFiles( new TList()),
64 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()));
104 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
106 AliFatal(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
110 // Reset the event number
113 // Get number of events from esd tree
114 printf("AliESDInputHandlerRP::Init() %d %d\n",__LINE__, fNEvents);
118 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
120 // Begin the next event
121 // Delegate first to base class
122 AliESDInputHandler::BeginEvent(entry);
126 entry = fEventNumber;
128 fEventNumber = entry;
131 if (entry >= fNEvents) {
132 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvents));
135 return LoadEvent(entry);
138 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
140 // Load the event number iev
142 // Calculate the file number
143 Int_t inew = iev / fEventsPerFile;
144 if (inew != fFileNumber) {
146 if (!OpenFile(fFileNumber)){
152 sprintf(folder, "Event%d", iev);
158 while ((file = (TFile*) next()))
160 file->GetObject(folder, fDirR);
162 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
166 fDirR->GetObject("TreeR", tree);
167 fRTrees->AddAt(tree, idx++);
172 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
177 fExtension = Form("%d", i);
183 TIter next(fDetectors);
186 while ((det = (TNamed*) next()))
189 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
191 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
193 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
199 Bool_t AliESDInputHandlerRP::Notify(const char *path)
201 // Notify about directory change
202 // The directory is taken from the 'path' argument
204 AliInfo(Form("Directory change %s \n", path));
205 // Get path to directory
206 TString fileName(path);
208 if(fileName.Contains("#")){
209 // If this is an archive it will contain a #
211 } else if(fileName.Contains("AliESDs.root")){
212 fileName.ReplaceAll("AliESDs.root", "");
216 // At this point we have a path to the directory or to the archive anchor
217 *fPathName = fileName;
219 // Now filter the files containing RecPoints *.RecPoints.*
221 TSeqCollection* members;
226 TFile* file = TFile::Open(fPathName->Data());
227 TArchiveFile* arch = file->GetArchive();
228 members = arch->GetMembers();
230 // Directory or alien archive
231 if (fileName.BeginsWith("alien:")) {
232 TFile* file = TFile::Open(Form("%s/root_archive.zip", fPathName->Data()));
233 TArchiveFile* arch = file->GetArchive();
234 members = arch->GetMembers();
236 TString wd = gSystem->WorkingDirectory();
237 TSystemDirectory dir(".", fPathName->Data());
238 members = dir.GetListOfFiles();
246 fDetectors->Delete();
248 while ( (entry = (TFile*) next()) )
250 TString name(entry->GetName());
251 TObjArray* tokens = name.Tokenize(".");
252 Int_t ntok = tokens->GetEntries();
253 if (ntok <= 1) continue;
254 TString str = ((TObjString*) tokens->At(1))->GetString();
255 if (!(strcmp(str.Data(), "RecPoints"))){
256 TString det = ((TObjString*) tokens->At(0))->GetString();
257 printf("Found file with RecPoints for %s \n", det.Data());
258 TNamed* ent = new TNamed(det.Data(), det.Data());
259 fRTrees->AddAt(0, ien);
260 ent->SetUniqueID(ien++);
261 fDetectors->Add(ent);
263 if(tokens) delete tokens;
267 // Now we have the path and the list of detectors
269 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
279 Bool_t AliESDInputHandlerRP::FinishEvent()
281 // Clean-up after each event
282 delete fDirR; fDirR = 0;
283 AliESDInputHandler::FinishEvent();
287 void AliESDInputHandlerRP::ResetIO()
289 // Delete trees and files
290 fRFiles->Clear("nodelete");
294 TTree* AliESDInputHandlerRP::GetTreeR(const char* det)
296 // Return pointer to RecPoint tree for detector det
297 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
299 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
302 Int_t ien = entry->GetUniqueID();
303 return ((TTree*) (fRTrees->At(ien)));