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