]>
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; | |
92 | while (det = ((TNamed*) next())) | |
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 | } | |
99 | if (!file) AliFatal(Form("AliESDInputHandlerRP: TPC.RecPoints.root not found in %s ! \n", fPathName->Data())); | |
100 | fRFiles->Add(file); | |
101 | } | |
a847da94 | 102 | fEventsPerFile = file->GetNkeys() - file->GetNProcessIDs(); |
103 | // Reset the event number | |
104 | fEventNumber = -1; | |
105 | fFileNumber = 0; | |
80d90f25 | 106 | // Get number of events from esd tree |
a847da94 | 107 | fNEvent = fTree->GetEntries(); |
108 | ||
109 | printf("AliESDInputHandler::Init() %d\n",__LINE__); | |
110 | return kTRUE; | |
111 | } | |
112 | ||
113 | Bool_t AliESDInputHandlerRP::BeginEvent(Long64_t entry) | |
114 | { | |
115 | // Begin the next event | |
80d90f25 | 116 | // Delegate first to base class |
a847da94 | 117 | AliESDInputHandler::BeginEvent(entry); |
118 | // | |
119 | if (entry == -1) { | |
120 | fEventNumber++; | |
121 | entry = fEventNumber; | |
122 | } else { | |
123 | fEventNumber = entry; | |
124 | } | |
125 | ||
126 | if (entry >= fNEvent) { | |
127 | AliWarning(Form("AliESDInputHandlerRP: Event number out of range %5d %5d\n", entry, fNEvent)); | |
128 | return kFALSE; | |
129 | } | |
f207215d | 130 | return LoadEvent(entry); |
a847da94 | 131 | } |
132 | ||
f207215d | 133 | Bool_t AliESDInputHandlerRP::LoadEvent(Int_t iev) |
a847da94 | 134 | { |
135 | // Load the event number iev | |
136 | // | |
137 | // Calculate the file number | |
138 | Int_t inew = iev / fEventsPerFile; | |
139 | if (inew != fFileNumber) { | |
140 | fFileNumber = inew; | |
141 | if (!OpenFile(fFileNumber)){ | |
142 | return kFALSE; | |
143 | } | |
144 | } | |
145 | // Folder name | |
146 | char folder[20]; | |
147 | sprintf(folder, "Event%d", iev); | |
148 | // Tree R | |
80d90f25 | 149 | TIter next(fRFiles); |
150 | TFile* file; | |
151 | while (file = ((TFile*) next())) | |
152 | { | |
153 | file->GetObject(folder, fDirR); | |
154 | if (!fDirR) { | |
155 | AliWarning(Form("AliESDInputHandlerRP: Event #%5d not found\n", iev)); | |
156 | return kFALSE; | |
157 | } | |
158 | TTree* tree; | |
159 | fDirR ->GetObject("TreeR", tree); | |
160 | fRTrees->Add(tree); | |
161 | tree->ls(); | |
a847da94 | 162 | } |
a847da94 | 163 | return kTRUE; |
164 | } | |
165 | ||
166 | Bool_t AliESDInputHandlerRP::OpenFile(Int_t i) | |
167 | { | |
168 | // Open file i | |
169 | Bool_t ok = kTRUE; | |
170 | if (i > 0) { | |
171 | fExtension = Form("%d", i); | |
172 | } else { | |
173 | fExtension = ""; | |
174 | } | |
175 | ||
176 | fRFiles->Delete(); | |
80d90f25 | 177 | TIter next(fDetectors); |
178 | TNamed* det; | |
a847da94 | 179 | TFile* file; |
80d90f25 | 180 | while (det = ((TNamed*) next())) |
181 | { | |
182 | if (!fIsArchive) { | |
183 | file = TFile::Open(Form("%s%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension)); | |
184 | } else { | |
185 | file = TFile::Open(Form("%s#%s.RecPoints%s.root", fPathName->Data(), det->GetName(), fExtension)); | |
186 | } | |
187 | if (!file) AliFatal(Form("AliESDInputHandlerRP: RecPoints.root not found in %s ! \n", fPathName->Data())); | |
188 | fRFiles->Add(file); | |
a847da94 | 189 | } |
190 | return ok; | |
191 | } | |
192 | ||
193 | Bool_t AliESDInputHandlerRP::Notify(const char *path) | |
194 | { | |
195 | // Notify about directory change | |
196 | // The directory is taken from the 'path' argument | |
80d90f25 | 197 | // |
198 | // Get path to directory | |
a847da94 | 199 | TString fileName(path); |
200 | if(fileName.Contains("AliESDs.root")){ | |
201 | fileName.ReplaceAll("AliESDs.root", ""); | |
202 | } | |
80d90f25 | 203 | // If this is an archive it will contain a # |
204 | if(fileName.Contains("#")){ | |
205 | fileName.ReplaceAll("#", ""); | |
206 | } | |
207 | // | |
208 | // At this point we have a path to the directory or to the archive | |
a847da94 | 209 | *fPathName = fileName; |
80d90f25 | 210 | // |
211 | // Now filter the files containing RecPoints *.RecPoints.* | |
212 | fIsArchive = kFALSE; | |
213 | if (fPathName->Contains(".zip")) fIsArchive = kTRUE; | |
a847da94 | 214 | |
80d90f25 | 215 | TSeqCollection* members; |
216 | ||
217 | if (fIsArchive) { | |
218 | // Archive | |
219 | TFile* file = TFile::Open(fPathName->Data()); | |
220 | TArchiveFile* arch = file->GetArchive(); | |
221 | members = arch->GetMembers(); | |
222 | } else { | |
223 | // Directory | |
224 | TSystemDirectory dir(".", fPathName->Data()); | |
225 | members = dir.GetListOfFiles(); | |
226 | } | |
227 | ||
228 | TIter next(members); | |
229 | TFile* entry; | |
ad61d1be | 230 | Int_t ien = 0; |
80d90f25 | 231 | while ( (entry = (TFile*) next()) ) |
232 | { | |
233 | printf("File %s \n", entry->GetName()); | |
234 | TString name(entry->GetName()); | |
235 | TObjArray* tokens = name.Tokenize("."); | |
236 | Int_t ntok = tokens->GetEntries(); | |
237 | if (ntok <= 1) continue; | |
238 | TString str = ((TObjString*) tokens->At(1))->GetString(); | |
239 | if (!(strcmp(str.Data(), "RecPoints"))){ | |
240 | TString det = ((TObjString*) tokens->At(0))->GetString(); | |
241 | printf("Name %s \n", det.Data()); | |
ad61d1be | 242 | TNamed* entry = new TNamed(det.Data(), det.Data()); |
243 | entry->SetUniqueID(ien++); | |
244 | fDetectors->Add(entry); | |
80d90f25 | 245 | } |
246 | } // loop over files | |
247 | ||
248 | ||
249 | // Now we have the path and the list of detectors | |
a847da94 | 250 | |
80d90f25 | 251 | printf("AliESDInputHandlerRP::Notify() Path: %s\n", fPathName->Data()); |
252 | // | |
a847da94 | 253 | ResetIO(); |
254 | InitIO(""); | |
80d90f25 | 255 | // Some clean-up |
256 | members->Delete(); | |
257 | // | |
a847da94 | 258 | return kTRUE; |
259 | } | |
260 | ||
261 | Bool_t AliESDInputHandlerRP::FinishEvent() | |
262 | { | |
263 | // Clean-up after each event | |
264 | delete fDirR; fDirR = 0; | |
265 | AliESDInputHandler::FinishEvent(); | |
266 | return kTRUE; | |
267 | } | |
268 | ||
269 | void AliESDInputHandlerRP::ResetIO() | |
270 | { | |
271 | // Delete trees and files | |
272 | fRTrees->Delete(); | |
273 | fRFiles->Delete(); | |
274 | fExtension=""; | |
275 | } | |
ad61d1be | 276 | |
277 | TTree* AliESDInputHandlerRP::GetTreeR(char* det) | |
278 | { | |
279 | // Return pointer to RecPoint tree for detector det | |
280 | TNamed* entry = (TNamed*) (fDetectors->FindObject(det)); | |
281 | if (!entry) { | |
282 | AliWarning(Form("AliESDInputHandlerRP: No RecPoints for detector %s available \n", det)); | |
283 | return 0; | |
284 | } else { | |
285 | Int_t ien = entry->GetUniqueID(); | |
286 | return ((TTree*) (fRTrees->At(ien))); | |
287 | } | |
288 | } |