Coverity fix
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibViewerGUI.cxx
CommitLineData
9bf458e3 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/* $Id: AliTRDCalibViewerGUI.cxx 40390 2010-04-14 09:43:23Z cblume $ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// GUI for the AliTRDCalibViewerGUI //
21// used for the calibration monitor //
22// All functionalities of the AliTRDCalibViewer are here available //
23// //
24// Authors: Marian Ivanov (Marian.Ivanov@cern.ch) //
25// Jens Wiechula (Jens.Wiechula@cern.ch) //
26// Ionut Arsene (iarsene@cern.ch) //
27// //
28// Example usage: //
29/*
30 aliroot
31 AliTRDCalibViewerGUI::ShowGUI()
32
33*/
34// //
35// //
36///////////////////////////////////////////////////////////////////////////////
37
38
39#include "AliTRDCalibViewerGUI.h"
40#include <iostream>
41#include <string.h>
42
43#include <TCanvas.h>
44#include <TPad.h>
45#include <TVirtualPad.h>
46
47#include <TROOT.h>
48#include <TObjArray.h>
49#include <TObjString.h>
50#include <TVector.h>
51#include <TH1.h>
52#include <TMath.h>
53#include <TStyle.h>
54#include <TGFileDialog.h>
55#include <TGInputDialog.h>
56#include "AliBaseCalibViewer.h"
57#include "AliCalibViewerGUItime.h"
58#include "AliTRDCalibViewer.h"
59#include "AliCDBManager.h"
60#include "AliCDBStorage.h"
61
62ClassImp(AliTRDCalibViewerGUI)
63
64//________________________________________________________________________________________________
65AliTRDCalibViewerGUI::AliTRDCalibViewerGUI(const TGWindow *p, UInt_t w, UInt_t h, char* fileName)
66: AliBaseCalibViewerGUI(p, w, h),
67 fContLayer(0),
68 fContSector(0),
69 fContStack(0),
70 fLblLayer(0),
71 fLblSector(0),
72 fLblStack(0),
73 fNmbLayer(0),
74 fNmbSector(0),
75 fNmbStack(0),
76 fContLoad(0),
77 fContRun(0),
78 fLblRun(0),
79 fNmbRun(0),
80 fContStorage(0),
81 fLblStorage(0),
82 fTxtStorage(0),
83 fContVersion(0),
84 fLblVersion(0),
85 fNmbVersion(0),
86 fContSubVersion(0),
87 fLblSubVersion(0),
88 fNmbSubVersion(0),
89 fContChecks(0),
90 fChkCalibs(0),
91 fChkDCS(0),
92 fChkAlign(0),
93 fBtnLoad(0),
94 fContLoadCalibObjects(0),
95 fContCalibInput(0),
96 fLblCalibInputFilename(0),
97 fTxtCalibInputFilename(0),
98 fContCalibOutput(0),
99 fLblCalibOutputFilename(0),
100 fTxtCalibOutputFilename(0),
101 fBtnLoadCalibObjects(0)
102{
103 //
104 // AliTRDCalibViewerGUI constructor; fileName specifies the ROOT tree used for drawing
105 //
106 // draw the GUI:
107 DrawGUI(p, w, h);
108 // initialize
109 if (fileName) Initialize(fileName, "TRDcalibDetails");
110 // set default button states:
111 SetInitialValues();
112 // do first drawing:
113 if (fileName) DoDraw();
114}
115
116//________________________________________________________________________________________________
117AliTRDCalibViewerGUI::AliTRDCalibViewerGUI(const AliTRDCalibViewerGUI &c)
118 :AliBaseCalibViewerGUI(c),
119 fContLayer(0),
120 fContSector(0),
121 fContStack(0),
122 fLblLayer(0),
123 fLblSector(0),
124 fLblStack(0),
125 fNmbLayer(0),
126 fNmbSector(0),
127 fNmbStack(0),
128 fContLoad(0),
129 fContRun(0),
130 fLblRun(0),
131 fNmbRun(0),
132 fContStorage(0),
133 fLblStorage(0),
134 fTxtStorage(0),
135 fContVersion(0),
136 fLblVersion(0),
137 fNmbVersion(0),
138 fContSubVersion(0),
139 fLblSubVersion(0),
140 fNmbSubVersion(0),
141 fContChecks(0),
142 fChkCalibs(0),
143 fChkDCS(0),
144 fChkAlign(0),
145 fBtnLoad(0),
146 fContLoadCalibObjects(0),
147 fContCalibInput(0),
148 fLblCalibInputFilename(0),
149 fTxtCalibInputFilename(0),
150 fContCalibOutput(0),
151 fLblCalibOutputFilename(0),
152 fTxtCalibOutputFilename(0),
153 fBtnLoadCalibObjects(0)
154{
155 //
156 // dummy AliTPCCalibViewerGUI_new copy constructor
157 //
158}
159
160//________________________________________________________________________________________________
161AliTRDCalibViewerGUI & AliTRDCalibViewerGUI::operator =(const AliTRDCalibViewerGUI & /*param*/) {
162 //
163 // dummy assignment operator
164 //
165 return (*this);
166}
167
168//________________________________________________________________________________________________
169AliTRDCalibViewerGUI::~AliTRDCalibViewerGUI() {
170 //
171 // Destructor
172 //
173 /*
174 if (fCanvMain && fCanvMain->GetCanvas()) {
175 for (Int_t i = 0; i < fCanvMain->GetCanvas()->GetListOfPrimitives()->GetEntries(); i++) {
176 if (strcmp(fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->ClassName(), "TFrame") != 0)
177 fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->Delete();
178 }
179 } */
180 Cleanup();
181 if (fViewer) fViewer->Delete();
182}
183
184//________________________________________________________________________________________________
9cc39f20 185Bool_t AliTRDCalibViewerGUI::CreateDetailsTree(Int_t run, const Char_t* outFile, const Char_t* /*ocdbStorage*/) {
9bf458e3 186 //
187 // Get pad level info from OCDB for a given run and dump it into a tree
188 //
9bf458e3 189 if(!AliCDBManager::Instance()->GetDefaultStorage()){
190 std::cout << "AliTRDCalibViewerGUI::CreateDetailsTree(): Default Storage not set. Cannot create Calibration Tree!" << std::endl;
191 return kFALSE;
192 }
193 TString storage = AliCDBManager::Instance()->GetDefaultStorage()->GetURI();
194 return ((AliTRDCalibViewer*)fViewer)->DumpOCDBtoTreeDetails("", outFile, run, run, storage.Data());
195}
196
197//________________________________________________________________________________________________
198void AliTRDCalibViewerGUI::DrawGUI(const TGWindow *p, UInt_t w, UInt_t h) {
199 //
200 // draw the GUI
201 //
202
203 // draw most of the GUI (all common stuff)
204 AliBaseCalibViewerGUI::DrawGUI(p, w, h);
205
206 // remove some frames from the virtual class
207 fTabRight1->RemoveFrame(fContExport);
208 fTabRight1->RemoveFrame(fContTree);
209 fTabRight1->RemoveFrame(fContFit);
210
211 // draw and connect slots specific to TRD
212 // **************************** content of tabLeft0 *******************************
213 // layer options container
214 fContLayer = new TGCompositeFrame(fContCuts, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
215 fContCuts->AddFrame(fContLayer, new TGLayoutHints(kLHintsExpandX, 5, 0, 0, 0));
216
217 // layer number label
218 fLblLayer = new TGLabel(fContLayer, "Layer");
219 fLblLayer->SetTextJustify(kTextLeft);
220 fContLayer->AddFrame(fLblLayer, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 0, 0, 0));
221 // layer number entry
222 fNmbLayer = new TGNumberEntry(fContLayer, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, 0, 5);
223 fContLayer->AddFrame(fNmbLayer, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
224 fNmbLayer->SetNumber(0);
225 fNmbLayer->Connect("ValueSet(Long_t)", "AliTRDCalibViewerGUI", this, "DoNewSelection()");
226
227 // sector options container
228 fContSector = new TGCompositeFrame(fContCuts, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
229 fContCuts->AddFrame(fContSector, new TGLayoutHints(kLHintsExpandX, 5, 0, 0, 0));
230
231 // sector number label
232 fLblSector = new TGLabel(fContSector, "SM");
233 fLblSector->SetTextJustify(kTextLeft);
234 fContSector->AddFrame(fLblSector, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 0, 0, 0));
235 // sector number entry
236 fNmbSector = new TGNumberEntry(fContSector, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -1, 17);
237 fContSector->AddFrame(fNmbSector, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
238 fNmbSector->SetNumber(-1);
239 fNmbSector->Connect("ValueSet(Long_t)", "AliTRDCalibViewerGUI", this, "DoNewSelection()");
240
241 // stack options container
242 fContStack = new TGCompositeFrame(fContCuts, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
243 fContCuts->AddFrame(fContStack, new TGLayoutHints(kLHintsExpandX, 5, 0, 0, 0));
244
245 // stack number label
246 fLblStack = new TGLabel(fContStack, "Stack");
247 fLblStack->SetTextJustify(kTextLeft);
248 fContStack->AddFrame(fLblStack, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 0, 0, 0));
249 // stack number entry
250 fNmbStack = new TGNumberEntry(fContStack, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -1, 4);
251 fContStack->AddFrame(fNmbStack, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
252 fNmbStack->SetNumber(-1);
253 fNmbStack->Connect("ValueSet(Long_t)", "AliTRDCalibViewerGUI", this, "DoNewSelection()");
254
255 // Load run frame
256 fContLoad = new TGGroupFrame(fTabRight1, "Load run", kVerticalFrame | kFitWidth | kFitHeight);
257 fTabRight1->AddFrame(fContLoad, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
258 // Storage
259 fContStorage = new TGCompositeFrame(fContLoad, 400, 200, kHorizontalFrame | kFitWidth | kFitHeight);
260 fContLoad->AddFrame(fContStorage, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
261 // label
262 fLblStorage = new TGLabel(fContStorage, "OCDB:");
263 fLblStorage->SetTextJustify(kTextLeft);
264 fContStorage->AddFrame(fLblStorage, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
265 // text entry
266 fTxtStorage = new TGTextEntry(fContStorage, "alien://folder=/alice/data/2010/OCDB/", 111);
267 fContStorage->AddFrame(fTxtStorage, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
268// fTxtStorage->Connect("ReturnPressed()", "AliBaseCalibViewerGUI", this, "HandleButtons1D(=111)");
269 fTxtStorage->SetToolTipText("Enter the OCDB storage location");
270 // Run entry
271 fContRun = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
272 fContLoad->AddFrame(fContRun, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
273 // label
274 fLblRun = new TGLabel(fContRun, "Run:");
275 fLblRun->SetTextJustify(kTextLeft);
276 fContRun->AddFrame(fLblRun, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
277 // run number entry
278 fNmbRun = new TGNumberEntry(fContRun, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELNoLimits);
279 fContRun->AddFrame(fNmbRun, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
280 fNmbRun->SetNumber(-1);
281 //fNmbRun->SetToolTipText("Enter the run number");
282 // Version entry
283 fContVersion = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
284 fContLoad->AddFrame(fContVersion, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
285 // label
286 fLblVersion = new TGLabel(fContVersion, "Version:");
287 fLblVersion->SetTextJustify(kTextLeft);
288 fContVersion->AddFrame(fLblVersion, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
289 // run number entry
290 fNmbVersion = new TGNumberEntry(fContVersion, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELNoLimits);
291 fContVersion->AddFrame(fNmbVersion, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
292 fNmbVersion->SetNumber(-1);
293 // SubVersion entry
294 fContSubVersion = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
295 fContLoad->AddFrame(fContSubVersion, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
296 // label
297 fLblSubVersion = new TGLabel(fContSubVersion, "SubVersion:");
298 fLblSubVersion->SetTextJustify(kTextLeft);
299 fContSubVersion->AddFrame(fLblSubVersion, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
300 // run number entry
301 fNmbSubVersion = new TGNumberEntry(fContSubVersion, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELNoLimits);
302 fContSubVersion->AddFrame(fNmbSubVersion, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
303 fNmbSubVersion->SetNumber(-1);
304
305 // Calib & DCS & Align check boxes frame
306 fContChecks = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
307 fContLoad->AddFrame(fContChecks, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
308 // Calibs check box
309 fChkCalibs = new TGCheckButton(fContChecks, "Calib");
310 fContChecks->AddFrame(fChkCalibs, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
311 fChkCalibs->SetToolTipText("Get calibration info (gain, pedestal, vdrift, T0 and status)");
312 fChkCalibs->SetState(kButtonDown);
313 // DCS check box
314 fChkDCS = new TGCheckButton(fContChecks, "DCS");
315 fContChecks->AddFrame(fChkDCS, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
316 fChkDCS->SetToolTipText("Get DCS info");
317 fChkDCS->SetState(kButtonDown);
318 // Calibs check box
319 fChkAlign = new TGCheckButton(fContChecks, "Align");
320 fContChecks->AddFrame(fChkAlign, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
321 fChkAlign->SetToolTipText("Get alingment info");
322 fChkAlign->SetState(kButtonDown);
323 // Load button
324 fBtnLoad = new TGTextButton(fContLoad, "&Load run");
325 fBtnLoad->SetName("loadOCDB");
326 fContLoad->AddFrame(fBtnLoad, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
327 fBtnLoad->SetToolTipText("Load run from OCDB");
328 fBtnLoad->Connect("Clicked()", "AliTRDCalibViewerGUI", this, "SetTree()");
329
330 // Load a file with AliTRDCalPad objects
331 // main frame
332 fContLoadCalibObjects = new TGGroupFrame(fTabRight1, "Load CalPad from file", kVerticalFrame | kFitWidth | kFitHeight);
333 fTabRight1->AddFrame(fContLoadCalibObjects, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
334 // container for the input file
335 fContCalibInput = new TGCompositeFrame(fContLoadCalibObjects, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
336 fContLoadCalibObjects->AddFrame(fContCalibInput, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
337 // label
338 fLblCalibInputFilename = new TGLabel(fContCalibInput, "Input:");
339 fLblCalibInputFilename->SetTextJustify(kTextLeft);
340 fContCalibInput->AddFrame(fLblCalibInputFilename, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
341 // text entry
342 fTxtCalibInputFilename = new TGTextEntry(fContCalibInput, "Input file", 200);
343 fContCalibInput->AddFrame(fTxtCalibInputFilename, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
344 fTxtCalibInputFilename->Connect("DoubleClicked()", "AliTRDCalibViewerGUI", this, "HandleFilesystem()");
345 // container for the output file
346 fContCalibOutput = new TGCompositeFrame(fContLoadCalibObjects, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
347 fContLoadCalibObjects->AddFrame(fContCalibOutput, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
348 // label
349 fLblCalibOutputFilename = new TGLabel(fContCalibOutput, "Output:");
350 fLblCalibOutputFilename->SetTextJustify(kTextLeft);
351 fContCalibOutput->AddFrame(fLblCalibOutputFilename, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
352 // text entry
353 fTxtCalibOutputFilename = new TGTextEntry(fContCalibOutput, "/tmp/output.root", 201);
354 fContCalibOutput->AddFrame(fTxtCalibOutputFilename, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
355 fTxtCalibOutputFilename->Connect("DoubleClicked()", "AliTRDCalibViewerGUI", this, "HandleFilesystem()");
356 // Load button
357 fBtnLoadCalibObjects = new TGTextButton(fContLoadCalibObjects, "L&oad calib");
358 fBtnLoadCalibObjects->SetName("loadCalPad");
359 fContLoadCalibObjects->AddFrame(fBtnLoadCalibObjects, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
360 fBtnLoadCalibObjects->SetToolTipText("Extract a tree from an array of AliTRDCalPad objects,\nand load it into this application");
361 fBtnLoadCalibObjects->Connect("Clicked()", "AliTRDCalibViewerGUI", this, "SetTree()");
362
363 SetWindowName("AliTRDCalibViewer GUI");
364 MapSubwindows();
365 Resize(GetDefaultSize());
366 MapWindow();
367}
368
369//___________________________________________________________________________________
370void AliTRDCalibViewerGUI::SetTree() {
371 //
372 // handles the loading of a new tree and updates the GUI
373 //
374 TString fileName;
375 TGTextButton *button = ((TGTextButton*)gTQSender);
376 TString name=button->GetName();
377 if(name.Contains("OCDB")) {
378 Int_t run = (Int_t)fNmbRun->GetNumber();
379 TString storage(fTxtStorage->GetText());
380 Bool_t getCalibs = (fChkCalibs->GetState()==kButtonDown ? kTRUE : kFALSE);
381 Bool_t getDCS = (fChkDCS->GetState()==kButtonDown ? kTRUE : kFALSE);
382 Bool_t getAlign = (fChkAlign->GetState()==kButtonDown ? kTRUE : kFALSE);
383 Int_t version = (Int_t)fNmbVersion->GetNumber();
384 Int_t subVersion = (Int_t)fNmbSubVersion->GetNumber();
385
386 fileName = Form("trdOCDBDetails_run%d.root", run);
387 Bool_t load=kTRUE;
388 load=((AliTRDCalibViewer*)fViewer)->DumpOCDBtoTreeDetails("", fileName.Data(), run, run, storage.Data(),
389 version, subVersion, getCalibs, getDCS, getAlign);
390 if(!load) {
391 Reset();
392 return;
393 }
394 }
395 if(name.Contains("CalPad")) {
396 ((AliTRDCalibViewer*)fViewer)->DumpCalibToTree(fTxtCalibInputFilename->GetText(),
397 fTxtCalibOutputFilename->GetText());
398 fileName = fTxtCalibOutputFilename->GetText();
399 }
400 Initialize(fileName.Data(), "TRDcalibDetails");
401 Reload();
402 DoDraw();
403}
404
405//________________________________________________________________________________________________
406void AliTRDCalibViewerGUI::HandleFilesystem() {
407 //
408 // Slot used by the text buttons to trigger the file system dialog
409 //
410 Int_t id = ((TGTextEntry*)gTQSender)->WidgetId();
411 const char *kTypes[] = {
412 "All files", "*",
413 0, 0};
414 TString dir(".");
415 TGFileInfo fi;
416 fi.fFileTypes = kTypes;
417 fi.fOverwrite = kFALSE;
418 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
419 if(fi.fFilename && strlen(fi.fFilename)) {
420 if(id==200)
421 fTxtCalibInputFilename->SetText(fi.fFilename);
422 if(id==201)
423 fTxtCalibOutputFilename->SetText(fi.fFilename);
424 }
425 return;
426}
427
428//________________________________________________________________________________________________
429void AliTRDCalibViewerGUI::Initialize(const char* fileName, const char* treeName) {
430 //
431 // initialize the GUI with a calibrationTree from fileName
432 //
433 // create AliTRDCalibViewer object, which will be used for generating all drawings
434 if (fViewer) delete fViewer;
435 fViewer = new AliTRDCalibViewer(fileName, treeName);
436 Initialize(fViewer);
437}
438
439//________________________________________________________________________________________________
440void AliTRDCalibViewerGUI::Initialize(AliBaseCalibViewer *viewer) {
441 //
442 // initializes the GUI with default settings and opens tree for drawing
443 //
444 fViewer = viewer;
445 TString selectedVariable("");
446 TString selectedNormalization("");
447 Int_t variableId = -1;
448 Int_t normalizationId = -1;
449 if (fInitialized) {
450 // remember the selected entry
451 if (fListVariables->GetSelectedEntry()) selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
452 if (fListNormalization->GetSelectedEntry()) selectedNormalization = fListNormalization->GetSelectedEntry()->GetTitle();
453 }
454
455 // fill fListVariables, list of drawable variables:
456 TObjArray* arr = ((AliTRDCalibViewer*)fViewer)->GetListOfVariables(1);
457 if (!arr) {
458 return;
459 }
460 TIterator* iter = arr->MakeIterator();
461 iter->Reset();
462 TObjString* currentStr = 0;
463 Int_t id = 0;
464 fListVariables->RemoveAll();
465 while ((currentStr = (TObjString*)(iter->Next()))) {
466 fListVariables->AddEntry(currentStr->GetString().Data(), id);
467 if (fInitialized && currentStr->GetString() == selectedVariable) variableId = id;
468 id++;
469 }
470
471 // fill fListNorm, list of normalization variables:
472 TObjArray *arrNorm = ((AliTRDCalibViewer*)fViewer)->GetListOfNormalizationVariables();
473 TIterator *iterNorm = arrNorm->MakeIterator();
474 iterNorm->Reset();
475 currentStr = 0;
476 id = 0;
477 fListNormalization->RemoveAll();
478 while ((currentStr = (TObjString*)(iterNorm->Next()))) {
479 fListNormalization->AddEntry(currentStr->GetString().Data(), id);
480 if (fInitialized && currentStr->GetString() == selectedNormalization) normalizationId = id;
481 id++;
482 }
483 currentStr = 0;
484 iter->Reset();
485 //Add draw variables to the list of normalisation
486 while ((currentStr = (TObjString*)(iter->Next()))) {
487 if (currentStr->GetString().BeginsWith("Map")) continue; //don't add mapping information
488 fListNormalization->AddEntry(currentStr->GetString().Data(), id);
489 if (fInitialized && currentStr->GetString() == selectedNormalization) normalizationId = id;
490 id++;
491 }
492
493 delete iterNorm;
494 arrNorm->Delete();
495 delete arrNorm;
496
497 delete iter;
498 arr->Delete();
499 delete arr;
500
501 // trick do display the entries corectly after reinitialization
502 // otherwise all the entries would appear as one kryptic entry
503 // resizing the listbox somehow fixes the problem...
504 if (fInitialized) fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
505 if (fInitialized) fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
506 if (fInitialized) fListNormalization->Resize(fListNormalization->GetWidth()-1, fListNormalization->GetHeight());
507 if (fInitialized) fListNormalization->Resize(fListNormalization->GetWidth()+1, fListNormalization->GetHeight());
508
509 // select the last selected variable and normalization
510 if (fInitialized && variableId != -1) fListVariables->Select(variableId);
511 if (fInitialized && normalizationId != -1)fListVariables->Select(normalizationId);
512
513 if (fInitialized) Info("Initialize", "AliTRDCalibViewerGUI new initialized.");
514 fInitialized = kTRUE;
515}
516
517//________________________________________________________________________________________________
518void AliTRDCalibViewerGUI::Reset(){
519 //
520 // reset variables, delete calib viewer
521 //
522 if (fViewer) delete fViewer;
523 fListVariables->RemoveAll();
524 fListNormalization->RemoveAll();
525 fInitialized = kFALSE;
526}
527
528//________________________________________________________________________________________________
529TString* AliTRDCalibViewerGUI::GetDrawString() {
530 //
531 // create the draw string out of selection
532 //
533
534 // specify data to plot
535 TString desiredData("");
536 if (!fListVariables->GetSelectedEntry()) return 0;
537 desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
538 desiredData += fViewer->GetAbbreviation();
539
540 // specify normalization
541 if (fRadioPredefined->GetState() == kButtonDown && fRadioNormalized->GetState() == kButtonDown) {
542 TString op("");
543 switch (fComboMethod->GetSelected()) {
544 case 0: // subtraction
545 op += "-";
546 break;
547 case 1: // division
548 op += "/";
549 break;
550 }
551 TString normalizationData("");
552 if (!fListNormalization->GetSelectedEntry()) return 0;
553 normalizationData += ((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle();
554
555 desiredData += op;
556 if (! (TString(((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle())).BeginsWith("Fit"))
557 if ( normalizationData.BeginsWith("_") ) desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
558 if ( fListVariables->FindEntry(normalizationData.Data()) )
559 normalizationData+="~";
560 desiredData += normalizationData;
561 }
562 else if (fRadioCustom->GetState() == kButtonDown) {
563 desiredData = fComboCustom->GetTextEntry()->GetText();
564 if (desiredData == "") return 0;
565 ReplacePlaceHolders(desiredData);
566 }
567
568 // try to add forgotten '~'
569 if (fChkAutoAppend->GetState() == kButtonDown)
570 desiredData = TString(((AliTRDCalibViewer*)fViewer)->AddAbbreviations((char*)desiredData.Data()));
571 return new TString(desiredData.Data());
572}
573
574//________________________________________________________________________________________________
575TString* AliTRDCalibViewerGUI::GetCutString() {
576 //
577 // create the cut string out of selection
578 //
579
580 TString cutsStr("");
581
582 // try to add forgotten '~'
583 if(fChkAutoAppend->GetState() == kButtonDown)
584 cutsStr = TString(((AliTRDCalibViewer*)fViewer)->AddAbbreviations((char*)cutsStr.Data()));
585 return new TString(cutsStr.Data());
586}
587
588//________________________________________________________________________________________________
589TString* AliTRDCalibViewerGUI::GetSectorString() {
590 //
591 // create the sector string out of selection
592 //
593
594 Int_t layerNo = (Int_t)(fNmbLayer->GetNumber());
595 Int_t sectorNo = (Int_t)(fNmbSector->GetNumber());
596 Int_t stackNo = (Int_t)(fNmbStack->GetNumber());
597
598 TString sectorStr("");
599 sectorStr = Form("Layer%dSector%dStack%d", layerNo, sectorNo, stackNo);
600
601 return new TString(sectorStr.Data());
602}
603
604//________________________________________________________________________________________________
605void AliTRDCalibViewerGUI::DoDraw() {
606 //
607 // main method for drawing according to user selection
608 //
609
610 // specify data to plot:
611 if (!GetDrawString()) return;
612 TString desiredData(GetDrawString()->Data());
613 // specify sector:
614 TString sectorStr(GetSectorString()->Data());
615 // specify cuts:
616 TString cutsStr(GetCutString()->Data());
617
618 TString addDrawOpt("");
619 if (fChkAddDrawOpt->GetState() == kButtonDown)
620 addDrawOpt += fComboAddDrawOpt->GetTextEntry()->GetText();
621
622 // remove last picture
623 if (!addDrawOpt.Contains("same"))
624 for (Int_t i = 0; i < fCanvMain->GetCanvas()->GetListOfPrimitives()->GetEntries(); i++) {
625 if (strcmp(fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->ClassName(), "TFrame") != 0)
626 fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->Delete();
627 }
628 //fCanvMain->GetCanvas()->Clear();
629 fCanvMain->GetCanvas()->cd();
630 Int_t entries = -1;
631 // draw finally
632 if (fRadio1D->GetState() == kButtonDown){
633 // 1D-Drawing
634 TString strSigmaMax(fTxtSigmaMax->GetText()); // get sigmaMax from text enty
635 Double_t sigmaMax = (strSigmaMax.IsFloat()) ? strSigmaMax.Atof() : 5; // convert to double, if not convertable, set to 5
636 Bool_t plotMean = fChkMean->GetState() == kButtonDown;
637 Bool_t plotMedian = fChkMedian->GetState() == kButtonDown;
638 Bool_t plotLTM = fChkLTM->GetState() == kButtonDown;
639 if (fRadioNorm->GetState() == kButtonDown) // normal 1D drawing
640 entries = ((AliTRDCalibViewer*)fViewer)->EasyDraw1D(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), addDrawOpt.Data());
641 if (fRadioSigma->GetState() == kButtonDown) // sigma 1D drawing
642 entries = fViewer->DrawHisto1D(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
643 fTxtSigmas->GetText(), plotMean, plotMedian, plotLTM);
644 if (fRadioCumulative->GetState() == kButtonDown) // cumulative 1D drawing
645 entries = fViewer->SigmaCut(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
646 sigmaMax, plotMean, plotMedian, plotLTM, //
647 fCheckCumulativePM->GetState() == kButtonDown, fTxtSigmas->GetText(), /* Float_t sigmaStep =*/ -1);
648 if (fRadioIntegrate->GetState() == kButtonDown) // integral 1D drawing
649 entries = fViewer->Integrate(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
650 sigmaMax, plotMean, plotMedian, plotLTM, //
651 fTxtSigmas->GetText(), /* Float_t sigmaStep =*/ -1);
652 }
653 else if (fRadio2D->GetState() == kButtonDown) {
654 // 2D-Drawing
655 entries = ((AliTRDCalibViewer*)fViewer)->EasyDraw(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), addDrawOpt.Data());
656 }
657 if (entries == -1) return; // nothing was drawn, there is no histogram to get min and max
658
659 SetMinMaxLabel();
660 fCanvMain->GetCanvas()->Update();
661}
662
663//________________________________________________________________________________________________
664void AliTRDCalibViewerGUI::MouseMove(Int_t event, Int_t x, Int_t y, TObject *selectedObject) {
665 //
666 // mouse move
667 // zoom to chamber works ONLY in 2D mode
668 //
669 if(event != kButton1Double )
670 return;
671 if(!selectedObject->InheritsFrom("TH2")) return;
672
fc2125de 673 //Int_t layerNo = (Int_t)(fNmbLayer->GetNumber());
9bf458e3 674 Int_t sectorNo = (Int_t)(fNmbSector->GetNumber());
675 Int_t stackNo = (Int_t)(fNmbStack->GetNumber());
676
677 // zoom out to the current layer if a chamber is viewed now
678 if(sectorNo!=-1 && stackNo!=-1) {
679 fNmbSector->SetNumber(-1);
680 fNmbStack->SetNumber(-1);
681 DoNewSelection();
682 return;
683 }
684
685 // check what kind of parameter we visualize
686 TString drawStr(GetDrawString()->Data());
687 Int_t viewedParamClass = -1; // -1 nothing, 0 calibration, 1 FEE params
688 if(drawStr.Contains("Status") || drawStr.Contains("Gain") || drawStr.Contains("Noise") ||
689 drawStr.Contains("Vdrift") || drawStr.Contains("T0") ||
690 drawStr.Contains("gain") || drawStr.Contains("chiSquare"))
691 viewedParamClass = 0;
692 if(drawStr.Contains("SORandEOR") ||
693 drawStr.Contains("gsmSOR") || drawStr.Contains("gsmDelta") ||
694 drawStr.Contains("nimSOR") || drawStr.Contains("nimDelta") ||
695 drawStr.Contains("nevSOR") || drawStr.Contains("nevDelta") ||
696 drawStr.Contains("nptSOR") || drawStr.Contains("nptDelta")) {
697 viewedParamClass = 1;
698 }
699 if(viewedParamClass==-1) return;
700
701 // some constants refering to the TRD geometry
702 const Int_t gkNRows[ 5] = {16, 16, 12, 16, 16}; // number of pad rows in the chambers from each of the 5 stacks
703 const Int_t gkNCols = 144; // number of pad cols per chamber
704
705 // get the coordinate of the clicked point in physical coordinates
706 Float_t upy = gPad->AbsPixeltoY(y);
707 Float_t upx = gPad->AbsPixeltoX(x);
708 Float_t gy = gPad->PadtoY(upy);
709 Float_t gx = gPad->PadtoX(upx);
710 Int_t selectedStack = -1;
711 Int_t selectedSector = -1;
712
713 // retrieve the double-clicked chamber
714 if(sectorNo==-1 && stackNo==-1) {
715 // get the selected stack
716 Float_t rowLowBound = -0.5;
717 Float_t rowHighBound = -0.5;
718 for(Int_t i=0; i<5; i++) {
719 if(i>0) rowLowBound += gkNRows[i-1];
720 rowHighBound += gkNRows[i];
721 if(gx>=rowLowBound && gx<=rowHighBound)
722 selectedStack = i;
723 }
724 // get the selected sector
725 if(viewedParamClass==0) { // calibration params
726 selectedSector = (Int_t)TMath::Floor((gy+0.5)/Float_t(gkNCols));
727 }
728 if(viewedParamClass==1) { // FEE params
729 selectedSector = (Int_t)TMath::Floor((gy+0.5)/8.0); // 8 MCMs per chamber in pad cols direction
730 }
731 }
732 if(sectorNo!=-1 && stackNo==-1) {
733 // get the selected stack
734 Float_t rowLowBound = -0.5;
735 Float_t rowHighBound = -0.5;
736 for(Int_t i=0; i<5; i++) {
737 if(i>0) rowLowBound += gkNRows[i-1];
738 rowHighBound += gkNRows[i];
739 if(gx>=rowLowBound && gx<=rowHighBound)
740 selectedStack = i;
741 }
742 // get the selected sector
743 selectedSector = sectorNo;
744 }
745 if(sectorNo==-1 && stackNo!=-1) {
746 // get the selected stack
747 selectedStack = stackNo;
748 // get the selected sector
749 if(viewedParamClass==0) { // calibration params
750 selectedSector = (Int_t)TMath::Floor((gy+0.5)/144.0);
751 }
752 if(viewedParamClass==1) { // FEE params
753 selectedSector = (Int_t)TMath::Floor((gy+0.5)/8.0);
754 }
755 }
756
757 fNmbSector->SetNumber(selectedSector);
758 fNmbStack->SetNumber(selectedStack);
759 DoNewSelection();
760 return;
761}
762
763//___________________________________________________________________________
764void AliTRDCalibViewerGUI::ShowGUI() {
765 //
766 // Draw the graphical user interface
767 //
768 TGMainFrame* mainWindow = new TGMainFrame(gClient->GetRoot(), 1000, 700);
769 mainWindow->SetWindowName("Run OCDB details");
770 mainWindow->SetCleanup(kDeepCleanup);
771 AliTRDCalibViewerGUI *calibViewer = new AliTRDCalibViewerGUI(mainWindow, 1000, 650, 0);
772 mainWindow->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
773 mainWindow->MapSubwindows();
774 mainWindow->Resize();
775 mainWindow->MapWindow();
776}
777
778//___________________________________________________________________________
779void AliTRDCalibViewerGUI::ShowGUI(const Char_t* treeFile, const Char_t* treeName) {
780 //
781 // Draw the graphical user interface
782 //
783 TGMainFrame* mainWindow = new TGMainFrame(gClient->GetRoot(), 1000, 700);
784 mainWindow->SetWindowName("Run OCDB details");
785 mainWindow->SetCleanup(kDeepCleanup);
786 AliBaseCalibViewerGUI *calibViewer = new AliTRDCalibViewerGUI(mainWindow, 1000, 650, 0);
787 mainWindow->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
788
789 calibViewer->Initialize(treeFile, treeName);
790 calibViewer->Reload();
791 calibViewer->DoDraw();
792
793 mainWindow->MapSubwindows();
794 mainWindow->Resize();
795 mainWindow->MapWindow();
796}
797
798//___________________________________________________________________________
799void AliTRDCalibViewerGUI::ShowGUIwithTrending() {
800 //
801 // Draw a GUI application containing 2 tabs:
802 // -- tab for time/run trending
803 // -- tab for run details
804 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 700);
805 frmMain->SetCleanup(kDeepCleanup);
806
807 TGTab* tabMain = new TGTab(frmMain, 1000, 700);
808 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
809 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
810 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
811
812 AliCalibViewerGUItime* calibViewerTime = new AliCalibViewerGUItime(tabCont1, 1000, 650, "TRD");
813 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
814
815 AliTRDCalibViewerGUI *calibViewer = new AliTRDCalibViewerGUI(tabCont2, 1000, 700, 0);
816 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
817 calibViewerTime->SetCalibViewerGUI(calibViewer);
818 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
819
820 frmMain->MapSubwindows();
821 frmMain->Resize();
822 frmMain->MapWindow();
823}