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()),
50 fPathName(new TString("./")),
53 // Default constructor
57 //______________________________________________________________________________
58 AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
59 AliESDInputHandler(name, title),
60 fRTrees( new TList()),
61 fRFiles( new TList()),
62 fDetectors(new TList()),
68 fPathName(new TString("./")),
74 //______________________________________________________________________________
75 AliESDInputHandlerRP::~AliESDInputHandlerRP()
80 Bool_t AliESDInputHandlerRP::Init(Option_t* opt)
85 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
87 TIter next(fDetectors);
90 while ((det = (TNamed*) next()))
93 file = TFile::Open(Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName()));
95 file = TFile::Open(Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName()));
97 if (!file) AliFatal(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
102 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
104 AliFatal(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
108 // Reset the event number
111 // Get number of events from esd tree
112 printf("AliESDInputHandler::Init() %d %d\n",__LINE__, fNEvents);
116 Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
118 // Begin the next event
119 // Delegate first to base class
120 AliESDInputHandler::BeginEvent(entry);
124 entry = fEventNumber;
126 fEventNumber = entry;
129 if (entry >= fNEvents) {
130 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvents));
133 return LoadEvent(entry);
136 Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
138 // Load the event number iev
140 // Calculate the file number
141 Int_t inew = iev / fEventsPerFile;
142 if (inew != fFileNumber) {
144 if (!OpenFile(fFileNumber)){
150 sprintf(folder, "Event%d", iev);
155 while ((file = (TFile*) next()))
157 file->GetObject(folder, fDirR);
159 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
163 fDirR ->GetObject("TreeR", tree);
164 fRTrees->AddAt(tree, idx++);
169 Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
174 fExtension = Form("%d", i);
180 TIter next(fDetectors);
183 while ((det = (TNamed*) next()))
186 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
188 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
190 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
196 Bool_t AliESDInputHandlerRP::Notify(const char *path)
198 // Notify about directory change
199 // The directory is taken from the 'path' argument
201 // Get path to directory
202 TString fileName(path);
203 if(fileName.Contains("AliESDs.root")){
204 fileName.ReplaceAll("AliESDs.root", "");
206 // If this is an archive it will contain a #
207 if(fileName.Contains("#")){
208 fileName.ReplaceAll("#", "");
211 // At this point we have a path to the directory or to the archive
212 *fPathName = fileName;
214 // Now filter the files containing RecPoints *.RecPoints.*
216 if (fPathName->Contains(".zip")) fIsArchive = kTRUE;
218 TSeqCollection* members;
222 TFile* file = TFile::Open(fPathName->Data());
223 TArchiveFile* arch = file->GetArchive();
224 members = arch->GetMembers();
227 TSystemDirectory dir(".", fPathName->Data());
228 members = dir.GetListOfFiles();
236 while ( (entry = (TFile*) next()) )
238 printf("File %s \n", entry->GetName());
239 TString name(entry->GetName());
240 TObjArray* tokens = name.Tokenize(".");
241 Int_t ntok = tokens->GetEntries();
242 if (ntok <= 1) continue;
243 TString str = ((TObjString*) tokens->At(1))->GetString();
244 if (!(strcmp(str.Data(), "RecPoints"))){
245 TString det = ((TObjString*) tokens->At(0))->GetString();
246 printf("Name %s \n", det.Data());
247 TNamed* ent = new TNamed(det.Data(), det.Data());
248 ent->SetUniqueID(ien++);
249 fDetectors->Add(ent);
254 // Now we have the path and the list of detectors
256 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
266 Bool_t AliESDInputHandlerRP::FinishEvent()
268 // Clean-up after each event
269 delete fDirR; fDirR = 0;
270 AliESDInputHandler::FinishEvent();
274 void AliESDInputHandlerRP::ResetIO()
276 // Delete trees and files
282 TTree* AliESDInputHandlerRP::GetTreeR(char* det)
284 // Return pointer to RecPoint tree for detector det
285 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
287 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
290 Int_t ien = entry->GetUniqueID();
291 return ((TTree*) (fRTrees->At(ien)));