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