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: TPC.RecPoints.root not found in %s ! \n", fPathName->Data()));
102 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
103 // Reset the event number
106 // Get number of events from esd tree
107 fNEvent = fTree->GetEntries();
109 printf("AliESDInputHandler::Init() %d\n",__LINE__);
113 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
115 // Begin the next event
116 // Delegate first to base class
117 AliESDInputHandler::BeginEvent(entry);
121 entry = fEventNumber;
123 fEventNumber = entry;
126 if (entry >= fNEvent) {
127 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvent));
130 return LoadEvent(entry);
133 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
135 // Load the event number iev
137 // Calculate the file number
138 Int_t inew = iev / fEventsPerFile;
139 if (inew != fFileNumber) {
141 if (!OpenFile(fFileNumber)){
147 sprintf(folder, "Event%d", iev);
151 while (file = ((TFile*) next()))
153 file->GetObject(folder, fDirR);
155 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
159 fDirR ->GetObject("TreeR", tree);
166 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
171 fExtension = Form("%d", i);
177 TIter next(fDetectors);
180 while (det = ((TNamed*) next()))
183 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
185 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
187 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
193 Bool_t AliESDInputHandlerRP::Notify(const char *path)
195 // Notify about directory change
196 // The directory is taken from the 'path' argument
198 // Get path to directory
199 TString fileName(path);
200 if(fileName.Contains("AliESDs.root")){
201 fileName.ReplaceAll("AliESDs.root", "");
203 // If this is an archive it will contain a #
204 if(fileName.Contains("#")){
205 fileName.ReplaceAll("#", "");
208 // At this point we have a path to the directory or to the archive
209 *fPathName = fileName;
211 // Now filter the files containing RecPoints *.RecPoints.*
213 if (fPathName->Contains(".zip")) fIsArchive = kTRUE;
215 TSeqCollection* members;
219 TFile* file = TFile::Open(fPathName->Data());
220 TArchiveFile* arch = file->GetArchive();
221 members = arch->GetMembers();
224 TSystemDirectory dir(".", fPathName->Data());
225 members = dir.GetListOfFiles();
231 while ( (entry = (TFile*) next()) )
233 printf("File %s \n", entry->GetName());
234 TString name(entry->GetName());
235 TObjArray* tokens = name.Tokenize(".");
236 Int_t ntok = tokens->GetEntries();
237 if (ntok <= 1) continue;
238 TString str = ((TObjString*) tokens->At(1))->GetString();
239 if (!(strcmp(str.Data(), "RecPoints"))){
240 TString det = ((TObjString*) tokens->At(0))->GetString();
241 printf("Name %s \n", det.Data());
242 TNamed* entry = new TNamed(det.Data(), det.Data());
243 entry->SetUniqueID(ien++);
244 fDetectors->Add(entry);
249 // Now we have the path and the list of detectors
251 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
261 Bool_t AliESDInputHandlerRP::FinishEvent()
263 // Clean-up after each event
264 delete fDirR; fDirR = 0;
265 AliESDInputHandler::FinishEvent();
269 void AliESDInputHandlerRP::ResetIO()
271 // Delete trees and files
277 TTree* AliESDInputHandlerRP::GetTreeR(char* det)
279 // Return pointer to RecPoint tree for detector det
280 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
282 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
285 Int_t ien = entry->GetUniqueID();
286 return ((TTree*) (fRTrees->At(ien)));