]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliESDInputHandlerRP.cxx
Removing osolete variable. Adding title to trigger configuration obj also
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandlerRP.cxx
CommitLineData
a847da94 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
80d90f25 16/* $Id$ */
a847da94 17
18//-------------------------------------------------------------------------
19// Event handler for ESD input reading the RecPoint Trees in parallel
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
23#include <TTree.h>
24#include <TList.h>
25#include <TFile.h>
80d90f25 26#include <TArchiveFile.h>
27#include <TSystemDirectory.h>
a847da94 28#include <TString.h>
29#include <TObjString.h>
30#include <TProcessID.h>
31
32#include "AliESDInputHandlerRP.h"
33#include "AliESDEvent.h"
34#include "AliESD.h"
35#include "AliLog.h"
36
37ClassImp(AliESDInputHandlerRP)
38
39//______________________________________________________________________________
40AliESDInputHandlerRP::AliESDInputHandlerRP() :
41 AliESDInputHandler(),
ad61d1be 42 fRTrees( new TList()),
43 fRFiles( new TList()),
80d90f25 44 fDetectors(new TList()),
a847da94 45 fDirR(0),
46 fEventNumber(-1),
47 fNEvent(-1),
48 fFileNumber(0),
49 fEventsPerFile(0),
50 fExtension(""),
80d90f25 51 fPathName(new TString("./")),
52 fIsArchive(kFALSE)
a847da94 53{
80d90f25 54 // Default constructor
a847da94 55}
56
a847da94 57
58//______________________________________________________________________________
59AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title):
60 AliESDInputHandler(name, title),
ad61d1be 61 fRTrees( new TList()),
62 fRFiles( new TList()),
80d90f25 63 fDetectors(new TList()),
a847da94 64 fDirR(0),
65 fEventNumber(-1),
66 fNEvent(-1),
67 fFileNumber(0),
68 fEventsPerFile(0),
69 fExtension(""),
80d90f25 70 fPathName(new TString("./")),
71 fIsArchive(kFALSE)
a847da94 72{
73 // Constructor
74}
75
80d90f25 76//______________________________________________________________________________
77AliESDInputHandlerRP::~AliESDInputHandlerRP()
78{
79 // Destructor
80}
81
a847da94 82Bool_t AliESDInputHandlerRP::Init(Option_t* opt)
83{
84 //
85 // Initialize input
86 //
87 if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE;
88 //
80d90f25 89 TIter next(fDetectors);
90 TNamed* det;
91 TFile* file = 0;
8ac4fa64 92 while ((det = (TNamed*) next()))
80d90f25 93 {
94 if (!fIsArchive) {
95 file = TFile::Open(Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName()));
96 } else {
97 file = TFile::Open(Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName()));
98 }
6e2a8152 99 if (!file) AliFatal(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data()));
80d90f25 100 fRFiles->Add(file);
101 }
6e2a8152 102 if (file) {
103 fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs();
104 } else {
105 AliFatal(Form("AliESDInputHandlerRP: No file with RecPoints found in %s ! \n", fPathName->Data()));
106 }
107
108
a847da94 109 // Reset the event number
110 fEventNumber = -1;
111 fFileNumber = 0;
80d90f25 112 // Get number of events from esd tree
a847da94 113 fNEvent = fTree->GetEntries();
114
115 printf("AliESDInputHandler::Init() %d\n",__LINE__);
116 return kTRUE;
117}
118
119Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry)
120{
121 // Begin the next event
80d90f25 122 // Delegate first to base class
a847da94 123 AliESDInputHandler::BeginEvent(entry);
124//
125 if (entry == -1) {
126 fEventNumber++;
127 entry = fEventNumber;
128 } else {
129 fEventNumber = entry;
130 }
131
132 if (entry >= fNEvent) {
133 AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvent));
134 return kFALSE;
135 }
f207215d 136 return LoadEvent(entry);
a847da94 137}
138
f207215d 139Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev)
a847da94 140{
141 // Load the event number iev
142 //
143 // Calculate the file number
144 Int_t inew = iev / fEventsPerFile;
145 if (inew != fFileNumber) {
146 fFileNumber = inew;
147 if (!OpenFile(fFileNumber)){
148 return kFALSE;
149 }
150 }
151 // Folder name
152 char folder[20];
153 sprintf(folder, "Event%d", iev);
154 // Tree R
80d90f25 155 TIter next(fRFiles);
156 TFile* file;
8ac4fa64 157 while ((file = (TFile*) next()))
80d90f25 158 {
159 file->GetObject(folder, fDirR);
160 if (!fDirR) {
161 AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev));
162 return kFALSE;
163 }
164 TTree* tree;
165 fDirR ->GetObject("TreeR", tree);
166 fRTrees->Add(tree);
167 tree->ls();
a847da94 168 }
a847da94 169 return kTRUE;
170}
171
172Bool_t AliESDInputHandlerRP::OpenFile(Int_t i)
173{
174 // Open file i
175 Bool_t ok = kTRUE;
176 if (i > 0) {
177 fExtension = Form("%d", i);
178 } else {
179 fExtension = "";
180 }
181
182 fRFiles->Delete();
80d90f25 183 TIter next(fDetectors);
184 TNamed* det;
a847da94 185 TFile* file;
8ac4fa64 186 while ((det = (TNamed*) next()))
80d90f25 187 {
188 if (!fIsArchive) {
189 file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
190 } else {
191 file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension));
192 }
193 if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data()));
194 fRFiles->Add(file);
a847da94 195 }
196 return ok;
197}
198
199Bool_t AliESDInputHandlerRP::Notify(const char *path)
200{
201 // Notify about directory change
202 // The directory is taken from the 'path' argument
80d90f25 203 //
204 // Get path to directory
a847da94 205 TString fileName(path);
206 if(fileName.Contains("AliESDs.root")){
207 fileName.ReplaceAll("AliESDs.root", "");
208 }
80d90f25 209 // If this is an archive it will contain a #
210 if(fileName.Contains("#")){
211 fileName.ReplaceAll("#", "");
212 }
213 //
214 // At this point we have a path to the directory or to the archive
a847da94 215 *fPathName = fileName;
80d90f25 216 //
217 // Now filter the files containing RecPoints *.RecPoints.*
218 fIsArchive = kFALSE;
219 if (fPathName->Contains(".zip")) fIsArchive = kTRUE;
a847da94 220
80d90f25 221 TSeqCollection* members;
222
223 if (fIsArchive) {
224 // Archive
225 TFile* file = TFile::Open(fPathName->Data());
226 TArchiveFile* arch = file->GetArchive();
227 members = arch->GetMembers();
228 } else {
229 // Directory
230 TSystemDirectory dir(".", fPathName->Data());
231 members = dir.GetListOfFiles();
232 }
233
234 TIter next(members);
235 TFile* entry;
ad61d1be 236 Int_t ien = 0;
80d90f25 237 while ( (entry = (TFile*) next()) )
238 {
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());
8ac4fa64 248 TNamed* ent = new TNamed(det.Data(), det.Data());
249 ent->SetUniqueID(ien++);
250 fDetectors->Add(ent);
80d90f25 251 }
252 } // loop over files
253
254
255 // Now we have the path and the list of detectors
a847da94 256
80d90f25 257 printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data());
258 //
a847da94 259 ResetIO();
260 InitIO("");
80d90f25 261 // Some clean-up
262 members->Delete();
263 //
a847da94 264 return kTRUE;
265}
266
267Bool_t AliESDInputHandlerRP::FinishEvent()
268{
269 // Clean-up after each event
270 delete fDirR; fDirR = 0;
271 AliESDInputHandler::FinishEvent();
272 return kTRUE;
273}
274
275void AliESDInputHandlerRP::ResetIO()
276{
277// Delete trees and files
278 fRTrees->Delete();
279 fRFiles->Delete();
280 fExtension="";
281}
ad61d1be 282
283TTree* AliESDInputHandlerRP::GetTreeR(char* det)
284{
285// Return pointer to RecPoint tree for detector det
286 TNamed* entry = (TNamed*) (fDetectors->FindObject(det));
287 if (!entry) {
288 AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det));
289 return 0;
290 } else {
291 Int_t ien = entry->GetUniqueID();
292 return ((TTree*) (fRTrees->At(ien)));
293 }
294}