]>
Commit | Line | Data |
---|---|---|
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> | |
30cd6a86 | 30 | #include <TObjArray.h> |
a847da94 | 31 | #include <TProcessID.h> |
32 | ||
33 | #include "AliESDInputHandlerRP.h" | |
34 | #include "AliESDEvent.h" | |
35 | #include "AliESD.h" | |
36 | #include "AliLog.h" | |
37 | ||
38 | ClassImp(AliESDInputHandlerRP) | |
39 | ||
40 | //______________________________________________________________________________ | |
41 | AliESDInputHandlerRP::AliESDInputHandlerRP() : | |
42 | AliESDInputHandler(), | |
30cd6a86 | 43 | fRTrees( new TObjArray()), |
ad61d1be | 44 | fRFiles( new TList()), |
80d90f25 | 45 | fDetectors(new TList()), |
a847da94 | 46 | fDirR(0), |
47 | fEventNumber(-1), | |
a847da94 | 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 | //______________________________________________________________________________ | |
59 | AliESDInputHandlerRP::AliESDInputHandlerRP(const char* name, const char* title): | |
60 | AliESDInputHandler(name, title), | |
30cd6a86 | 61 | fRTrees( new TObjArray()), |
ad61d1be | 62 | fRFiles( new TList()), |
80d90f25 | 63 | fDetectors(new TList()), |
a847da94 | 64 | fDirR(0), |
65 | fEventNumber(-1), | |
a847da94 | 66 | fFileNumber(0), |
67 | fEventsPerFile(0), | |
68 | fExtension(""), | |
80d90f25 | 69 | fPathName(new TString("./")), |
70 | fIsArchive(kFALSE) | |
a847da94 | 71 | { |
72 | // Constructor | |
73 | } | |
74 | ||
80d90f25 | 75 | //______________________________________________________________________________ |
76 | AliESDInputHandlerRP::~AliESDInputHandlerRP() | |
77 | { | |
78 | // Destructor | |
79 | } | |
80 | ||
a847da94 | 81 | Bool_t AliESDInputHandlerRP::Init(Option_t* opt) |
82 | { | |
83 | // | |
84 | // Initialize input | |
85 | // | |
86 | if (!(strcmp(opt, "proof")) || !(strcmp(opt, "local"))) return kTRUE; | |
87 | // | |
80d90f25 | 88 | TIter next(fDetectors); |
89 | TNamed* det; | |
90 | TFile* file = 0; | |
8ac4fa64 | 91 | while ((det = (TNamed*) next())) |
80d90f25 | 92 | { |
93 | if (!fIsArchive) { | |
94 | file = TFile::Open(Form("%s%s.RecPoints.root", fPathName->Data(), det->GetName())); | |
95 | } else { | |
96 | file = TFile::Open(Form("%s#%s.RecPoints.root", fPathName->Data(), det->GetName())); | |
97 | } | |
6e2a8152 | 98 | if (!file) AliFatal(Form("AliESDInputHandlerRP: %s.RecPoints.root not found in %s ! \n", det->GetName(), fPathName->Data())); |
80d90f25 | 99 | fRFiles->Add(file); |
100 | } | |
4d2a7370 | 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 | ||
4d2a7370 | 108 | |
a847da94 | 109 | // Reset the event number |
110 | fEventNumber = -1; | |
111 | fFileNumber = 0; | |
80d90f25 | 112 | // Get number of events from esd tree |
4d2a7370 | 113 | printf("AliESDInputHandler::Init() %d %d\n",__LINE__, fNEvents); |
a847da94 | 114 | return kTRUE; |
115 | } | |
116 | ||
117 | Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry) | |
118 | { | |
119 | // Begin the next event | |
80d90f25 | 120 | // Delegate first to base class |
a847da94 | 121 | AliESDInputHandler::BeginEvent(entry); |
122 | // | |
123 | if (entry == -1) { | |
124 | fEventNumber++; | |
125 | entry = fEventNumber; | |
126 | } else { | |
127 | fEventNumber = entry; | |
128 | } | |
129 | ||
4d2a7370 | 130 | if (entry >= fNEvents) { |
131 | AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvents)); | |
a847da94 | 132 | return kFALSE; |
133 | } | |
f207215d | 134 | return LoadEvent(entry); |
a847da94 | 135 | } |
136 | ||
f207215d | 137 | Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev) |
a847da94 | 138 | { |
139 | // Load the event number iev | |
140 | // | |
141 | // Calculate the file number | |
142 | Int_t inew = iev / fEventsPerFile; | |
143 | if (inew != fFileNumber) { | |
144 | fFileNumber = inew; | |
145 | if (!OpenFile(fFileNumber)){ | |
146 | return kFALSE; | |
147 | } | |
148 | } | |
149 | // Folder name | |
150 | char folder[20]; | |
151 | sprintf(folder, "Event%d", iev); | |
152 | // Tree R | |
80d90f25 | 153 | TIter next(fRFiles); |
154 | TFile* file; | |
4d2a7370 | 155 | Int_t idx = 0; |
30cd6a86 | 156 | |
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 | } | |
4d2a7370 | 164 | TTree* tree = 0; |
30cd6a86 | 165 | fDirR->GetObject("TreeR", tree); |
4d2a7370 | 166 | fRTrees->AddAt(tree, idx++); |
a847da94 | 167 | } |
a847da94 | 168 | return kTRUE; |
169 | } | |
170 | ||
171 | Bool_t AliESDInputHandlerRP::OpenFile(Int_t i) | |
172 | { | |
173 | // Open file i | |
174 | Bool_t ok = kTRUE; | |
175 | if (i > 0) { | |
176 | fExtension = Form("%d", i); | |
177 | } else { | |
178 | fExtension = ""; | |
179 | } | |
180 | ||
181 | fRFiles->Delete(); | |
80d90f25 | 182 | TIter next(fDetectors); |
183 | TNamed* det; | |
a847da94 | 184 | TFile* file; |
8ac4fa64 | 185 | while ((det = (TNamed*) next())) |
80d90f25 | 186 | { |
187 | if (!fIsArchive) { | |
188 | file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension)); | |
189 | } else { | |
190 | file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension)); | |
191 | } | |
192 | if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data())); | |
193 | fRFiles->Add(file); | |
a847da94 | 194 | } |
195 | return ok; | |
196 | } | |
197 | ||
198 | Bool_t AliESDInputHandlerRP::Notify(const char *path) | |
199 | { | |
200 | // Notify about directory change | |
201 | // The directory is taken from the 'path' argument | |
80d90f25 | 202 | // |
203 | // Get path to directory | |
a847da94 | 204 | TString fileName(path); |
205 | if(fileName.Contains("AliESDs.root")){ | |
206 | fileName.ReplaceAll("AliESDs.root", ""); | |
207 | } | |
80d90f25 | 208 | // If this is an archive it will contain a # |
209 | if(fileName.Contains("#")){ | |
210 | fileName.ReplaceAll("#", ""); | |
211 | } | |
212 | // | |
213 | // At this point we have a path to the directory or to the archive | |
a847da94 | 214 | *fPathName = fileName; |
80d90f25 | 215 | // |
216 | // Now filter the files containing RecPoints *.RecPoints.* | |
217 | fIsArchive = kFALSE; | |
218 | if (fPathName->Contains(".zip")) fIsArchive = kTRUE; | |
a847da94 | 219 | |
80d90f25 | 220 | TSeqCollection* members; |
30cd6a86 | 221 | |
80d90f25 | 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 | } | |
30cd6a86 | 233 | |
80d90f25 | 234 | TIter next(members); |
235 | TFile* entry; | |
ad61d1be | 236 | Int_t ien = 0; |
30cd6a86 | 237 | fDetectors->Delete(); |
4d2a7370 | 238 | |
80d90f25 | 239 | while ( (entry = (TFile*) next()) ) |
240 | { | |
80d90f25 | 241 | TString name(entry->GetName()); |
242 | TObjArray* tokens = name.Tokenize("."); | |
243 | Int_t ntok = tokens->GetEntries(); | |
244 | if (ntok <= 1) continue; | |
245 | TString str = ((TObjString*) tokens->At(1))->GetString(); | |
246 | if (!(strcmp(str.Data(), "RecPoints"))){ | |
247 | TString det = ((TObjString*) tokens->At(0))->GetString(); | |
30cd6a86 | 248 | printf("Found file with RecPoints for %s \n", det.Data()); |
8ac4fa64 | 249 | TNamed* ent = new TNamed(det.Data(), det.Data()); |
30cd6a86 | 250 | fRTrees->AddAt(0, ien); |
8ac4fa64 | 251 | ent->SetUniqueID(ien++); |
252 | fDetectors->Add(ent); | |
80d90f25 | 253 | } |
254 | } // loop over files | |
4d2a7370 | 255 | |
80d90f25 | 256 | |
257 | // Now we have the path and the list of detectors | |
a847da94 | 258 | |
80d90f25 | 259 | printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data()); |
260 | // | |
a847da94 | 261 | ResetIO(); |
262 | InitIO(""); | |
80d90f25 | 263 | // Some clean-up |
264 | members->Delete(); | |
4d2a7370 | 265 | |
a847da94 | 266 | return kTRUE; |
267 | } | |
268 | ||
269 | Bool_t AliESDInputHandlerRP::FinishEvent() | |
270 | { | |
271 | // Clean-up after each event | |
272 | delete fDirR; fDirR = 0; | |
273 | AliESDInputHandler::FinishEvent(); | |
274 | return kTRUE; | |
275 | } | |
276 | ||
277 | void AliESDInputHandlerRP::ResetIO() | |
278 | { | |
279 | // Delete trees and files | |
30cd6a86 | 280 | fRFiles->Delete(); |
a847da94 | 281 | fExtension=""; |
282 | } | |
ad61d1be | 283 | |
284 | TTree* AliESDInputHandlerRP::GetTreeR(char* det) | |
285 | { | |
286 | // Return pointer to RecPoint tree for detector det | |
287 | TNamed* entry = (TNamed*) (fDetectors->FindObject(det)); | |
288 | if (!entry) { | |
289 | AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det)); | |
290 | return 0; | |
291 | } else { | |
292 | Int_t ien = entry->GetUniqueID(); | |
293 | return ((TTree*) (fRTrees->At(ien))); | |
294 | } | |
295 | } |