]>
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> | |
30 | #include <TProcessID.h> | |
31 | ||
32 | #include "AliESDInputHandlerRP.h" | |
33 | #include "AliESDEvent.h" | |
34 | #include "AliESD.h" | |
35 | #include "AliLog.h" | |
36 | ||
37 | ClassImp(AliESDInputHandlerRP) | |
38 | ||
39 | //______________________________________________________________________________ | |
40 | AliESDInputHandlerRP::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 | //______________________________________________________________________________ | |
59 | AliESDInputHandlerRP::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 | //______________________________________________________________________________ |
77 | AliESDInputHandlerRP::~AliESDInputHandlerRP() | |
78 | { | |
79 | // Destructor | |
80 | } | |
81 | ||
a847da94 | 82 | Bool_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 | ||
119 | Bool_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 | 139 | Bool_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 | |
0829b2ed | 155 | fRTrees->Clear(); |
156 | ||
80d90f25 | 157 | TIter next(fRFiles); |
158 | TFile* file; | |
8ac4fa64 | 159 | while ((file = (TFile*) next())) |
80d90f25 | 160 | { |
161 | file->GetObject(folder, fDirR); | |
162 | if (!fDirR) { | |
163 | AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev)); | |
164 | return kFALSE; | |
165 | } | |
166 | TTree* tree; | |
167 | fDirR ->GetObject("TreeR", tree); | |
168 | fRTrees->Add(tree); | |
a847da94 | 169 | } |
a847da94 | 170 | return kTRUE; |
171 | } | |
172 | ||
173 | Bool_t AliESDInputHandlerRP::OpenFile(Int_t i) | |
174 | { | |
175 | // Open file i | |
176 | Bool_t ok = kTRUE; | |
177 | if (i > 0) { | |
178 | fExtension = Form("%d", i); | |
179 | } else { | |
180 | fExtension = ""; | |
181 | } | |
182 | ||
183 | fRFiles->Delete(); | |
80d90f25 | 184 | TIter next(fDetectors); |
185 | TNamed* det; | |
a847da94 | 186 | TFile* file; |
8ac4fa64 | 187 | while ((det = (TNamed*) next())) |
80d90f25 | 188 | { |
189 | if (!fIsArchive) { | |
190 | file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension)); | |
191 | } else { | |
192 | file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension)); | |
193 | } | |
194 | if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data())); | |
195 | fRFiles->Add(file); | |
a847da94 | 196 | } |
197 | return ok; | |
198 | } | |
199 | ||
200 | Bool_t AliESDInputHandlerRP::Notify(const char *path) | |
201 | { | |
202 | // Notify about directory change | |
203 | // The directory is taken from the 'path' argument | |
80d90f25 | 204 | // |
205 | // Get path to directory | |
a847da94 | 206 | TString fileName(path); |
207 | if(fileName.Contains("AliESDs.root")){ | |
208 | fileName.ReplaceAll("AliESDs.root", ""); | |
209 | } | |
80d90f25 | 210 | // If this is an archive it will contain a # |
211 | if(fileName.Contains("#")){ | |
212 | fileName.ReplaceAll("#", ""); | |
213 | } | |
214 | // | |
215 | // At this point we have a path to the directory or to the archive | |
a847da94 | 216 | *fPathName = fileName; |
80d90f25 | 217 | // |
218 | // Now filter the files containing RecPoints *.RecPoints.* | |
219 | fIsArchive = kFALSE; | |
220 | if (fPathName->Contains(".zip")) fIsArchive = kTRUE; | |
a847da94 | 221 | |
80d90f25 | 222 | TSeqCollection* members; |
223 | ||
224 | if (fIsArchive) { | |
225 | // Archive | |
226 | TFile* file = TFile::Open(fPathName->Data()); | |
227 | TArchiveFile* arch = file->GetArchive(); | |
228 | members = arch->GetMembers(); | |
229 | } else { | |
230 | // Directory | |
231 | TSystemDirectory dir(".", fPathName->Data()); | |
232 | members = dir.GetListOfFiles(); | |
233 | } | |
234 | ||
235 | TIter next(members); | |
236 | TFile* entry; | |
ad61d1be | 237 | Int_t ien = 0; |
80d90f25 | 238 | while ( (entry = (TFile*) next()) ) |
239 | { | |
240 | printf("File %s \n", entry->GetName()); | |
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(); | |
248 | printf("Name %s \n", det.Data()); | |
8ac4fa64 | 249 | TNamed* ent = new TNamed(det.Data(), det.Data()); |
250 | ent->SetUniqueID(ien++); | |
251 | fDetectors->Add(ent); | |
80d90f25 | 252 | } |
253 | } // loop over files | |
254 | ||
255 | ||
256 | // Now we have the path and the list of detectors | |
a847da94 | 257 | |
80d90f25 | 258 | printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data()); |
259 | // | |
a847da94 | 260 | ResetIO(); |
261 | InitIO(""); | |
80d90f25 | 262 | // Some clean-up |
263 | members->Delete(); | |
264 | // | |
a847da94 | 265 | return kTRUE; |
266 | } | |
267 | ||
268 | Bool_t AliESDInputHandlerRP::FinishEvent() | |
269 | { | |
270 | // Clean-up after each event | |
271 | delete fDirR; fDirR = 0; | |
272 | AliESDInputHandler::FinishEvent(); | |
273 | return kTRUE; | |
274 | } | |
275 | ||
276 | void AliESDInputHandlerRP::ResetIO() | |
277 | { | |
278 | // Delete trees and files | |
279 | fRTrees->Delete(); | |
280 | fRFiles->Delete(); | |
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 | } |