1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////
18 // support class for the QA histogram viewer
20 // origin: Mikolaj Krzewicki, Nikhef, Mikolaj.Krzewicki@cern.ch
22 ///////////////////////////////////////////////////////////////////////////
24 #include "AliQAHistNavigator.h"
26 ClassImp(AliQAHistNavigator)
28 //_________________________________________________________________________
29 AliQAHistNavigator::AliQAHistNavigator(Int_t run):
32 fPQAResultFile( NULL ),
35 fPCurrDetector( NULL ),
38 fPListOfFiles( new AliQADirList() ),
40 fLoopAllDetectors(kTRUE),
41 fLoopAllLevels(kTRUE),
44 fExpertDirName("Expert"),
45 fPEmptyList(new TList())
47 fPEmptyList->AddLast(new AliQADirListItem(""));
51 //_________________________________________________________________________
52 AliQAHistNavigator::~AliQAHistNavigator()
56 //_________________________________________________________________________
57 Bool_t AliQAHistNavigator::GetHistogram(TH1*& hist)
59 TString file = GetFileName();
60 TString dir = GetDirName();
61 TString histname = GetItemName();
62 cout<<"GetHistogram: "<<file<<":"<<dir<<"/"<<histname<<endl;
63 if (file==""||dir==""||histname=="")
65 printf("GetItem: nothing to fetch...\n");
68 if (!OpenCurrentDirectory()) return kFALSE;
69 hist = dynamic_cast<TH1*>( gDirectory->FindKey(histname)->ReadObj() );
72 printf("GetItem: null pointer returned by gDirectory\n");
78 //_________________________________________________________________________
79 Bool_t AliQAHistNavigator::Next()
81 if (!fPCurrFile||!fPCurrDetector||!fPCurrLevel) return kFALSE;
82 if (!(fPCurrItem=(AliQADirListItem*)GetItemList()->After(fPCurrItem)))
84 if (!(fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->After(fPCurrLevel)))
86 if (!(fPCurrDetector=(AliQADirList*)fPCurrFile->GetDirs()->After(fPCurrDetector)))
88 if (!(fPCurrFile=(AliQADirList*)fPListOfFiles->GetDirs()->After(fPCurrFile)))
90 //we're at the end of everything
93 //rewind to the beginning
94 fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First();
95 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
96 fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First();
97 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
99 OpenCurrentDirectory();
100 printf("----------------back at the beginning!\n");
101 } else return kFALSE; //no rewind, we finish
102 } else //if there is a next file
104 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
105 fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->First();
106 fPCurrItem=(AliQADirListItem*)GetItemList()->First();
108 OpenCurrentDirectory();
110 } else //if there is a next detector
112 fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->First();
113 fPCurrItem=(AliQADirListItem*)GetItemList()->First();
114 OpenCurrentDirectory();
116 } else //if there is a next level
118 fPCurrItem=(AliQADirListItem*)GetItemList()->First();
119 OpenCurrentDirectory();
121 } else //if there is a next histgram
127 //_________________________________________________________________________
128 Bool_t AliQAHistNavigator::Prev()
130 if (!fPCurrLevel||!fPCurrDetector||!fPCurrFile) return kFALSE;
131 if (!(fPCurrItem=(AliQADirListItem*)GetItemList()->Before(fPCurrItem)))
133 if (!(fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Before(fPCurrLevel)))
135 if (!(fPCurrDetector=(AliQADirList*)fPCurrFile->GetDirs()->Before(fPCurrDetector)))
137 if (!(fPCurrFile=(AliQADirList*)fPListOfFiles->GetDirs()->Before(fPCurrFile)))
139 //we're at the end of everything
142 //rewind to the beginning
143 fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->Last();
144 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->Last();
145 fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->Last();
146 fPCurrItem = (AliQADirListItem*)GetItemList()->Last();
148 OpenCurrentDirectory();
149 printf("----------------back at the end!\n");
150 } else return kFALSE; //no rewind, we finish
151 } else //if there is a next file
153 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->Last();
154 fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Last();
155 fPCurrItem=(AliQADirListItem*)GetItemList()->Last();
157 OpenCurrentDirectory();
159 } else //if there is a next detector
161 fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Last();
162 fPCurrItem=(AliQADirListItem*)GetItemList()->Last();
163 OpenCurrentDirectory();
165 } else //if there is a next level
167 fPCurrItem=(AliQADirListItem*)GetItemList()->Last();
168 OpenCurrentDirectory();
170 } else //if there is a next histgram
176 //_________________________________________________________________________
177 void AliQAHistNavigator::SetExpertMode(Bool_t mode)
179 //sets the expert mode
180 Bool_t oldmode = fExpertMode;
182 if (fExpertMode!=oldmode) fPCurrItem = (AliQADirListItem*)GetItemList()->First();
186 //_________________________________________________________________________
187 Bool_t AliQAHistNavigator::OpenCurrentFile()
190 if (fPFile) fPFile->Close();
191 if (!(fPFile->Open(GetFileName(),"READ")))
194 cout<<"There is no file: "<<GetFileName()<<endl;
199 //_________________________________________________________________________
200 Bool_t AliQAHistNavigator::OpenCurrentDirectory()
202 //Open current directory
203 if (!gDirectory->cd(GetDirName())) return kFALSE;
207 //_________________________________________________________________________
208 Bool_t AliQAHistNavigator::SetFile( TString file )
210 //Set a new file to read from
211 AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->FindObject ( file.Data() );
212 if (!tmp) return kFALSE;
215 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
216 fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
217 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
221 //_________________________________________________________________________
222 Bool_t AliQAHistNavigator::SetFile( Int_t file )
224 //Set a new file to read from
225 printf("AliQAHistNavigator::SetFile(%i)\n",file);
226 AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->At(file);
227 if (!tmp) return kFALSE;
230 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
231 fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
232 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
233 OpenCurrentDirectory();
237 //_________________________________________________________________________
238 Bool_t AliQAHistNavigator::SetDetector( TString det )
241 AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->FindObject( det.Data() );
242 if (!tmp) return kFALSE;
243 fPCurrDetector = tmp;
244 fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
245 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
246 OpenCurrentDirectory();
250 //_________________________________________________________________________
251 Bool_t AliQAHistNavigator::SetDetector( Int_t det )
254 printf("AliQAHistNavigator::SetDetector(%i)\n",det);
255 AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->At( det );
256 if (!tmp) return kFALSE;
257 fPCurrDetector = tmp;
258 fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
259 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
260 OpenCurrentDirectory();
264 //_________________________________________________________________________
265 Bool_t AliQAHistNavigator::SetLevel( TString level )
268 AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->FindObject( level.Data() );
269 if (!tmp) return kFALSE;
271 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
272 OpenCurrentDirectory();
276 //_________________________________________________________________________
277 Bool_t AliQAHistNavigator::SetLevel( Int_t level )
280 AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->At( level );
281 if (!tmp) return kFALSE;
283 fPCurrItem = (AliQADirListItem*)GetItemList()->First();
284 OpenCurrentDirectory();
288 //_________________________________________________________________________
289 Bool_t AliQAHistNavigator::SetItem( TString hist )
292 AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->FindObject( hist.Data() );
293 if (!tmp) return kFALSE;
298 //_________________________________________________________________________
299 Bool_t AliQAHistNavigator::SetItem( Int_t hist )
302 AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->At( hist );
303 if (!tmp) return kFALSE;
308 //_________________________________________________________________________
309 TList* AliQAHistNavigator::GetItemList()
311 //returns the current list of histograms, if none, returns empty list
312 TList* itemlist=NULL;
315 AliQADirList* expertlist = (AliQADirList*)fPCurrLevel->GetDirs()->FindObject(fExpertDirName);
316 if (expertlist) itemlist = expertlist->GetItems();
319 //this is a bit of a hack, but it will always return something sensible
320 AliQADirListItem* it = (AliQADirListItem*)fPEmptyList->First();
321 it->SetParent(fPCurrLevel);
322 itemlist = fPEmptyList;
326 itemlist = fPCurrLevel->GetItems();
331 //_________________________________________________________________________
332 TString AliQAHistNavigator::GetDetectorName()
334 //Get name of current detector
335 if (!fPCurrDetector) return "";
336 TString name = fPCurrDetector->GetName();
340 //_________________________________________________________________________
341 TString AliQAHistNavigator::GetLevelName()
343 //Get name of current leve
344 if (!fPCurrLevel) return "";
345 TString name = fPCurrLevel->GetName();
349 //_________________________________________________________________________
350 TString AliQAHistNavigator::GetFileName()
352 //Get name of current file
353 if (!fPCurrFile) return "";
354 TString file = fPCurrFile->GetName();
358 //_________________________________________________________________________
359 TString AliQAHistNavigator::GetDirName()
361 //get the name of dir containing current item
362 if (!fPCurrItem) return "";
363 AliQADirList* d=(AliQADirList*)fPCurrItem->GetParent();
367 path = d->GetName() + path;
371 while (d->GetParent());
375 //_________________________________________________________________________
376 TString AliQAHistNavigator::GetPath(AliQADirListItem* item)
378 //Get the full path to teh directory containing item
379 AliQADirList* d=item->GetParent();
380 TString path = "";//item->GetString();
383 TString sep = (d->GetParent()) ? "/" : ":/" ;
384 path = d->GetName() + sep + path;
386 while ((d=d->GetParent()));
390 //_________________________________________________________________________
391 TString AliQAHistNavigator::GetItemName()
393 //Get name of current item
394 if (!fPCurrItem) return "";
395 return fPCurrItem->GetString();
398 //_________________________________________________________________________
399 Bool_t AliQAHistNavigator::GetListOfFiles()
401 //scan directory for QA files
402 delete fPListOfFiles;
403 fPListOfFiles = new AliQADirList();
405 TString CORRFileName;
406 TString QAResultFileName;
409 gSystem->ExpandPathName(macdir);
411 void* dirhandle = gSystem->OpenDirectory(macdir.Data());
414 const char* filename;
420 reg+= (fRun==0) ? "[0-9].*" : revstr.Data();
422 TPRegexp reHist(reg);
423 TPRegexp reMerged("Merged.QA.Data.[0-9]*.root");
424 TPRegexp reCORR("CORR.QA.[0-9]*.root");
425 TPRegexp reQA("QA.root");
426 std::list<string> names;
427 while((filename = gSystem->GetDirEntry(dirhandle)) != 0)
429 if (reCORR.Match(filename))
431 CORRFileName = filename;
434 if (reQA.Match(filename))
436 QAResultFileName = filename;
439 if (reMerged.Match(filename))
442 names.push_back(filename);
445 if (reHist.Match(filename))
447 names.push_back(filename);
450 if (!fPCORRFile) fPCORRFile = new TFile(CORRFileName,"READ");
451 if (!fPQAResultFile) fPQAResultFile = new TFile(QAResultFileName,"READ");
454 printf("GetListOfFiles: no files matching...\n");
459 for (std::list<string>::iterator si=names.begin(); si!=names.end(); ++si)
461 sprintf(fullName,"%s", si->c_str());
462 AliQADirList* f = new AliQADirList();
463 f->SetName(fullName);
464 fPListOfFiles->GetDirs()->AddLast(f);
469 gSystem->FreeDirectory(dirhandle);
475 //_________________________________________________________________________
476 Bool_t AliQAHistNavigator::CloneDirStructure()
479 if (!GetListOfFiles()) return kFALSE;
480 if (fPListOfFiles->GetDirs()->GetEntries()==0) return kFALSE;
481 TIter fileiter(fPListOfFiles->GetDirs());
483 while ((f = (AliQADirList*)fileiter.Next()))
485 TString filename = f->GetName();
486 TFile file(filename);
487 if (!Crawl(f)) continue;
492 //_________________________________________________________________________
493 Bool_t AliQAHistNavigator::Crawl(AliQADirList* dir)
497 //scans the current directory and puts result in dir
498 TString pwd = gDirectory->GetPath();
499 //returns false if dir in file empty
500 TList* keys = gDirectory->GetListOfKeys();
501 if (!keys) return kFALSE;
502 if (keys->GetEntries()==0) return kFALSE;
505 while ((key = dynamic_cast <TKey* > (keyiter.Next()) ))
507 keyname = key->GetName();
508 if (keyname==oldkeyname) continue; //do not copy cycles
509 oldkeyname = keyname;
510 TString classname=key->GetClassName();
511 if (!classname) return kFALSE;
512 if (classname=="TDirectoryFile")
514 gDirectory->cd(key->GetName());
515 AliQADirList* newdir = new AliQADirList();
523 newdir->SetName(keyname);
524 newdir->SetParent(dir);
525 dir->GetDirs()->AddLast(newdir);
529 AliQADirListItem* item = new AliQADirListItem(keyname);
530 item->SetParent(dir);
531 dir->GetItems()->AddLast(item);
537 //_________________________________________________________________________
538 Bool_t AliQAHistNavigator::ReReadFiles()
540 //close, open and rescan the files
541 if (!CloneDirStructure())
543 printf("AliQAHistNavigator::AliQAHistNavigator(): error reading files\n");
546 fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First();
549 fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
552 fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First();
555 fPCurrItem = (AliQADirListItem*) GetItemList()->First();
560 OpenCurrentDirectory();
568 //_________________________________________________________________________
569 ClassImp(AliQADirList)
570 //_________________________________________________________________________
571 AliQADirList::AliQADirList():
574 fPItems(new TList()),
580 //_________________________________________________________________________
581 AliQADirList::~AliQADirList()
584 if (fPParent) delete fPParent;
589 //_________________________________________________________________________
590 ClassImp(AliQADirListItem)
591 //_________________________________________________________________________
592 AliQADirListItem::AliQADirListItem(const char* s):
599 //_________________________________________________________________________
600 AliQADirListItem::~AliQADirListItem()
603 if (fPParent) delete fPParent;