]>
Commit | Line | Data |
---|---|---|
923f55ee | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, 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 | **************************************************************************/ | |
923f55ee | 15 | //////////////////////////////////////////////////////////////////////////// |
16 | // | |
21535372 | 17 | // support classes for the QA histogram viewer |
18 | // | |
923f55ee | 19 | // origin: Mikolaj Krzewicki, Nikhef, Mikolaj.Krzewicki@cern.ch |
20 | // | |
21 | /////////////////////////////////////////////////////////////////////////// | |
22 | ||
21535372 | 23 | #include <list> |
24 | #include <string> | |
25 | #include <Riostream.h> | |
26 | #include <TSystem.h> | |
27 | #include <TH1.h> | |
28 | #include <TList.h> | |
29 | #include <TNamed.h> | |
30 | #include <TObjString.h> | |
31 | #include <TString.h> | |
32 | #include <TFile.h> | |
33 | #include <TPRegexp.h> | |
34 | #include <TKey.h> | |
923f55ee | 35 | #include "AliQAHistNavigator.h" |
36 | ||
c82bb898 | 37 | using std::endl; |
38 | using std::cout; | |
39 | using std::string; | |
923f55ee | 40 | ClassImp(AliQAHistNavigator) |
41 | ||
42 | //_________________________________________________________________________ | |
d3a269ff | 43 | AliQAHistNavigator::AliQAHistNavigator(Int_t run): |
923f55ee | 44 | fPFile( NULL ), |
d3a269ff | 45 | fPCORRFile( NULL ), |
46 | fPQAResultFile( NULL ), | |
923f55ee | 47 | fRun( run ), |
923f55ee | 48 | fPCurrFile( NULL ), |
49 | fPCurrDetector( NULL ), | |
50 | fPCurrLevel( NULL ), | |
d3a269ff | 51 | fPCurrItem( NULL ), |
52 | fPListOfFiles( new AliQADirList() ), | |
923f55ee | 53 | fLoopAllFiles(kTRUE), |
54 | fLoopAllDetectors(kTRUE), | |
7b852582 | 55 | fLoopAllLevels(kTRUE), |
d3a269ff | 56 | fInitOK(kFALSE), |
57 | fExpertMode(kFALSE), | |
58 | fExpertDirName("Expert"), | |
59 | fPEmptyList(new TList()) | |
923f55ee | 60 | { |
21535372 | 61 | //ctor |
d3a269ff | 62 | fPEmptyList->AddLast(new AliQADirListItem("")); |
7b852582 | 63 | ReReadFiles(); |
923f55ee | 64 | } |
65 | ||
66 | //_________________________________________________________________________ | |
d3a269ff | 67 | AliQAHistNavigator::~AliQAHistNavigator() |
923f55ee | 68 | { |
21535372 | 69 | //dtor |
923f55ee | 70 | } |
71 | ||
72 | //_________________________________________________________________________ | |
73 | Bool_t AliQAHistNavigator::GetHistogram(TH1*& hist) | |
74 | { | |
21535372 | 75 | //get histogram from file |
7b852582 | 76 | TString file = GetFileName(); |
77 | TString dir = GetDirName(); | |
d3a269ff | 78 | TString histname = GetItemName(); |
79 | cout<<"GetHistogram: "<<file<<":"<<dir<<"/"<<histname<<endl; | |
7b852582 | 80 | if (file==""||dir==""||histname=="") |
81 | { | |
d3a269ff | 82 | printf("GetItem: nothing to fetch...\n"); |
7b852582 | 83 | return kFALSE; |
84 | } | |
d3a269ff | 85 | if (!OpenCurrentDirectory()) return kFALSE; |
86 | hist = dynamic_cast<TH1*>( gDirectory->FindKey(histname)->ReadObj() ); | |
923f55ee | 87 | if (!hist) |
88 | { | |
d3a269ff | 89 | printf("GetItem: null pointer returned by gDirectory\n"); |
923f55ee | 90 | return kFALSE; |
91 | } | |
92 | return kTRUE; | |
93 | } | |
94 | ||
923f55ee | 95 | //_________________________________________________________________________ |
96 | Bool_t AliQAHistNavigator::Next() | |
97 | { | |
21535372 | 98 | //move to the next histogram |
d3a269ff | 99 | if (!fPCurrFile||!fPCurrDetector||!fPCurrLevel) return kFALSE; |
100 | if (!(fPCurrItem=(AliQADirListItem*)GetItemList()->After(fPCurrItem))) | |
923f55ee | 101 | { |
d3a269ff | 102 | if (!(fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->After(fPCurrLevel))) |
923f55ee | 103 | { |
d3a269ff | 104 | if (!(fPCurrDetector=(AliQADirList*)fPCurrFile->GetDirs()->After(fPCurrDetector))) |
923f55ee | 105 | { |
d3a269ff | 106 | if (!(fPCurrFile=(AliQADirList*)fPListOfFiles->GetDirs()->After(fPCurrFile))) |
923f55ee | 107 | { |
108 | //we're at the end of everything | |
109 | if (fLoopAllFiles) | |
110 | { | |
111 | //rewind to the beginning | |
d3a269ff | 112 | fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First(); |
113 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); | |
114 | fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First(); | |
115 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 116 | OpenCurrentFile(); |
117 | OpenCurrentDirectory(); | |
118 | printf("----------------back at the beginning!\n"); | |
119 | } else return kFALSE; //no rewind, we finish | |
120 | } else //if there is a next file | |
121 | { | |
d3a269ff | 122 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
123 | fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->First(); | |
124 | fPCurrItem=(AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 125 | OpenCurrentFile(); |
126 | OpenCurrentDirectory(); | |
127 | } | |
128 | } else //if there is a next detector | |
129 | { | |
d3a269ff | 130 | fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->First(); |
131 | fPCurrItem=(AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 132 | OpenCurrentDirectory(); |
133 | } | |
134 | } else //if there is a next level | |
135 | { | |
d3a269ff | 136 | fPCurrItem=(AliQADirListItem*)GetItemList()->First(); |
923f55ee | 137 | OpenCurrentDirectory(); |
923f55ee | 138 | } |
139 | } else //if there is a next histgram | |
140 | { | |
923f55ee | 141 | } |
142 | return kTRUE; | |
143 | } | |
144 | ||
145 | //_________________________________________________________________________ | |
146 | Bool_t AliQAHistNavigator::Prev() | |
147 | { | |
21535372 | 148 | //move to the previous histrogram |
d3a269ff | 149 | if (!fPCurrLevel||!fPCurrDetector||!fPCurrFile) return kFALSE; |
150 | if (!(fPCurrItem=(AliQADirListItem*)GetItemList()->Before(fPCurrItem))) | |
923f55ee | 151 | { |
d3a269ff | 152 | if (!(fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Before(fPCurrLevel))) |
923f55ee | 153 | { |
d3a269ff | 154 | if (!(fPCurrDetector=(AliQADirList*)fPCurrFile->GetDirs()->Before(fPCurrDetector))) |
923f55ee | 155 | { |
d3a269ff | 156 | if (!(fPCurrFile=(AliQADirList*)fPListOfFiles->GetDirs()->Before(fPCurrFile))) |
923f55ee | 157 | { |
158 | //we're at the end of everything | |
159 | if (fLoopAllFiles) | |
160 | { | |
161 | //rewind to the beginning | |
d3a269ff | 162 | fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->Last(); |
163 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->Last(); | |
164 | fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->Last(); | |
165 | fPCurrItem = (AliQADirListItem*)GetItemList()->Last(); | |
923f55ee | 166 | OpenCurrentFile(); |
167 | OpenCurrentDirectory(); | |
168 | printf("----------------back at the end!\n"); | |
169 | } else return kFALSE; //no rewind, we finish | |
170 | } else //if there is a next file | |
171 | { | |
d3a269ff | 172 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->Last(); |
173 | fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Last(); | |
174 | fPCurrItem=(AliQADirListItem*)GetItemList()->Last(); | |
923f55ee | 175 | OpenCurrentFile(); |
176 | OpenCurrentDirectory(); | |
177 | } | |
178 | } else //if there is a next detector | |
179 | { | |
d3a269ff | 180 | fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Last(); |
181 | fPCurrItem=(AliQADirListItem*)GetItemList()->Last(); | |
923f55ee | 182 | OpenCurrentDirectory(); |
183 | } | |
184 | } else //if there is a next level | |
185 | { | |
d3a269ff | 186 | fPCurrItem=(AliQADirListItem*)GetItemList()->Last(); |
923f55ee | 187 | OpenCurrentDirectory(); |
923f55ee | 188 | } |
189 | } else //if there is a next histgram | |
190 | { | |
923f55ee | 191 | } |
192 | return kTRUE; | |
193 | } | |
194 | ||
d3a269ff | 195 | //_________________________________________________________________________ |
196 | void AliQAHistNavigator::SetExpertMode(Bool_t mode) | |
197 | { | |
198 | //sets the expert mode | |
199 | Bool_t oldmode = fExpertMode; | |
200 | fExpertMode = mode; | |
7e0cf530 | 201 | if (fExpertMode!=oldmode) fPCurrItem = (AliQADirListItem*)GetItemList()->First(); |
d3a269ff | 202 | |
203 | } | |
204 | ||
923f55ee | 205 | //_________________________________________________________________________ |
206 | Bool_t AliQAHistNavigator::OpenCurrentFile() | |
207 | { | |
d3a269ff | 208 | //open current file |
923f55ee | 209 | if (fPFile) fPFile->Close(); |
210 | if (!(fPFile->Open(GetFileName(),"READ"))) | |
211 | { | |
923f55ee | 212 | cout<<"There is no file: "<<GetFileName()<<endl; |
55a7e500 | 213 | return kFALSE; |
923f55ee | 214 | } |
215 | return kTRUE; | |
216 | } | |
217 | ||
218 | //_________________________________________________________________________ | |
219 | Bool_t AliQAHistNavigator::OpenCurrentDirectory() | |
220 | { | |
d3a269ff | 221 | //Open current directory |
923f55ee | 222 | if (!gDirectory->cd(GetDirName())) return kFALSE; |
223 | return kTRUE; | |
224 | } | |
225 | ||
226 | //_________________________________________________________________________ | |
227 | Bool_t AliQAHistNavigator::SetFile( TString file ) | |
228 | { | |
d3a269ff | 229 | //Set a new file to read from |
230 | AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->FindObject ( file.Data() ); | |
923f55ee | 231 | if (!tmp) return kFALSE; |
232 | fPCurrFile = tmp; | |
233 | OpenCurrentFile(); | |
d3a269ff | 234 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
235 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); | |
236 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 237 | return kTRUE; |
238 | } | |
239 | ||
240 | //_________________________________________________________________________ | |
241 | Bool_t AliQAHistNavigator::SetFile( Int_t file ) | |
242 | { | |
d3a269ff | 243 | //Set a new file to read from |
923f55ee | 244 | printf("AliQAHistNavigator::SetFile(%i)\n",file); |
d3a269ff | 245 | AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->At(file); |
923f55ee | 246 | if (!tmp) return kFALSE; |
247 | fPCurrFile = tmp; | |
248 | OpenCurrentFile(); | |
d3a269ff | 249 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
250 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); | |
251 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 252 | OpenCurrentDirectory(); |
253 | return kTRUE; | |
254 | } | |
255 | ||
256 | //_________________________________________________________________________ | |
257 | Bool_t AliQAHistNavigator::SetDetector( TString det ) | |
258 | { | |
d3a269ff | 259 | //Set a new detector |
260 | AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->FindObject( det.Data() ); | |
923f55ee | 261 | if (!tmp) return kFALSE; |
262 | fPCurrDetector = tmp; | |
d3a269ff | 263 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); |
264 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 265 | OpenCurrentDirectory(); |
266 | return kTRUE; | |
267 | } | |
268 | ||
269 | //_________________________________________________________________________ | |
270 | Bool_t AliQAHistNavigator::SetDetector( Int_t det ) | |
271 | { | |
d3a269ff | 272 | //Set a new detector |
923f55ee | 273 | printf("AliQAHistNavigator::SetDetector(%i)\n",det); |
d3a269ff | 274 | AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->At( det ); |
923f55ee | 275 | if (!tmp) return kFALSE; |
276 | fPCurrDetector = tmp; | |
d3a269ff | 277 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); |
278 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 279 | OpenCurrentDirectory(); |
280 | return kTRUE; | |
281 | } | |
282 | ||
283 | //_________________________________________________________________________ | |
284 | Bool_t AliQAHistNavigator::SetLevel( TString level ) | |
285 | { | |
d3a269ff | 286 | //Set a new level |
287 | AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->FindObject( level.Data() ); | |
923f55ee | 288 | if (!tmp) return kFALSE; |
289 | fPCurrLevel = tmp; | |
d3a269ff | 290 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); |
923f55ee | 291 | OpenCurrentDirectory(); |
292 | return kTRUE; | |
293 | } | |
294 | ||
295 | //_________________________________________________________________________ | |
296 | Bool_t AliQAHistNavigator::SetLevel( Int_t level ) | |
297 | { | |
d3a269ff | 298 | //Set a new level |
299 | AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->At( level ); | |
923f55ee | 300 | if (!tmp) return kFALSE; |
301 | fPCurrLevel = tmp; | |
d3a269ff | 302 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); |
923f55ee | 303 | OpenCurrentDirectory(); |
304 | return kTRUE; | |
305 | } | |
306 | ||
307 | //_________________________________________________________________________ | |
d3a269ff | 308 | Bool_t AliQAHistNavigator::SetItem( TString hist ) |
923f55ee | 309 | { |
d3a269ff | 310 | //set the new item |
311 | AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->FindObject( hist.Data() ); | |
923f55ee | 312 | if (!tmp) return kFALSE; |
d3a269ff | 313 | fPCurrItem = tmp; |
923f55ee | 314 | return kTRUE; |
315 | } | |
316 | ||
317 | //_________________________________________________________________________ | |
d3a269ff | 318 | Bool_t AliQAHistNavigator::SetItem( Int_t hist ) |
923f55ee | 319 | { |
d3a269ff | 320 | //set the new item |
321 | AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->At( hist ); | |
923f55ee | 322 | if (!tmp) return kFALSE; |
d3a269ff | 323 | fPCurrItem = tmp; |
923f55ee | 324 | return kTRUE; |
325 | } | |
326 | ||
327 | //_________________________________________________________________________ | |
d3a269ff | 328 | TList* AliQAHistNavigator::GetItemList() |
923f55ee | 329 | { |
d3a269ff | 330 | //returns the current list of histograms, if none, returns empty list |
7e0cf530 | 331 | TList* itemlist=NULL; |
d3a269ff | 332 | if (fExpertMode) |
333 | { | |
7e0cf530 | 334 | AliQADirList* expertlist = (AliQADirList*)fPCurrLevel->GetDirs()->FindObject(fExpertDirName); |
d3a269ff | 335 | if (expertlist) itemlist = expertlist->GetItems(); |
336 | else | |
337 | { | |
338 | //this is a bit of a hack, but it will always return something sensible | |
339 | AliQADirListItem* it = (AliQADirListItem*)fPEmptyList->First(); | |
340 | it->SetParent(fPCurrLevel); | |
341 | itemlist = fPEmptyList; | |
342 | } | |
343 | } else | |
344 | { | |
7e0cf530 | 345 | itemlist = fPCurrLevel->GetItems(); |
d3a269ff | 346 | } |
347 | return itemlist; | |
923f55ee | 348 | } |
349 | ||
350 | //_________________________________________________________________________ | |
351 | TString AliQAHistNavigator::GetDetectorName() | |
352 | { | |
d3a269ff | 353 | //Get name of current detector |
923f55ee | 354 | if (!fPCurrDetector) return ""; |
355 | TString name = fPCurrDetector->GetName(); | |
356 | return name; | |
357 | } | |
358 | ||
359 | //_________________________________________________________________________ | |
360 | TString AliQAHistNavigator::GetLevelName() | |
361 | { | |
d3a269ff | 362 | //Get name of current leve |
923f55ee | 363 | if (!fPCurrLevel) return ""; |
364 | TString name = fPCurrLevel->GetName(); | |
365 | return name; | |
366 | } | |
367 | ||
368 | //_________________________________________________________________________ | |
369 | TString AliQAHistNavigator::GetFileName() | |
370 | { | |
d3a269ff | 371 | //Get name of current file |
923f55ee | 372 | if (!fPCurrFile) return ""; |
373 | TString file = fPCurrFile->GetName(); | |
374 | return file; | |
375 | } | |
376 | ||
377 | //_________________________________________________________________________ | |
378 | TString AliQAHistNavigator::GetDirName() | |
379 | { | |
d3a269ff | 380 | //get the name of dir containing current item |
7e0cf530 | 381 | if (!fPCurrItem) return ""; |
d3a269ff | 382 | AliQADirList* d=(AliQADirList*)fPCurrItem->GetParent(); |
383 | TString path; | |
384 | do | |
385 | { | |
386 | path = d->GetName() + path; | |
387 | path = "/" + path; | |
388 | d=d->GetParent(); | |
389 | } | |
390 | while (d->GetParent()); | |
391 | return path; | |
923f55ee | 392 | } |
393 | ||
394 | //_________________________________________________________________________ | |
21535372 | 395 | TString AliQAHistNavigator::GetPath(AliQADirListItem* const item) |
923f55ee | 396 | { |
d3a269ff | 397 | //Get the full path to teh directory containing item |
398 | AliQADirList* d=item->GetParent(); | |
399 | TString path = "";//item->GetString(); | |
923f55ee | 400 | do |
401 | { | |
d3a269ff | 402 | TString sep = (d->GetParent()) ? "/" : ":/" ; |
403 | path = d->GetName() + sep + path; | |
404 | } | |
b91f40cc | 405 | while ((d=d->GetParent())); |
d3a269ff | 406 | return path; |
923f55ee | 407 | } |
408 | ||
409 | //_________________________________________________________________________ | |
d3a269ff | 410 | TString AliQAHistNavigator::GetItemName() |
923f55ee | 411 | { |
d3a269ff | 412 | //Get name of current item |
413 | if (!fPCurrItem) return ""; | |
414 | return fPCurrItem->GetString(); | |
923f55ee | 415 | } |
416 | ||
417 | //_________________________________________________________________________ | |
418 | Bool_t AliQAHistNavigator::GetListOfFiles() | |
419 | { | |
d3a269ff | 420 | //scan directory for QA files |
923f55ee | 421 | delete fPListOfFiles; |
d3a269ff | 422 | fPListOfFiles = new AliQADirList(); |
423 | ||
21535372 | 424 | TString fileNameCORR; |
425 | TString fileNameQAResult; | |
923f55ee | 426 | |
427 | TString macdir("."); | |
428 | gSystem->ExpandPathName(macdir); | |
429 | ||
430 | void* dirhandle = gSystem->OpenDirectory(macdir.Data()); | |
431 | if(dirhandle != 0) | |
432 | { | |
433 | const char* filename; | |
434 | TString runstr = ""; | |
435 | TString revstr = ""; | |
436 | runstr += fRun; | |
923f55ee | 437 | TString reg; |
438 | reg+= ".*QA\\."; | |
923f55ee | 439 | reg+= (fRun==0) ? "[0-9].*" : revstr.Data(); |
440 | reg+= "\\.root$"; | |
d3a269ff | 441 | TPRegexp reHist(reg); |
442 | TPRegexp reMerged("Merged.QA.Data.[0-9]*.root"); | |
443 | TPRegexp reCORR("CORR.QA.[0-9]*.root"); | |
444 | TPRegexp reQA("QA.root"); | |
923f55ee | 445 | std::list<string> names; |
446 | while((filename = gSystem->GetDirEntry(dirhandle)) != 0) | |
447 | { | |
d3a269ff | 448 | if (reCORR.Match(filename)) |
449 | { | |
21535372 | 450 | fileNameCORR = filename; |
d3a269ff | 451 | continue; |
452 | } | |
453 | if (reQA.Match(filename)) | |
454 | { | |
21535372 | 455 | fileNameQAResult = filename; |
d3a269ff | 456 | continue; |
457 | } | |
458 | if (reMerged.Match(filename)) | |
459 | { | |
460 | names.clear(); | |
461 | names.push_back(filename); | |
462 | break; | |
463 | } | |
464 | if (reHist.Match(filename)) | |
923f55ee | 465 | { |
466 | names.push_back(filename); | |
467 | } | |
468 | } | |
21535372 | 469 | if (!fPCORRFile) fPCORRFile = new TFile(fileNameCORR,"READ"); |
470 | if (!fPQAResultFile) fPQAResultFile = new TFile(fileNameQAResult,"READ"); | |
923f55ee | 471 | if (names.empty()) |
472 | { | |
473 | printf("GetListOfFiles: no files matching...\n"); | |
474 | return kFALSE; | |
475 | } | |
476 | names.sort(); | |
477 | char fullName[1000]; | |
478 | for (std::list<string>::iterator si=names.begin(); si!=names.end(); ++si) | |
479 | { | |
4dc1a1d3 | 480 | snprintf(fullName,sizeof(fullName),"%s", si->c_str()); |
d3a269ff | 481 | AliQADirList* f = new AliQADirList(); |
923f55ee | 482 | f->SetName(fullName); |
d3a269ff | 483 | fPListOfFiles->GetDirs()->AddLast(f); |
923f55ee | 484 | } |
485 | } | |
486 | else | |
487 | { | |
488 | gSystem->FreeDirectory(dirhandle); | |
489 | return kFALSE; | |
490 | } | |
491 | return kTRUE; | |
492 | } | |
493 | ||
494 | //_________________________________________________________________________ | |
495 | Bool_t AliQAHistNavigator::CloneDirStructure() | |
496 | { | |
d3a269ff | 497 | //scan all files |
923f55ee | 498 | if (!GetListOfFiles()) return kFALSE; |
d3a269ff | 499 | if (fPListOfFiles->GetDirs()->GetEntries()==0) return kFALSE; |
500 | TIter fileiter(fPListOfFiles->GetDirs()); | |
501 | AliQADirList* f; | |
502 | while ((f = (AliQADirList*)fileiter.Next())) | |
923f55ee | 503 | { |
504 | TString filename = f->GetName(); | |
923f55ee | 505 | TFile file(filename); |
506 | if (!Crawl(f)) continue; | |
507 | } | |
508 | return kTRUE; | |
509 | } | |
510 | ||
511 | //_________________________________________________________________________ | |
d3a269ff | 512 | Bool_t AliQAHistNavigator::Crawl(AliQADirList* dir) |
923f55ee | 513 | { |
21535372 | 514 | //scans the current directory and puts result in dir |
515 | //returns false if dir in file empty | |
d3a269ff | 516 | TString oldkeyname; |
517 | TString keyname; | |
923f55ee | 518 | TString pwd = gDirectory->GetPath(); |
923f55ee | 519 | TList* keys = gDirectory->GetListOfKeys(); |
520 | if (!keys) return kFALSE; | |
521 | if (keys->GetEntries()==0) return kFALSE; | |
522 | TIter keyiter(keys); | |
523 | TKey* key; | |
524 | while ((key = dynamic_cast <TKey* > (keyiter.Next()) )) | |
525 | { | |
d3a269ff | 526 | keyname = key->GetName(); |
527 | if (keyname==oldkeyname) continue; //do not copy cycles | |
528 | oldkeyname = keyname; | |
923f55ee | 529 | TString classname=key->GetClassName(); |
530 | if (!classname) return kFALSE; | |
531 | if (classname=="TDirectoryFile") | |
532 | { | |
533 | gDirectory->cd(key->GetName()); | |
d3a269ff | 534 | AliQADirList* newdir = new AliQADirList(); |
923f55ee | 535 | if (!Crawl(newdir)) |
536 | { | |
537 | gDirectory->cd(pwd); | |
538 | continue; | |
539 | } | |
540 | gDirectory->cd(pwd); | |
541 | ||
d3a269ff | 542 | newdir->SetName(keyname); |
543 | newdir->SetParent(dir); | |
544 | dir->GetDirs()->AddLast(newdir); | |
923f55ee | 545 | } |
546 | else | |
547 | { | |
d3a269ff | 548 | AliQADirListItem* item = new AliQADirListItem(keyname); |
549 | item->SetParent(dir); | |
550 | dir->GetItems()->AddLast(item); | |
923f55ee | 551 | } |
552 | } | |
553 | return kTRUE; | |
554 | } | |
7b852582 | 555 | |
d3a269ff | 556 | //_________________________________________________________________________ |
7b852582 | 557 | Bool_t AliQAHistNavigator::ReReadFiles() |
558 | { | |
d3a269ff | 559 | //close, open and rescan the files |
560 | if (!CloneDirStructure()) | |
561 | { | |
562 | printf("AliQAHistNavigator::AliQAHistNavigator(): error reading files\n"); | |
563 | return kFALSE; | |
564 | } | |
565 | fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First(); | |
566 | if (fPCurrFile) | |
7b852582 | 567 | { |
d3a269ff | 568 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
569 | if (fPCurrDetector) | |
7b852582 | 570 | { |
d3a269ff | 571 | fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First(); |
572 | if (fPCurrLevel) | |
7b852582 | 573 | { |
d3a269ff | 574 | fPCurrItem = (AliQADirListItem*) GetItemList()->First(); |
575 | if (fPCurrItem) | |
7b852582 | 576 | { |
d3a269ff | 577 | fInitOK = kTRUE; |
578 | OpenCurrentFile(); | |
579 | OpenCurrentDirectory(); | |
7b852582 | 580 | } |
581 | } | |
582 | } | |
7b852582 | 583 | } |
584 | return kTRUE; | |
585 | } | |
586 | ||
21535372 | 587 | //_________________________________________________________________________ |
d3a269ff | 588 | //_________________________________________________________________________ |
589 | ClassImp(AliQADirList) | |
590 | //_________________________________________________________________________ | |
591 | AliQADirList::AliQADirList(): | |
592 | TNamed(), | |
593 | fPParent(NULL), | |
594 | fPItems(new TList()), | |
595 | fPDirs(new TList()) | |
596 | { | |
597 | //ctor | |
598 | } | |
599 | ||
600 | //_________________________________________________________________________ | |
601 | AliQADirList::~AliQADirList() | |
602 | { | |
603 | //dtor | |
604 | if (fPParent) delete fPParent; | |
605 | delete fPItems; | |
606 | delete fPDirs; | |
607 | } | |
608 | ||
609 | //_________________________________________________________________________ | |
610 | ClassImp(AliQADirListItem) | |
611 | //_________________________________________________________________________ | |
612 | AliQADirListItem::AliQADirListItem(const char* s): | |
613 | TObjString(s), | |
614 | fPParent(NULL) | |
615 | { | |
616 | //ctor | |
617 | } | |
618 | ||
619 | //_________________________________________________________________________ | |
620 | AliQADirListItem::~AliQADirListItem() | |
621 | { | |
622 | //dtor | |
623 | if (fPParent) delete fPParent; | |
624 | } | |
625 |