]>
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; | |
2df7b269 | 201 | TList* itemList = GetItemList(); |
202 | ||
203 | if (fExpertMode!=oldmode && itemList) fPCurrItem = (AliQADirListItem*)itemList->First(); | |
d3a269ff | 204 | |
205 | } | |
206 | ||
923f55ee | 207 | //_________________________________________________________________________ |
208 | Bool_t AliQAHistNavigator::OpenCurrentFile() | |
209 | { | |
d3a269ff | 210 | //open current file |
923f55ee | 211 | if (fPFile) fPFile->Close(); |
212 | if (!(fPFile->Open(GetFileName(),"READ"))) | |
213 | { | |
923f55ee | 214 | cout<<"There is no file: "<<GetFileName()<<endl; |
55a7e500 | 215 | return kFALSE; |
923f55ee | 216 | } |
217 | return kTRUE; | |
218 | } | |
219 | ||
220 | //_________________________________________________________________________ | |
221 | Bool_t AliQAHistNavigator::OpenCurrentDirectory() | |
222 | { | |
d3a269ff | 223 | //Open current directory |
923f55ee | 224 | if (!gDirectory->cd(GetDirName())) return kFALSE; |
225 | return kTRUE; | |
226 | } | |
227 | ||
228 | //_________________________________________________________________________ | |
229 | Bool_t AliQAHistNavigator::SetFile( TString file ) | |
230 | { | |
d3a269ff | 231 | //Set a new file to read from |
232 | AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->FindObject ( file.Data() ); | |
923f55ee | 233 | if (!tmp) return kFALSE; |
234 | fPCurrFile = tmp; | |
235 | OpenCurrentFile(); | |
d3a269ff | 236 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
237 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); | |
238 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 239 | return kTRUE; |
240 | } | |
241 | ||
242 | //_________________________________________________________________________ | |
243 | Bool_t AliQAHistNavigator::SetFile( Int_t file ) | |
244 | { | |
d3a269ff | 245 | //Set a new file to read from |
923f55ee | 246 | printf("AliQAHistNavigator::SetFile(%i)\n",file); |
d3a269ff | 247 | AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->At(file); |
923f55ee | 248 | if (!tmp) return kFALSE; |
249 | fPCurrFile = tmp; | |
250 | OpenCurrentFile(); | |
d3a269ff | 251 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
252 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); | |
253 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 254 | OpenCurrentDirectory(); |
255 | return kTRUE; | |
256 | } | |
257 | ||
258 | //_________________________________________________________________________ | |
259 | Bool_t AliQAHistNavigator::SetDetector( TString det ) | |
260 | { | |
d3a269ff | 261 | //Set a new detector |
262 | AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->FindObject( det.Data() ); | |
923f55ee | 263 | if (!tmp) return kFALSE; |
264 | fPCurrDetector = tmp; | |
d3a269ff | 265 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); |
266 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 267 | OpenCurrentDirectory(); |
268 | return kTRUE; | |
269 | } | |
270 | ||
271 | //_________________________________________________________________________ | |
272 | Bool_t AliQAHistNavigator::SetDetector( Int_t det ) | |
273 | { | |
d3a269ff | 274 | //Set a new detector |
923f55ee | 275 | printf("AliQAHistNavigator::SetDetector(%i)\n",det); |
d3a269ff | 276 | AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->At( det ); |
923f55ee | 277 | if (!tmp) return kFALSE; |
278 | fPCurrDetector = tmp; | |
d3a269ff | 279 | fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First(); |
280 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); | |
923f55ee | 281 | OpenCurrentDirectory(); |
282 | return kTRUE; | |
283 | } | |
284 | ||
285 | //_________________________________________________________________________ | |
286 | Bool_t AliQAHistNavigator::SetLevel( TString level ) | |
287 | { | |
d3a269ff | 288 | //Set a new level |
289 | AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->FindObject( level.Data() ); | |
923f55ee | 290 | if (!tmp) return kFALSE; |
291 | fPCurrLevel = tmp; | |
d3a269ff | 292 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); |
923f55ee | 293 | OpenCurrentDirectory(); |
294 | return kTRUE; | |
295 | } | |
296 | ||
297 | //_________________________________________________________________________ | |
298 | Bool_t AliQAHistNavigator::SetLevel( Int_t level ) | |
299 | { | |
d3a269ff | 300 | //Set a new level |
301 | AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->At( level ); | |
923f55ee | 302 | if (!tmp) return kFALSE; |
303 | fPCurrLevel = tmp; | |
d3a269ff | 304 | fPCurrItem = (AliQADirListItem*)GetItemList()->First(); |
923f55ee | 305 | OpenCurrentDirectory(); |
306 | return kTRUE; | |
307 | } | |
308 | ||
309 | //_________________________________________________________________________ | |
d3a269ff | 310 | Bool_t AliQAHistNavigator::SetItem( TString hist ) |
923f55ee | 311 | { |
d3a269ff | 312 | //set the new item |
313 | AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->FindObject( hist.Data() ); | |
923f55ee | 314 | if (!tmp) return kFALSE; |
d3a269ff | 315 | fPCurrItem = tmp; |
923f55ee | 316 | return kTRUE; |
317 | } | |
318 | ||
319 | //_________________________________________________________________________ | |
d3a269ff | 320 | Bool_t AliQAHistNavigator::SetItem( Int_t hist ) |
923f55ee | 321 | { |
d3a269ff | 322 | //set the new item |
323 | AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->At( hist ); | |
923f55ee | 324 | if (!tmp) return kFALSE; |
d3a269ff | 325 | fPCurrItem = tmp; |
923f55ee | 326 | return kTRUE; |
327 | } | |
328 | ||
329 | //_________________________________________________________________________ | |
d3a269ff | 330 | TList* AliQAHistNavigator::GetItemList() |
923f55ee | 331 | { |
d3a269ff | 332 | //returns the current list of histograms, if none, returns empty list |
2df7b269 | 333 | TList* itemlist=0; |
d3a269ff | 334 | if (fExpertMode) |
335 | { | |
2df7b269 | 336 | AliQADirList* expertlist = 0; |
337 | if(fPCurrLevel) expertlist = (AliQADirList*)fPCurrLevel->GetDirs()->FindObject(fExpertDirName); | |
d3a269ff | 338 | if (expertlist) itemlist = expertlist->GetItems(); |
339 | else | |
340 | { | |
341 | //this is a bit of a hack, but it will always return something sensible | |
342 | AliQADirListItem* it = (AliQADirListItem*)fPEmptyList->First(); | |
343 | it->SetParent(fPCurrLevel); | |
344 | itemlist = fPEmptyList; | |
345 | } | |
346 | } else | |
347 | { | |
2df7b269 | 348 | if(fPCurrLevel) itemlist = fPCurrLevel->GetItems(); |
d3a269ff | 349 | } |
350 | return itemlist; | |
923f55ee | 351 | } |
352 | ||
353 | //_________________________________________________________________________ | |
354 | TString AliQAHistNavigator::GetDetectorName() | |
355 | { | |
d3a269ff | 356 | //Get name of current detector |
923f55ee | 357 | if (!fPCurrDetector) return ""; |
358 | TString name = fPCurrDetector->GetName(); | |
359 | return name; | |
360 | } | |
361 | ||
362 | //_________________________________________________________________________ | |
363 | TString AliQAHistNavigator::GetLevelName() | |
364 | { | |
d3a269ff | 365 | //Get name of current leve |
923f55ee | 366 | if (!fPCurrLevel) return ""; |
367 | TString name = fPCurrLevel->GetName(); | |
368 | return name; | |
369 | } | |
370 | ||
371 | //_________________________________________________________________________ | |
372 | TString AliQAHistNavigator::GetFileName() | |
373 | { | |
d3a269ff | 374 | //Get name of current file |
923f55ee | 375 | if (!fPCurrFile) return ""; |
376 | TString file = fPCurrFile->GetName(); | |
377 | return file; | |
378 | } | |
379 | ||
380 | //_________________________________________________________________________ | |
381 | TString AliQAHistNavigator::GetDirName() | |
382 | { | |
d3a269ff | 383 | //get the name of dir containing current item |
2df7b269 | 384 | if (!fPCurrItem || !fPCurrItem->GetParent()) return ""; |
d3a269ff | 385 | AliQADirList* d=(AliQADirList*)fPCurrItem->GetParent(); |
386 | TString path; | |
387 | do | |
388 | { | |
389 | path = d->GetName() + path; | |
390 | path = "/" + path; | |
391 | d=d->GetParent(); | |
392 | } | |
393 | while (d->GetParent()); | |
394 | return path; | |
923f55ee | 395 | } |
396 | ||
397 | //_________________________________________________________________________ | |
21535372 | 398 | TString AliQAHistNavigator::GetPath(AliQADirListItem* const item) |
923f55ee | 399 | { |
d3a269ff | 400 | //Get the full path to teh directory containing item |
401 | AliQADirList* d=item->GetParent(); | |
402 | TString path = "";//item->GetString(); | |
923f55ee | 403 | do |
404 | { | |
d3a269ff | 405 | TString sep = (d->GetParent()) ? "/" : ":/" ; |
406 | path = d->GetName() + sep + path; | |
407 | } | |
b91f40cc | 408 | while ((d=d->GetParent())); |
d3a269ff | 409 | return path; |
923f55ee | 410 | } |
411 | ||
412 | //_________________________________________________________________________ | |
d3a269ff | 413 | TString AliQAHistNavigator::GetItemName() |
923f55ee | 414 | { |
d3a269ff | 415 | //Get name of current item |
416 | if (!fPCurrItem) return ""; | |
417 | return fPCurrItem->GetString(); | |
923f55ee | 418 | } |
419 | ||
420 | //_________________________________________________________________________ | |
421 | Bool_t AliQAHistNavigator::GetListOfFiles() | |
422 | { | |
d3a269ff | 423 | //scan directory for QA files |
923f55ee | 424 | delete fPListOfFiles; |
d3a269ff | 425 | fPListOfFiles = new AliQADirList(); |
426 | ||
21535372 | 427 | TString fileNameCORR; |
428 | TString fileNameQAResult; | |
923f55ee | 429 | |
430 | TString macdir("."); | |
431 | gSystem->ExpandPathName(macdir); | |
432 | ||
433 | void* dirhandle = gSystem->OpenDirectory(macdir.Data()); | |
434 | if(dirhandle != 0) | |
435 | { | |
436 | const char* filename; | |
437 | TString runstr = ""; | |
438 | TString revstr = ""; | |
439 | runstr += fRun; | |
923f55ee | 440 | TString reg; |
441 | reg+= ".*QA\\."; | |
923f55ee | 442 | reg+= (fRun==0) ? "[0-9].*" : revstr.Data(); |
443 | reg+= "\\.root$"; | |
d3a269ff | 444 | TPRegexp reHist(reg); |
445 | TPRegexp reMerged("Merged.QA.Data.[0-9]*.root"); | |
446 | TPRegexp reCORR("CORR.QA.[0-9]*.root"); | |
447 | TPRegexp reQA("QA.root"); | |
923f55ee | 448 | std::list<string> names; |
449 | while((filename = gSystem->GetDirEntry(dirhandle)) != 0) | |
450 | { | |
d3a269ff | 451 | if (reCORR.Match(filename)) |
452 | { | |
21535372 | 453 | fileNameCORR = filename; |
d3a269ff | 454 | continue; |
455 | } | |
456 | if (reQA.Match(filename)) | |
457 | { | |
21535372 | 458 | fileNameQAResult = filename; |
d3a269ff | 459 | continue; |
460 | } | |
461 | if (reMerged.Match(filename)) | |
462 | { | |
463 | names.clear(); | |
464 | names.push_back(filename); | |
465 | break; | |
466 | } | |
467 | if (reHist.Match(filename)) | |
923f55ee | 468 | { |
469 | names.push_back(filename); | |
470 | } | |
471 | } | |
21535372 | 472 | if (!fPCORRFile) fPCORRFile = new TFile(fileNameCORR,"READ"); |
473 | if (!fPQAResultFile) fPQAResultFile = new TFile(fileNameQAResult,"READ"); | |
923f55ee | 474 | if (names.empty()) |
475 | { | |
476 | printf("GetListOfFiles: no files matching...\n"); | |
477 | return kFALSE; | |
478 | } | |
479 | names.sort(); | |
480 | char fullName[1000]; | |
481 | for (std::list<string>::iterator si=names.begin(); si!=names.end(); ++si) | |
482 | { | |
4dc1a1d3 | 483 | snprintf(fullName,sizeof(fullName),"%s", si->c_str()); |
d3a269ff | 484 | AliQADirList* f = new AliQADirList(); |
923f55ee | 485 | f->SetName(fullName); |
d3a269ff | 486 | fPListOfFiles->GetDirs()->AddLast(f); |
923f55ee | 487 | } |
488 | } | |
489 | else | |
490 | { | |
491 | gSystem->FreeDirectory(dirhandle); | |
492 | return kFALSE; | |
493 | } | |
494 | return kTRUE; | |
495 | } | |
496 | ||
497 | //_________________________________________________________________________ | |
498 | Bool_t AliQAHistNavigator::CloneDirStructure() | |
499 | { | |
d3a269ff | 500 | //scan all files |
923f55ee | 501 | if (!GetListOfFiles()) return kFALSE; |
d3a269ff | 502 | if (fPListOfFiles->GetDirs()->GetEntries()==0) return kFALSE; |
503 | TIter fileiter(fPListOfFiles->GetDirs()); | |
504 | AliQADirList* f; | |
505 | while ((f = (AliQADirList*)fileiter.Next())) | |
923f55ee | 506 | { |
507 | TString filename = f->GetName(); | |
923f55ee | 508 | TFile file(filename); |
509 | if (!Crawl(f)) continue; | |
510 | } | |
511 | return kTRUE; | |
512 | } | |
513 | ||
514 | //_________________________________________________________________________ | |
d3a269ff | 515 | Bool_t AliQAHistNavigator::Crawl(AliQADirList* dir) |
923f55ee | 516 | { |
21535372 | 517 | //scans the current directory and puts result in dir |
518 | //returns false if dir in file empty | |
d3a269ff | 519 | TString oldkeyname; |
520 | TString keyname; | |
923f55ee | 521 | TString pwd = gDirectory->GetPath(); |
923f55ee | 522 | TList* keys = gDirectory->GetListOfKeys(); |
523 | if (!keys) return kFALSE; | |
524 | if (keys->GetEntries()==0) return kFALSE; | |
525 | TIter keyiter(keys); | |
526 | TKey* key; | |
527 | while ((key = dynamic_cast <TKey* > (keyiter.Next()) )) | |
528 | { | |
d3a269ff | 529 | keyname = key->GetName(); |
530 | if (keyname==oldkeyname) continue; //do not copy cycles | |
531 | oldkeyname = keyname; | |
923f55ee | 532 | TString classname=key->GetClassName(); |
533 | if (!classname) return kFALSE; | |
534 | if (classname=="TDirectoryFile") | |
535 | { | |
536 | gDirectory->cd(key->GetName()); | |
d3a269ff | 537 | AliQADirList* newdir = new AliQADirList(); |
923f55ee | 538 | if (!Crawl(newdir)) |
539 | { | |
540 | gDirectory->cd(pwd); | |
541 | continue; | |
542 | } | |
543 | gDirectory->cd(pwd); | |
544 | ||
d3a269ff | 545 | newdir->SetName(keyname); |
546 | newdir->SetParent(dir); | |
547 | dir->GetDirs()->AddLast(newdir); | |
923f55ee | 548 | } |
549 | else | |
550 | { | |
d3a269ff | 551 | AliQADirListItem* item = new AliQADirListItem(keyname); |
552 | item->SetParent(dir); | |
553 | dir->GetItems()->AddLast(item); | |
923f55ee | 554 | } |
555 | } | |
556 | return kTRUE; | |
557 | } | |
7b852582 | 558 | |
d3a269ff | 559 | //_________________________________________________________________________ |
7b852582 | 560 | Bool_t AliQAHistNavigator::ReReadFiles() |
561 | { | |
d3a269ff | 562 | //close, open and rescan the files |
563 | if (!CloneDirStructure()) | |
564 | { | |
565 | printf("AliQAHistNavigator::AliQAHistNavigator(): error reading files\n"); | |
566 | return kFALSE; | |
567 | } | |
568 | fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First(); | |
569 | if (fPCurrFile) | |
7b852582 | 570 | { |
d3a269ff | 571 | fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First(); |
572 | if (fPCurrDetector) | |
7b852582 | 573 | { |
d3a269ff | 574 | fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First(); |
575 | if (fPCurrLevel) | |
7b852582 | 576 | { |
d3a269ff | 577 | fPCurrItem = (AliQADirListItem*) GetItemList()->First(); |
578 | if (fPCurrItem) | |
7b852582 | 579 | { |
d3a269ff | 580 | fInitOK = kTRUE; |
581 | OpenCurrentFile(); | |
582 | OpenCurrentDirectory(); | |
7b852582 | 583 | } |
584 | } | |
585 | } | |
7b852582 | 586 | } |
587 | return kTRUE; | |
588 | } | |
589 | ||
21535372 | 590 | //_________________________________________________________________________ |
d3a269ff | 591 | //_________________________________________________________________________ |
592 | ClassImp(AliQADirList) | |
593 | //_________________________________________________________________________ | |
594 | AliQADirList::AliQADirList(): | |
595 | TNamed(), | |
596 | fPParent(NULL), | |
597 | fPItems(new TList()), | |
598 | fPDirs(new TList()) | |
599 | { | |
600 | //ctor | |
601 | } | |
602 | ||
603 | //_________________________________________________________________________ | |
604 | AliQADirList::~AliQADirList() | |
605 | { | |
606 | //dtor | |
607 | if (fPParent) delete fPParent; | |
608 | delete fPItems; | |
609 | delete fPDirs; | |
610 | } | |
611 | ||
612 | //_________________________________________________________________________ | |
613 | ClassImp(AliQADirListItem) | |
614 | //_________________________________________________________________________ | |
615 | AliQADirListItem::AliQADirListItem(const char* s): | |
616 | TObjString(s), | |
617 | fPParent(NULL) | |
618 | { | |
619 | //ctor | |
620 | } | |
621 | ||
622 | //_________________________________________________________________________ | |
623 | AliQADirListItem::~AliQADirListItem() | |
624 | { | |
625 | //dtor | |
626 | if (fPParent) delete fPParent; | |
627 | } | |
628 |