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