]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/AliQAHistViewer.cxx
added missing files
[u/mrichter/AliRoot.git] / MONITOR / AliQAHistViewer.cxx
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 //  QA histogram viewer
18 //  scans the current directory fro files with QA
19 //  and plots them.
20 //
21 //  origin: Mikolaj Krzewicki, Nikhef, Mikolaj.Krzewicki@cern.ch
22 //
23 ///////////////////////////////////////////////////////////////////////////
24
25 #include <TApplication.h>
26 #include <TGButton.h>
27 #include <TGFrame.h>
28 #include <TFrame.h>
29 #include <TRootEmbeddedCanvas.h>
30 #include <TGStatusBar.h>
31 #include <TCanvas.h>
32 #include <TH1.h>
33 #include <TF1.h>
34 #include <TString.h>
35 #include <TGComboBox.h>
36 #include <TList.h>
37 #include "AliQAHistNavigator.h"
38 #include "AliQAHistViewer.h"
39
40 ClassImp(AliQAHistViewer)
41
42 //_________________________________________________________________________
43 void AliQAHistViewer::DoDrawNext()
44 {
45    //draw next histogram
46    Int_t rows = 2;
47    Int_t cols = 2;
48    TString oldDirStr;
49    TString newDirStr;
50    oldDirStr = fQANavigator->GetDirName();
51
52    UpdateAllPathComboBoxes();
53
54    TCanvas *c1 = fEcan->GetCanvas();
55    c1->Clear();
56    c1->Divide(rows,cols);
57    for (Int_t i=1; i<=rows*cols;i++)
58    {
59        newDirStr = fQANavigator->GetDirName();
60        if (newDirStr!=oldDirStr)
61        {
62            oldDirStr=newDirStr;
63            break;
64        }
65        c1->cd(i);
66        TH1* hist;
67        if (fQANavigator->GetHistogram(hist))
68        {
69           if (hist) hist->Draw();
70        }
71        if (!fQANavigator->Next())
72        {
73            break;
74        }
75    }
76    c1->cd(0);
77    c1->Update();
78 }
79
80 //_________________________________________________________________________
81 void AliQAHistViewer::DoDrawPrev()
82 {
83    //draw previous histogram
84    Int_t rows = 2;
85    Int_t cols = 2;
86    TString oldDirStr;
87    TString newDirStr;
88    oldDirStr = fQANavigator->GetDirName();
89
90    UpdateAllPathComboBoxes();
91
92    TCanvas *c1 = fEcan->GetCanvas();
93    c1->Clear();
94    c1->Divide(rows,cols);
95    for (Int_t i=1; i<=rows*cols;i++)
96    {
97        newDirStr = fQANavigator->GetDirName();
98        if (newDirStr!=oldDirStr)
99        {
100            oldDirStr=newDirStr;
101            break;
102        }
103        c1->cd(i);
104        TH1* hist;
105        if (fQANavigator->GetHistogram(hist))
106        {
107           if (hist) hist->Draw();
108        }
109        if (!fQANavigator->Prev())
110        {
111            break;
112        }
113    }
114    c1->cd(0);
115    c1->Update();
116 }
117
118 //_________________________________________________________________________
119 void AliQAHistViewer::DoExit()
120 {
121    //exit
122    printf("Exit application...");
123    gApplication->Terminate(0);
124 }
125
126 //_________________________________________________________________________
127 AliQAHistViewer::AliQAHistViewer(const TGWindow *p, UInt_t w, UInt_t h, Bool_t embed) :
128     TGMainFrame(p, w, h),
129     fEcan(NULL),
130     fQANavigator(new AliQAHistNavigator()),
131     fFileListBox(NULL),
132     fDetectorListBox(NULL),
133     fLevelListBox(NULL),
134     fHistListBox(NULL),
135     fExpertMode(NULL),
136     fIsEmbedded(embed)
137 {
138    //initialize the QA navigator
139    // horizontal frame with comboboxes for navigation
140    TGHorizontalFrame *hframenav = new TGHorizontalFrame(this, 200,40);
141    fFileListBox = new TGComboBox(hframenav); 
142    fFileListBox->Connect("Selected(Int_t)", "AliQAHistViewer", this, "DoSetFile(Int_t)");
143    fFileListBox->Resize(150,20);
144    hframenav->AddFrame(fFileListBox, new TGLayoutHints(kLHintsExpandY|kLHintsLeft));
145    fDetectorListBox = new TGComboBox(hframenav);
146    fDetectorListBox->Connect("Selected(Int_t)", "AliQAHistViewer", this, "DoSetDetector(Int_t)");
147    fDetectorListBox->Resize(100,20);
148    hframenav->AddFrame(fDetectorListBox, new TGLayoutHints(kLHintsLeft));
149    fLevelListBox = new TGComboBox(hframenav);
150    fLevelListBox->Connect("Selected(Int_t)", "AliQAHistViewer", this, "DoSetLevel(Int_t)");
151    fLevelListBox->Resize(100,20);
152    hframenav->AddFrame(fLevelListBox, new TGLayoutHints(kLHintsLeft));
153    fHistListBox = new TGComboBox(hframenav);
154    fHistListBox->Connect("Selected(Int_t)", "AliQAHistViewer", this, "DoSetHistogram(Int_t)");
155    fHistListBox->Resize(250,20);
156    hframenav->AddFrame(fHistListBox, new TGLayoutHints(kLHintsLeft));
157    AddFrame(hframenav, new TGLayoutHints((kLHintsLeft|kLHintsExpandX), 5,5,5,5));
158    UpdateAllPathComboBoxes();
159    fExpertMode = new TGCheckButton(hframenav,"Expert");
160    hframenav->AddFrame(fExpertMode,new TGLayoutHints(kLHintsLeft, 0, 4, 3, 0));
161    fExpertMode->SetToolTipText("Show expert histograms");
162    fExpertMode->Connect("Toggled(Bool_t)", "AliQAHistViewer", this, "DoSetExpertMode(Bool_t)");
163    // Create the embedded canvas
164    fEcan = new TRootEmbeddedCanvas(0,this,800,600);
165    Int_t wid = fEcan->GetCanvasWindowId();
166    TCanvas *myc = new TCanvas("MyCanvas", 10,10,wid);
167    fEcan->AdoptCanvas(myc);
168    //myc->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","AliQAHistViewer",this, 
169    //            "EventInfo(Int_t,Int_t,Int_t,TObject*)");
170
171    AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft | 
172                                      kLHintsExpandX  | kLHintsExpandY,0,0,1,1));
173   
174    // Create a horizontal frame containing the buttons
175    TGHorizontalFrame *hframebuttons = new TGHorizontalFrame(this, 200, 40); 
176    TGTextButton *prev = new TGTextButton(hframebuttons, "&Prev");
177    prev->Connect("Clicked()", "AliQAHistViewer", this, "DoDrawPrev()");
178    hframebuttons->AddFrame(prev, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
179    TGTextButton *next = new TGTextButton(hframebuttons, "&Next");
180    next->Connect("Clicked()", "AliQAHistViewer", this, "DoDrawNext()");
181    hframebuttons->AddFrame(next, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
182    AddFrame(hframebuttons, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
183
184    if ((!fIsEmbedded))
185    {
186        TGTextButton *exit = new TGTextButton(hframebuttons, "&Exit ");
187        exit->Connect("Pressed()", "AliQAHistViewer", this, "DoExit()");
188        hframebuttons->AddFrame(exit, new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
189    }
190    
191    // Set a name to the main frame   
192    SetWindowName("Quality Assurance Monitoring");
193    MapSubwindows();
194
195    // Initialize the layout algorithm via Resize()
196    Resize(GetDefaultSize());
197
198    // Map main frame
199    MapWindow();
200    DoDrawNext();
201 }
202
203 //_________________________________________________________________________
204 AliQAHistViewer::~AliQAHistViewer()
205 {
206    // Clean up main frame...
207    Cleanup();
208    //delete fEcan;
209    delete fQANavigator;
210 }
211
212 //_________________________________________________________________________
213 void AliQAHistViewer::FillComboBoxWithListEntries( TGComboBox* box, const TList* list )
214 {
215     //fill the combobox with list entries
216     box->RemoveAll();
217     Int_t i=0;
218     TIter listiter(list);
219     TObject* o = NULL;
220     while ((o = (TObject*)listiter.Next()))
221     {
222         TString name = o->GetName();
223         box->AddEntry( name.Data(), i++ );
224     }
225 }
226
227 //_________________________________________________________________________
228 void AliQAHistViewer::UpdateAllPathComboBoxes()
229 {
230     //make gui elements up to date
231     if (!fQANavigator->InitOK()) return;
232     FillComboBoxWithListEntries( fFileListBox, (TList*)fQANavigator->GetFileList()->GetDirs() );
233     FillComboBoxWithListEntries( fDetectorListBox, (TList*)fQANavigator->GetDetectorList()->GetDirs() );
234     FillComboBoxWithListEntries( fLevelListBox, (TList*)fQANavigator->GetLevelList()->GetDirs() );
235     FillComboBoxWithListEntries( fHistListBox, (TList*)fQANavigator->GetItemList() );
236     fFileListBox->Select(fQANavigator->GetCurrListOfFiles()->GetDirs()->IndexOf(fQANavigator->GetCurrFile()),kFALSE);
237     fDetectorListBox->Select(fQANavigator->GetCurrFile()->GetDirs()->IndexOf(fQANavigator->GetCurrDetector()),kFALSE);
238     fLevelListBox->Select(fQANavigator->GetCurrDetector()->GetDirs()->IndexOf(fQANavigator->GetCurrLevel()),kFALSE);
239     fHistListBox->Select(fQANavigator->GetItemList()->IndexOf(fQANavigator->GetCurrItem()),kFALSE);
240 }
241
242 //_________________________________________________________________________
243 void AliQAHistViewer::DoSetFile( Int_t s )
244 {
245     //set file from user choice
246     fQANavigator->SetFile(s);
247     DoDrawNext();
248 }
249
250 //_________________________________________________________________________
251 void AliQAHistViewer::DoSetDetector( Int_t s )
252 {
253     //set detector number from user choice
254     fQANavigator->SetDetector(s);
255     DoDrawNext();
256 }
257
258 //_________________________________________________________________________
259 void AliQAHistViewer::DoSetLevel( Int_t s )
260 {
261     //set QA level
262     fQANavigator->SetLevel(s);
263     DoDrawNext();
264 }
265
266 //_________________________________________________________________________
267 void AliQAHistViewer::DoSetHistogram( Int_t s )
268 {
269     //set histogram
270     fQANavigator->SetItem(s);
271     DoDrawNext();
272 }
273
274 //_________________________________________________________________________
275 void AliQAHistViewer::DoSetExpertMode(Bool_t mode)
276 {
277     //set expert mode
278     fQANavigator->SetExpertMode(mode);
279     DoDrawNext();
280 }