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);
157 while ((file = (TFile*) next()))
159 file->GetObject(folder, fDirR);
161 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
165 fDirR ->GetObject("TreeR", tree);
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 // Get path to directory
205 TString fileName(path);
206 if(fileName.Contains("AliESDs.root")){
207 fileName.ReplaceAll("AliESDs.root", "");
209 // If this is an archive it will contain a #
210 if(fileName.Contains("#")){
211 fileName.ReplaceAll("#", "");
214 // At this point we have a path to the directory or to the archive
215 *fPathName = fileName;
217 // Now filter the files containing RecPoints *.RecPoints.*
219 if (fPathName->Contains(".zip")) fIsArchive = kTRUE;
221 TSeqCollection* members;
225 TFile* file = TFile::Open(fPathName->Data());
226 TArchiveFile* arch = file->GetArchive();
227 members = arch->GetMembers();
230 TSystemDirectory dir(".", fPathName->Data());
231 members = dir.GetListOfFiles();
237 while ( (entry = (TFile*) next()) )
239 printf("File %s \n", entry->GetName());
240 TString name(entry->GetName());
241 TObjArray* tokens = name.Tokenize(".");
242 Int_t ntok = tokens->GetEntries();
243 if (ntok <= 1) continue;
244 TString str = ((TObjString*) tokens->At(1))->GetString();
245 if (!(strcmp(str.Data(), "RecPoints"))){
246 TString det = ((TObjString*) tokens->At(0))->GetString();
247 printf("Name %s \n", det.Data());
248 TNamed* ent = new TNamed(det.Data(), det.Data());
249 ent->SetUniqueID(ien++);
250 fDetectors->Add(ent);
255 // Now we have the path and the list of detectors
257 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
267 Bool_t AliESDInputHandlerRP::FinishEvent()
269 // Clean-up after each event
270 delete fDirR; fDirR = 0;
271 AliESDInputHandler::FinishEvent();
275 void AliESDInputHandlerRP::ResetIO()
277 // Delete trees and files
283 TTree* AliESDInputHandlerRP::GetTreeR(char* det)
285 // Return pointer to RecPoint tree for detector det
286 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
288 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
291 Int_t ien = entry->GetUniqueID();
292 return ((TTree*) (fRTrees->At(ien)));