Update of the QA histo viewer. 2 new helper classes (Mikolaj)
[u/mrichter/AliRoot.git] / MONITOR / AliQAHistNavigator.cxx
index d209bd4..ad65276 100644 (file)
 ClassImp(AliQAHistNavigator)
 
 //_________________________________________________________________________
-AliQAHistNavigator::AliQAHistNavigator(Int_t run, Int_t rev):
+AliQAHistNavigator::AliQAHistNavigator(Int_t run):
     fPFile( NULL ),
+    fPCORRFile( NULL ),
+    fPQAResultFile( NULL ),
     fRun( run ),
-    fCyc( rev ),
     fPCurrFile( NULL ),
     fPCurrDetector( NULL ),
     fPCurrLevel( NULL ),
-    fPCurrHistName( NULL ),
-    fPListOfFiles( new TList() ),
+    fPCurrItem( NULL ),
+    fPListOfFiles( new AliQADirList() ),
     fLoopAllFiles(kTRUE),
     fLoopAllDetectors(kTRUE),
     fLoopAllLevels(kTRUE),
-    fInitOK(kFALSE)
+    fInitOK(kFALSE),
+    fExpertMode(kFALSE),
+    fExpertDirName("Expert"),
+    fPEmptyList(new TList())
 {
+    fPEmptyList->AddLast(new AliQADirListItem(""));
     ReReadFiles();
 }
 
 //_________________________________________________________________________
-Bool_t AliQAHistNavigator::GetNextHistogram(TH1*& hist)
+AliQAHistNavigator::~AliQAHistNavigator()
 {
-    //moves to the next histogram from the list and tries to get it.
-    if (!Next()) 
-    {
-        hist = NULL;
-        return kFALSE;
-    }
-    if (GetHistName()=="")
-        if (!Next())
-        {
-            hist = NULL;
-            return kTRUE;
-        }
-    return GetHistogram(hist);
 }
 
 //_________________________________________________________________________
@@ -66,89 +58,68 @@ Bool_t AliQAHistNavigator::GetHistogram(TH1*& hist)
 {
     TString file = GetFileName();
     TString dir = GetDirName();
-    TString histname = GetHistName();
+    TString histname = GetItemName();
+    cout<<"GetHistogram: "<<file<<":"<<dir<<"/"<<histname<<endl;
     if (file==""||dir==""||histname=="") 
     {
-        printf("GetHistogram: nothing to fetch...\n");
+        printf("GetItem: nothing to fetch...\n");
         return kFALSE;
     }
-    gDirectory->GetObject(file+":"+dir+"/"+histname,hist);
+    if (!OpenCurrentDirectory()) return kFALSE;
+    hist = dynamic_cast<TH1*>( gDirectory->FindKey(histname)->ReadObj() );
     if (!hist)
     {
-        printf("GetHistogram: null pointer returned by gDirectory\n");
+        printf("GetItem: null pointer returned by gDirectory\n");
         return kFALSE;
     }
     return kTRUE;
 }
 
-//_________________________________________________________________________
-Bool_t AliQAHistNavigator::GetPrevHistogram(TH1*& hist)
-{
-    //moves to the prev histogram from the list and tries to get it.
-    if (!Prev()) 
-    {
-        hist = NULL;
-        return kFALSE;
-    }
-    if (GetHistName()=="")
-        if (!Prev())
-        {
-            hist = NULL;
-            return kTRUE;
-        }
-    return GetHistogram(hist);
-}
-
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::Next()
 {
-    if (!fPCurrHistName||!fPCurrFile||!fPCurrDetector||!fPCurrLevel) return kFALSE;
-    if (!(fPCurrHistName=(TObjString*)fPCurrLevel->After(fPCurrHistName)))
+    if (!fPCurrFile||!fPCurrDetector||!fPCurrLevel) return kFALSE;
+    if (!(fPCurrItem=(AliQADirListItem*)GetItemList()->After(fPCurrItem)))
     {
-        if (!(fPCurrLevel=(TList*)fPCurrDetector->After(fPCurrLevel)))
+        if (!(fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->After(fPCurrLevel)))
         {
-            if (!(fPCurrDetector=(TList*)fPCurrFile->After(fPCurrDetector)))
+            if (!(fPCurrDetector=(AliQADirList*)fPCurrFile->GetDirs()->After(fPCurrDetector)))
             {
-                if (!(fPCurrFile=(TList*)fPListOfFiles->After(fPCurrFile)))
+                if (!(fPCurrFile=(AliQADirList*)fPListOfFiles->GetDirs()->After(fPCurrFile)))
                 {
                     //we're at the end of everything
                     if (fLoopAllFiles)
                     {
                         //rewind to the beginning
-                        fPCurrFile = (TList*)fPListOfFiles->First();
-                        fPCurrDetector = (TList*)fPCurrFile->First();
-                        fPCurrLevel = (TList*) fPCurrDetector->First();
-                        fPCurrHistName = (TObjString*) fPCurrLevel->First();
+                        fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First();
+                        fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
+                        fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First();
+                        fPCurrItem = (AliQADirListItem*)GetItemList()->First();
                         OpenCurrentFile();
                         OpenCurrentDirectory();
                         printf("----------------back at the beginning!\n");
                     } else return kFALSE; //no rewind, we finish
                 } else //if there is a next file
                 {
-                    fPCurrDetector = (TList*)fPCurrFile->First();
-                    fPCurrLevel=(TList*)fPCurrDetector->First();
-                    fPCurrHistName=(TObjString*)fPCurrLevel->First();
-                    cout<<GetFileName()<<":"<<GetDetectorName()<<"/"<<GetLevelName()<<"/"<<GetHistName()<<endl;
+                    fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
+                    fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->First();
+                    fPCurrItem=(AliQADirListItem*)GetItemList()->First();
                     OpenCurrentFile();
                     OpenCurrentDirectory();
                 }
             } else //if there is a next detector
             {
-                fPCurrLevel=(TList*)fPCurrDetector->First();
-                fPCurrHistName=(TObjString*)fPCurrLevel->First();
-                cout<<GetDetectorName()<<"/"<<GetLevelName()<<"/"<<GetHistName()<<endl;
+                fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->First();
+                fPCurrItem=(AliQADirListItem*)GetItemList()->First();
                 OpenCurrentDirectory();
             }
         } else //if there is a next level
         {
-            fPCurrHistName=(TObjString*)fPCurrLevel->First();
-            cout<<GetLevelName()<<"/"<<GetHistName()<<endl;
+            fPCurrItem=(AliQADirListItem*)GetItemList()->First();
             OpenCurrentDirectory();
-            cout<<GetHistName()<<endl;
         }
     } else //if there is a next histgram
     {
-        cout<<GetHistName()<<endl;
     }
     return kTRUE;
 }
@@ -156,60 +127,66 @@ Bool_t AliQAHistNavigator::Next()
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::Prev()
 {
-    if (!fPCurrHistName) return kFALSE;
-    if (!(fPCurrHistName=(TObjString*)fPCurrLevel->Before(fPCurrHistName)))
+    if (!fPCurrLevel||!fPCurrDetector||!fPCurrFile) return kFALSE;
+    if (!(fPCurrItem=(AliQADirListItem*)GetItemList()->Before(fPCurrItem)))
     {
-        if (!(fPCurrLevel=(TList*)fPCurrDetector->Before(fPCurrLevel)))
+        if (!(fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Before(fPCurrLevel)))
         {
-            if (!(fPCurrDetector=(TList*)fPCurrFile->Before(fPCurrDetector)))
+            if (!(fPCurrDetector=(AliQADirList*)fPCurrFile->GetDirs()->Before(fPCurrDetector)))
             {
-                if (!(fPCurrFile=(TList*)fPListOfFiles->Before(fPCurrFile)))
+                if (!(fPCurrFile=(AliQADirList*)fPListOfFiles->GetDirs()->Before(fPCurrFile)))
                 {
                     //we're at the end of everything
                     if (fLoopAllFiles)
                     {
                         //rewind to the beginning
-                        fPCurrFile = (TList*)fPListOfFiles->Last();
-                        fPCurrDetector = (TList*)fPCurrFile->Last();
-                        fPCurrLevel = (TList*) fPCurrDetector->Last();
-                        fPCurrHistName = (TObjString*) fPCurrLevel->Last();
+                        fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->Last();
+                        fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->Last();
+                        fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->Last();
+                        fPCurrItem = (AliQADirListItem*)GetItemList()->Last();
                         OpenCurrentFile();
                         OpenCurrentDirectory();
                         printf("----------------back at the end!\n");
                     } else return kFALSE; //no rewind, we finish
                 } else //if there is a next file
                 {
-                    fPCurrDetector = (TList*)fPCurrFile->Last();
-                    fPCurrLevel=(TList*)fPCurrDetector->Last();
-                    fPCurrHistName=(TObjString*)fPCurrLevel->Last();
-                    cout<<GetFileName()<<":"<<GetDetectorName()<<"/"<<GetLevelName()<<"/"<<GetHistName()<<endl;
+                    fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->Last();
+                    fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Last();
+                    fPCurrItem=(AliQADirListItem*)GetItemList()->Last();
                     OpenCurrentFile();
                     OpenCurrentDirectory();
                 }
             } else //if there is a next detector
             {
-                fPCurrLevel=(TList*)fPCurrDetector->Last();
-                fPCurrHistName=(TObjString*)fPCurrLevel->Last();
-                cout<<GetDetectorName()<<"/"<<GetLevelName()<<"/"<<GetHistName()<<endl;
+                fPCurrLevel=(AliQADirList*)fPCurrDetector->GetDirs()->Last();
+                fPCurrItem=(AliQADirListItem*)GetItemList()->Last();
                 OpenCurrentDirectory();
             }
         } else //if there is a next level
         {
-            fPCurrHistName=(TObjString*)fPCurrLevel->Last();
-            cout<<GetLevelName()<<"/"<<GetHistName()<<endl;
+            fPCurrItem=(AliQADirListItem*)GetItemList()->Last();
             OpenCurrentDirectory();
-            cout<<GetHistName()<<endl;
         }
     } else //if there is a next histgram
     {
-        cout<<GetHistName()<<endl;
     }
     return kTRUE;
 }
 
+//_________________________________________________________________________
+void AliQAHistNavigator::SetExpertMode(Bool_t mode)
+{
+    //sets the expert mode
+    Bool_t oldmode = fExpertMode;
+    fExpertMode = mode;
+    if (fExpertMode!=oldmode) fPCurrItem = (AliQADirListItem*)GetItemList()->First();
+    
+}
+
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::OpenCurrentFile()
 {
+    //open current file
     if (fPFile) fPFile->Close();
     if (!(fPFile->Open(GetFileName(),"READ")))
     {
@@ -222,6 +199,7 @@ Bool_t AliQAHistNavigator::OpenCurrentFile()
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::OpenCurrentDirectory()
 {
+    //Open current directory
     if (!gDirectory->cd(GetDirName())) return kFALSE;
     return kTRUE;
 }
@@ -229,27 +207,29 @@ Bool_t AliQAHistNavigator::OpenCurrentDirectory()
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::SetFile( TString file )
 {
-    TList* tmp = (TList*)fPListOfFiles->FindObject ( file.Data() );
+    //Set a new file to read from
+    AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->FindObject ( file.Data() );
     if (!tmp) return kFALSE;
     fPCurrFile = tmp;
     OpenCurrentFile();
-    fPCurrDetector = (TList*)fPCurrFile->First();
-    fPCurrLevel = (TList*)fPCurrDetector->First();
-    fPCurrHistName = (TObjString*)fPCurrLevel->First();
+    fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
+    fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
+    fPCurrItem = (AliQADirListItem*)GetItemList()->First();
     return kTRUE;
 }
 
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::SetFile( Int_t file )
 {
+    //Set a new file to read from
     printf("AliQAHistNavigator::SetFile(%i)\n",file);
-    TList* tmp = (TList*)fPListOfFiles->At(file);
+    AliQADirList* tmp = (AliQADirList*)fPListOfFiles->GetDirs()->At(file);
     if (!tmp) return kFALSE;
     fPCurrFile = tmp;
     OpenCurrentFile();
-    fPCurrDetector = (TList*)fPCurrFile->First();
-    fPCurrLevel = (TList*)fPCurrDetector->First();
-    fPCurrHistName = (TObjString*)fPCurrLevel->First();
+    fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
+    fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
+    fPCurrItem = (AliQADirListItem*)GetItemList()->First();
     OpenCurrentDirectory();
     return kTRUE;
 }
@@ -257,11 +237,12 @@ Bool_t AliQAHistNavigator::SetFile( Int_t file )
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::SetDetector( TString det )
 {
-    TList* tmp = (TList*)fPCurrFile->FindObject( det.Data() );
+    //Set a new detector
+    AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->FindObject( det.Data() );
     if (!tmp) return kFALSE;
     fPCurrDetector = tmp;
-    fPCurrLevel = (TList*)fPCurrDetector->First();
-    fPCurrHistName = (TObjString*)fPCurrLevel->First();
+    fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
+    fPCurrItem = (AliQADirListItem*)GetItemList()->First();
     OpenCurrentDirectory();
     return kTRUE;
 }
@@ -269,12 +250,13 @@ Bool_t AliQAHistNavigator::SetDetector( TString det )
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::SetDetector( Int_t det )
 {
+    //Set a new detector
     printf("AliQAHistNavigator::SetDetector(%i)\n",det);
-    TList* tmp = (TList*)fPCurrFile->At( det );
+    AliQADirList* tmp = (AliQADirList*)fPCurrFile->GetDirs()->At( det );
     if (!tmp) return kFALSE;
     fPCurrDetector = tmp;
-    fPCurrLevel = (TList*)fPCurrDetector->First();
-    fPCurrHistName = (TObjString*)fPCurrLevel->First();
+    fPCurrLevel = (AliQADirList*)fPCurrDetector->GetDirs()->First();
+    fPCurrItem = (AliQADirListItem*)GetItemList()->First();
     OpenCurrentDirectory();
     return kTRUE;
 }
@@ -282,10 +264,11 @@ Bool_t AliQAHistNavigator::SetDetector( Int_t det )
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::SetLevel( TString level )
 {
-    TList* tmp = (TList*)fPCurrDetector->FindObject( level.Data() );
+    //Set a new level
+    AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->FindObject( level.Data() );
     if (!tmp) return kFALSE;
     fPCurrLevel = tmp;
-    fPCurrHistName = (TObjString*)fPCurrLevel->First();
+    fPCurrItem = (AliQADirListItem*)GetItemList()->First();
     OpenCurrentDirectory();
     return kTRUE;
 }
@@ -293,47 +276,62 @@ Bool_t AliQAHistNavigator::SetLevel( TString level )
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::SetLevel( Int_t level )
 {
-    TList* tmp = (TList*)fPCurrDetector->At( level );
+    //Set a new level
+    AliQADirList* tmp = (AliQADirList*)fPCurrDetector->GetDirs()->At( level );
     if (!tmp) return kFALSE;
     fPCurrLevel = tmp;
-    fPCurrHistName = (TObjString*)fPCurrLevel->First();
+    fPCurrItem = (AliQADirListItem*)GetItemList()->First();
     OpenCurrentDirectory();
     return kTRUE;
 }
 
 //_________________________________________________________________________
-Bool_t AliQAHistNavigator::SetHist( TString hist )
+Bool_t AliQAHistNavigator::SetItem( TString hist )
 {
-    TObjString* tmp = (TObjString*)fPCurrLevel->FindObject( hist.Data() );
+    //set the new item
+    AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->FindObject( hist.Data() );
     if (!tmp) return kFALSE;
-    fPCurrHistName = tmp;
+    fPCurrItem = tmp;
     return kTRUE;
 }
 
 //_________________________________________________________________________
-Bool_t AliQAHistNavigator::SetHist( Int_t hist )
+Bool_t AliQAHistNavigator::SetItem( Int_t hist )
 {
-    TObjString* tmp = (TObjString*)fPCurrLevel->At( hist );
+    //set the new item
+    AliQADirListItem* tmp = (AliQADirListItem*)GetItemList()->At( hist );
     if (!tmp) return kFALSE;
-    fPCurrHistName = tmp;
+    fPCurrItem = tmp;
     return kTRUE;
 }
 
 //_________________________________________________________________________
-void AliQAHistNavigator::PrintDebugInfo()
+TList* AliQAHistNavigator::GetItemList()
 {
-    if (!fPCurrHistName) {cout<<"no more histograms"<<endl;return;};
-    if (!fPCurrLevel) {cout<<"no more levels"<<endl;return;};
-    if (!fPCurrDetector) {cout<<"no more detectors"<<endl;return;};
-    cout<<"AliQAHistNavigator state information:"<<endl;
-    cout<<"hist: "<<GetHistName()<<endl;
-    cout<<"dir:  "<<GetDirName()<<endl;
-    cout<<"$PWD: ";gDirectory->pwd();cout<<endl;
+    //returns the current list of histograms, if none, returns empty list
+    TList* itemlist=NULL;
+    if (fExpertMode)
+    {
+        AliQADirList* expertlist = (AliQADirList*)fPCurrLevel->GetDirs()->FindObject(fExpertDirName);
+        if (expertlist) itemlist = expertlist->GetItems();
+        else
+        {
+            //this is a bit of a hack, but it will always return something sensible
+            AliQADirListItem* it = (AliQADirListItem*)fPEmptyList->First();
+            it->SetParent(fPCurrLevel);
+            itemlist = fPEmptyList;
+        }
+    } else
+    {
+        itemlist = fPCurrLevel->GetItems();
+    }
+    return itemlist;
 }
 
 //_________________________________________________________________________
 TString AliQAHistNavigator::GetDetectorName()
 {
+    //Get name of current detector
     if (!fPCurrDetector) return "";
     TString name = fPCurrDetector->GetName();
     return name;
@@ -342,6 +340,7 @@ TString AliQAHistNavigator::GetDetectorName()
 //_________________________________________________________________________
 TString AliQAHistNavigator::GetLevelName()
 {
+    //Get name of current leve
     if (!fPCurrLevel) return "";
     TString name = fPCurrLevel->GetName();
     return name;
@@ -350,6 +349,7 @@ TString AliQAHistNavigator::GetLevelName()
 //_________________________________________________________________________
 TString AliQAHistNavigator::GetFileName()
 {
+    //Get name of current file
     if (!fPCurrFile) return "";
     TString file = fPCurrFile->GetName();
     return file;
@@ -358,122 +358,52 @@ TString AliQAHistNavigator::GetFileName()
 //_________________________________________________________________________
 TString AliQAHistNavigator::GetDirName()
 {
-    TString detector = GetDetectorName();
-    TString level = GetLevelName();
-    if (detector==""||level=="") return "";
-    TString dir = "/"+ detector +"/"+ level;
-    return dir;
-}
-
-//_________________________________________________________________________
-TString AliQAHistNavigator::GetHistName()
-{
-    if (!fPCurrHistName) return "";
-    return fPCurrHistName->GetString();
+    //get the name of dir containing current item
+    if (!fPCurrItem) return "";
+    AliQADirList* d=(AliQADirList*)fPCurrItem->GetParent();
+    TString path;
+    do
+    {
+        path = d->GetName() + path;
+        path = "/" + path;
+        d=d->GetParent();
+    }
+    while (d->GetParent());
+    return path;
 }
 
 //_________________________________________________________________________
-Bool_t AliQAHistNavigator::DumpList( TString filename )
+TString AliQAHistNavigator::GetPath(AliQADirListItem* item)
 {
-    ofstream fout(filename);
-    if (fout.bad()) return kFALSE;
-    TString lastlevel="";
-    TString lastdet="";
-    if (!Next()) return kTRUE;
+    //Get the full path to teh directory containing item
+    AliQADirList* d=item->GetParent();
+    TString path = "";//item->GetString();
     do
     {
-        if (GetLevelName()!=lastlevel)
-        {
-            fout<<GetDetectorName()<<"/"<<GetLevelName()<<":"<<endl;
-            lastlevel=GetLevelName();
-        }
-        fout << GetHistName() << endl;
-    } while (Next());
-    fout.close();
-    return kTRUE;
+        TString sep = (d->GetParent()) ? "/" : ":/" ;
+        path = d->GetName() + sep + path;
+    }
+    while (d=d->GetParent());
+    return path;
 }
 
 //_________________________________________________________________________
-Bool_t AliQAHistNavigator::ReadList( TString filename )
+TString AliQAHistNavigator::GetItemName()
 {
-    TString line = filename;
-    //TString level="";
-    //TString lastlevel="";
-    //TString det="";
-    //TString lastdet="";
-    //TRegexp detRegexp("^[a-zA-Z0-9]*");
-    //TRegexp typRegexp("[a-zA-Z0-9]*");
-
-    //ifstream fin(filename);
-    //if (fin.bad()) return kFALSE;
-    //delete fPListOfFiles;
-    //fPListOfFiles = new TList();
-    //TList* pDetector=new TList();
-    //TList* pLevel=new TList();
-    //
-    //line.ReadLine(fin,kFALSE);
-    //if (line=="") return kFALSE;
-    //cout<<"read line: "<<line<<endl;
-    //det = line(detRegexp);
-    //level = line(typRegexp, line.Index("/")+1);
-    //pDetector->SetName(det);
-    //lastdet = det;
-    //pLevel->SetName(level);
-    //lastlevel = level;
-    //pLevel->AddLast(new TObjString("DO NOT REMOVE THIS LINE"));
-    //
-    //while (!fin.eof())
-    //{
-    //    line.ReadLine(fin,kFALSE);
-    //    cout<<"read line: "<<line<<endl;
-    //    if (line.EndsWith(":"))
-    //    {
-    //        det = line(detRegexp);
-    //        level = line(typRegexp, line.Index("/")+1);
-    //        if (det!=lastdet)
-    //        {
-    //            pDetector->AddLast(pLevel);
-    //            fPListOfFiles->AddLast(pDetector);
-    //            pDetector = new TList();
-    //            pDetector->SetName(det);
-    //            cout<<"new detector: "<<det<<endl;
-    //            lastdet = det;
-    //            pLevel = new TList();
-    //            pLevel->SetName(level);
-    //            cout<<"new level: "<<level<<endl;
-    //            lastlevel = level;
-    //            continue;
-    //        }
-    //        if (level!=lastlevel)
-    //        {
-    //            pDetector->AddLast(pLevel);
-    //            pLevel = new TList();
-    //            pLevel->SetName(level);
-    //            cout<<"new level: "<<level<<endl;
-    //            lastlevel = level;
-    //            continue;
-    //        }
-    //    }
-    //    if (line.BeginsWith("//")) continue;
-    //    if (line.BeginsWith("#")) continue;
-    //    pLevel->AddLast(new TObjString(line));        
-    //    cout<<"added line: "<<line<<endl;
-    //}
-    //
-    //fPCurrDetector = (TList*)fPListOfFiles->First();
-    //fPCurrLevel = (TList*) fPCurrDetector->First();
-    //fPCurrHistName = (TObjString*) fPCurrLevel->First();
-    //OpenCurrentFile();
-    //OpenCurrentDirectory();
-    //fPListOfFiles->Print();
-    return kFALSE;
+    //Get name of current item
+    if (!fPCurrItem) return "";
+    return fPCurrItem->GetString();
 }
 
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::GetListOfFiles()
 {
+    //scan directory for QA files
     delete fPListOfFiles;
-    fPListOfFiles = new TList();
+    fPListOfFiles = new AliQADirList();
+
+    TString CORRFileName;
+    TString QAResultFileName;
 
     TString macdir(".");
     gSystem->ExpandPathName(macdir);
@@ -485,23 +415,40 @@ Bool_t AliQAHistNavigator::GetListOfFiles()
         TString runstr = "";
         TString revstr = "";
         runstr += fRun;
-        revstr += fCyc;
         TString reg;
         reg+= ".*QA\\.";
-        reg+= (fRun==0) ? "[0-9].*" : runstr.Data();
-        reg+= "\\.";
         reg+= (fRun==0) ? "[0-9].*" : revstr.Data();
         reg+= "\\.root$";
-        cout<<reg<<endl;
-        TPRegexp re(reg);
+        TPRegexp reHist(reg);
+        TPRegexp reMerged("Merged.QA.Data.[0-9]*.root");
+        TPRegexp reCORR("CORR.QA.[0-9]*.root");
+        TPRegexp reQA("QA.root");
         std::list<string> names;
         while((filename = gSystem->GetDirEntry(dirhandle)) != 0)
         {
-            if(re.Match(filename))
+            if (reCORR.Match(filename))
+            {
+                CORRFileName = filename;
+                continue;
+            }
+            if (reQA.Match(filename))
+            {
+                QAResultFileName = filename;
+                continue;
+            }
+            if (reMerged.Match(filename))
+            {
+                names.clear();
+                names.push_back(filename);
+                break;
+            }
+            if (reHist.Match(filename))
             {
                 names.push_back(filename);
             }
         }
+        if (!fPCORRFile) fPCORRFile = new TFile(CORRFileName,"READ");
+        if (!fPQAResultFile) fPQAResultFile = new TFile(QAResultFileName,"READ");
         if (names.empty())
         {
             printf("GetListOfFiles: no files matching...\n");
@@ -512,9 +459,9 @@ Bool_t AliQAHistNavigator::GetListOfFiles()
         for (std::list<string>::iterator si=names.begin(); si!=names.end(); ++si)
         {
           sprintf(fullName,"%s", si->c_str());
-          TList* f = new TList();
+          AliQADirList* f = new AliQADirList();
           f->SetName(fullName);
-          fPListOfFiles->AddLast(f);
+          fPListOfFiles->GetDirs()->AddLast(f);
         }
     }
     else
@@ -528,14 +475,14 @@ Bool_t AliQAHistNavigator::GetListOfFiles()
 //_________________________________________________________________________
 Bool_t AliQAHistNavigator::CloneDirStructure()
 {
+    //scan all files
     if (!GetListOfFiles()) return kFALSE;
-    if (fPListOfFiles->GetEntries()==0) return kFALSE;
-    TIter fileiter(fPListOfFiles);
-    TList* f;
-    while ((f = (TList*)fileiter.Next()))
+    if (fPListOfFiles->GetDirs()->GetEntries()==0) return kFALSE;
+    TIter fileiter(fPListOfFiles->GetDirs());
+    AliQADirList* f;
+    while ((f = (AliQADirList*)fileiter.Next()))
     {
         TString filename = f->GetName();
-        cout<<filename<<endl;
         TFile file(filename);
         if (!Crawl(f)) continue;
     }
@@ -543,8 +490,11 @@ Bool_t AliQAHistNavigator::CloneDirStructure()
 }
 
 //_________________________________________________________________________
-Bool_t AliQAHistNavigator::Crawl(TList* dir)
+Bool_t AliQAHistNavigator::Crawl(AliQADirList* dir)
 {
+    TString oldkeyname;
+    TString keyname;
+    //scans the current directory and puts result in dir
     TString pwd = gDirectory->GetPath();
     //returns false if dir in file empty
     TList* keys = gDirectory->GetListOfKeys();
@@ -554,13 +504,15 @@ Bool_t AliQAHistNavigator::Crawl(TList* dir)
     TKey* key;
     while ((key = dynamic_cast <TKey* > (keyiter.Next()) ))
     {
+        keyname = key->GetName();
+        if (keyname==oldkeyname) continue; //do not copy cycles
+        oldkeyname = keyname;
         TString classname=key->GetClassName();
         if (!classname) return kFALSE;
         if (classname=="TDirectoryFile")
         {
             gDirectory->cd(key->GetName());
-            gDirectory->pwd();
-            TList* newdir = new TList();
+            AliQADirList* newdir = new AliQADirList();
             if (!Crawl(newdir))
             {
                 gDirectory->cd(pwd);
@@ -568,46 +520,86 @@ Bool_t AliQAHistNavigator::Crawl(TList* dir)
             }
             gDirectory->cd(pwd);
 
-            newdir->SetName(key->GetName());
-            dir->AddLast(newdir);
+            newdir->SetName(keyname);
+            newdir->SetParent(dir);
+            dir->GetDirs()->AddLast(newdir);
         }
         else
         {
-            cout<<key->GetName()<<endl;
-            dir->AddLast(new TObjString(key->GetName()));
+            AliQADirListItem* item = new AliQADirListItem(keyname);
+            item->SetParent(dir);
+            dir->GetItems()->AddLast(item);
         }
     }
     return kTRUE;
 }
 
+//_________________________________________________________________________
 Bool_t AliQAHistNavigator::ReReadFiles()
 {
-    if (CloneDirStructure())
+    //close, open and rescan the files
+    if (!CloneDirStructure())
+    {
+        printf("AliQAHistNavigator::AliQAHistNavigator(): error reading files\n");
+        return kFALSE;
+    }
+    fPCurrFile = (AliQADirList*)fPListOfFiles->GetDirs()->First();
+    if (fPCurrFile)
     {
-        fPCurrFile = (TList*)fPListOfFiles->First();
-        if (fPCurrFile)
+        fPCurrDetector = (AliQADirList*)fPCurrFile->GetDirs()->First();
+        if (fPCurrDetector)
         {
-            fPCurrDetector = (TList*)fPCurrFile->First();
-            if (fPCurrDetector)
+            fPCurrLevel = (AliQADirList*) fPCurrDetector->GetDirs()->First();
+            if (fPCurrLevel)
             {
-                fPCurrLevel = (TList*) fPCurrDetector->First();
-                if (fPCurrLevel)
+                fPCurrItem = (AliQADirListItem*) GetItemList()->First();
+                if (fPCurrItem)
                 {
-                    fPCurrHistName = (TObjString*) fPCurrLevel->First();
-                    if (fPCurrHistName)
-                    {
-                        fInitOK = kTRUE;
-                        OpenCurrentFile();
-                        OpenCurrentDirectory();
-                    }
+                    fInitOK = kTRUE;
+                    OpenCurrentFile();
+                    OpenCurrentDirectory();
                 }
             }
         }
-    } else
-    {
-        printf("AliQAHistNavigator::AliQAHistNavigator(): error reading files\n");
-        return kFALSE;
     }
     return kTRUE;
 }
 
+//_________________________________________________________________________
+ClassImp(AliQADirList)
+//_________________________________________________________________________
+AliQADirList::AliQADirList():
+    TNamed(),
+    fPParent(NULL),
+    fPItems(new TList()),
+    fPDirs(new TList())
+{
+    //ctor
+}
+
+//_________________________________________________________________________
+AliQADirList::~AliQADirList()
+{
+    //dtor
+    if (fPParent) delete fPParent;
+    delete fPItems;
+    delete fPDirs;
+}
+
+//_________________________________________________________________________
+ClassImp(AliQADirListItem)
+//_________________________________________________________________________
+AliQADirListItem::AliQADirListItem(const char* s):
+    TObjString(s),
+    fPParent(NULL)
+{
+    //ctor
+}
+
+//_________________________________________________________________________
+AliQADirListItem::~AliQADirListItem()
+{
+    //dtor
+    if (fPParent) delete fPParent;
+}
+