Bug corrected.
[u/mrichter/AliRoot.git] / STEER / AliCalibViewerGUItime.cxx
CommitLineData
11a2ac51 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// //
19// GUI for displaying calibration entries over time //
20// //
21// Authors: Marian Ivanov (Marian.Ivanov@cern.ch) //
22// Jens Wiechula (Jens.Wiechula@cern.ch) //
23// Ionut Arsene (iarsene@cern.ch) //
24// //
25// Usage: AliCalibViewerGUItime::ShowGUI(TChain* chain) //
26// AliCalibViewerGUItime::ShowGUI() //
27///////////////////////////////////////////////////////////////////////////////
28
29
30#include <iostream>
31//Root includes
32#include <TROOT.h>
33#include <TDirectory.h>
34#include <TStyle.h>
35#include <TCanvas.h>
36#include <TPad.h>
37#include <TVirtualPad.h>
38#include <TObject.h>
39#include <TObjArray.h>
40#include <TObjString.h>
41#include <TSystem.h>
42#include <TVector.h>
43#include <TH1.h>
44#include <TCut.h>
45#include <TFile.h>
46#include <TTree.h>
47#include <TChain.h>
48#include <TBranch.h>
49#include <TIterator.h>
50#include <TGraph.h>
51#include <TAxis.h>
52#include <TTimeStamp.h>
53#include <TMath.h>
54#include <TMap.h>
55//
56#include <TGFileDialog.h>
57#include <TGInputDialog.h>
58//
59#include <TGButton.h>
60#include <TGListBox.h>
61#include <TGComboBox.h>
62#include <TGNumberEntry.h>
63#include <TGLayout.h>
64#include <TRootEmbeddedCanvas.h>
65#include <TGSplitter.h>
66#include <TGButtonGroup.h>
67#include <TGLabel.h>
68#include <TGTab.h>
69#include <TGString.h>
70
71//AliRoot includes
72#include <AliLog.h>
73#include "AliBaseCalibViewer.h"
74#include "AliBaseCalibViewerGUI.h"
75#include "AliCalibViewerGUItime.h"
76
77
78ClassImp(AliCalibViewerGUItime)
79
80//_______________________________________________________________________________________________________________
81AliCalibViewerGUItime::AliCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h, const Char_t* det) :
82TGCompositeFrame(p,w,h),
83 fDetector(det),
84 fFile(0x0),
85 fTree(0x0),
86 fCalibViewerGUI(0x0),
87 fCalibViewerGUItab(0x0),
88 fCurrentHist(0x0),
89 fCurrentGraph(0x0),
90 fCurrentRunDetails(-1),
91 fOutputCacheDir("/tmp"),
92 fDrawString(""),
93 fIsCustomDraw(kFALSE),
94 fRunNumbers(10),
95 fTimeStamps(10),
96 fValuesX(10),
97 fValuesY(10),
98 fNoGraph(kFALSE),
99 fGraphLimitEntries(10000),
100 fMapRefTrees(new TMap),
101 //GUI elements
102 //main canvas Top part, bottom part
103 fContTopBottom(0x0),
104 //top left, centre, right
105 fContLCR(0x0),
106 //content left
107 fContLeft(0x0),
108 fContDrawOpt(0x0),
109 fChkDrawOptSame(0x0),
110 fComboAddDrawOpt(0x0),
111 fContDrawSel(0x0),
112 fContDrawSelSubRunTime(0x0),
113 fRadioXhist(0x0),
114 fRadioXrun(0x0),
115 fRadioXtime(0x0),
116 fListVariables(0x0),
117 fComboRunType(0x0),
118 fLblRunType(0x0),
119 fNmbPar(0x0),
120 fLblPar(0x0),
121 fListCalibType(0x0),
122 fContCalibType(0x0),
123 //content centre
124 fContCenter(0x0),
125 fCanvMain(0x0),
126 //content right
127 fContRight(0x0),
128 fContValues(0x0),
129 fLblRunNumber(0x0),
130 fLblRunTime(0x0),
131 fLblValueX(0x0),
132 fLblValueY(0x0),
133 fLblRunNumberVal(0x0),
134 fLblRunTimeVal(0x0),
135 fLblValueXVal(0x0),
136 fLblValueYVal(0x0),
137 fBtnDumpRuns(0x0),
138 fBtnSave(0x0),
139 //load a file
140 fContLoad(0x0),
141 fContFilename(0x0),
142 fContConfigFile(0x0),
143 fContTreeName(0x0),
144 fLblTreeName(0x0),
145 fTxtFilename(0x0),
146 fTxtConfigFile(0x0),
147 fTxtTreeName(0x0),
148 fBtnLoadFile(0x0),
149 // extract information from OCDB
150 //content bottom
151 fContCustom(0x0),
152 fContCustomCuts(0x0),
153 fLblCustomDraw(0x0),
154 fLblCustomCuts(0x0),
155 fComboCustomDraw(0x0),
156 fComboCustomCuts(0x0),
157 fTrashBox(new TObjArray)
158{
159 //
160 // ctor
161 //
162 fDetector.ToUpper();
163 fMapRefTrees->SetOwnerKeyValue();
164 fTrashBox->SetOwner();
165 DrawGUI(p,w,h);
166 gStyle->SetMarkerStyle(20);
167 gStyle->SetMarkerSize(0.5);
168 SetInitialValues();
169}
170
171//______________________________________________________________________________
172AliCalibViewerGUItime::~AliCalibViewerGUItime(){
173 //
174 // dtor
175 //
176 // delete fConfigParser;
177 delete fTrashBox;
178 delete fMapRefTrees;
179}
180
181//______________________________________________________________________________
182void AliCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
183 //
184 // draw the GUI
185 //
186 // ======================================================================
187 // ************************* Display everything *************************
188 // ======================================================================
189
190 SetCleanup(kDeepCleanup);
191
192 // *****************************************************************************
193 // ************************* content of this MainFrame *************************
194 // *****************************************************************************
195 // top level container with horizontal layout
196 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
197 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
198
199 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
200 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
201
202 // ***********************************************************************
203 // ************************* content of fContLCR *************************
204 // ***********************************************************************
205 // left container
206 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
207 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
208
209 // left vertical splitter
210 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
211 splitLeft->SetFrame(fContLeft, kTRUE);
212 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
213
214 // right container
215 fContRight = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
216 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
217
218 // center container
219 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
220 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
221
222 // right vertical splitter
223 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
224 splitRight->SetFrame(fContRight, kFALSE);
225 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
226
227
228 // ========================================================================
229 // ************************* content of fContLeft *************************
230 // ========================================================================
231 // --- draw button and tabLeft ---
232 // draw options
233 fContDrawOpt = new TGGroupFrame(fContLeft, "Draw options", kVerticalFrame | kFitWidth | kFitHeight);
234 fContLeft->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
235 fChkDrawOptSame = new TGCheckButton(fContDrawOpt, "Same");
236 fContDrawOpt->AddFrame(fChkDrawOptSame, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
237 fChkDrawOptSame->SetToolTipText("Add draw option 'same'");
238 // additional draw options combo box
239 fComboAddDrawOpt = new TGComboBox(fContDrawOpt);
240 fComboAddDrawOpt->Resize(0, 22);
241 fComboAddDrawOpt->EnableTextInput(kTRUE);
242 fContDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
243
244 // draw selection group
245 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
246 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
247 //x-axis variables selection, Run of Time
248 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
249 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
250
251 // ------------------------- content of fContDrawOpt -------------------------
252 //
253 // Run radio button
254 // Time radio button
255 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
256 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
257 fRadioXhist->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleButtonsDrawSel()");
258 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
259
260 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
261 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
262 fRadioXrun->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleButtonsDrawSel()");
263 fRadioXrun->SetToolTipText("Use run number as x-value");
264
265 // Time radio button
266 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
267 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
268 fRadioXtime->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleButtonsDrawSel()");
269 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
270
271
272 // list of variables
273 fListVariables = new TGListBox(fContDrawSel);
274 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
275 fListVariables->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoNewSelection()");
276
277
278//-------------------- run type selection ------------------------
279 // Parameter label
280 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
281 fLblRunType->SetTextJustify(kTextLeft);
282 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
283
284 fComboRunType = new TGComboBox(fContDrawSel);
285 fComboRunType->EnableTextInput(kFALSE);
286 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
287 fComboRunType->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoDraw()");
288 fComboRunType->Resize(0, 22);
289
290 //-------------------- parameter selection ------------------------
291 // Parameter label
292 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
293 fLblPar->SetTextJustify(kTextLeft);
294 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
295
296 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
297 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
298 fNmbPar->Connect("ValueSet(Long_t)", "AliCalibViewerGUItime", this, "DoParLimitChange()");
299 fNmbPar->SetState(kFALSE);
300
301 //-------------------- calibration type selection ------------------------
302 // label
303 // draw selection group
304 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
305 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
306
307 // list of variables
308 fListCalibType = new TGListBox(fContCalibType);
309 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
310 fListCalibType->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoChangeSelectionList()");
311 fListCalibType->Resize(0,88);
312 fListCalibType->SetMultipleSelections();
313
314
315 // ==========================================================================
316 // ************************* content of fContCenter *************************
317 // ========================================================================
318 // main drawing canvas
319 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
320 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
321 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
322 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
323 fCanvMain->GetCanvas()->SetRightMargin(0.062);
324 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
325
326 // =========================================================================
327 // ************************* content of fContRight *************************
328 // ========================================================================
329 //group frame for value information
330 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
331 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
332 //set layout manager
333 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 4));
334 //value information labels
335
336 //run number label
337 fLblRunNumber = new TGLabel(fContValues, "Run:");
338 fLblRunNumber->SetTextJustify(kTextLeft);
339 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
340 //run number
341 fLblRunNumberVal = new TGLabel(fContValues, "0000000");
342 fLblRunNumberVal->SetTextJustify(kTextLeft);
343 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
344 //time stamp label
345 fLblRunTime = new TGLabel(fContValues, "Time:");
346 fLblRunTime->SetTextJustify(kTextLeft);
347 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
348 //run number
349 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
350 fLblRunTimeVal->SetTextJustify(kTextLeft);
351 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
352 //value label x
353 fLblValueX = new TGLabel(fContValues, "x-Value:");
354 fLblValueX->SetTextJustify(kTextLeft);
355 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
356 //value x
357 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
358 fLblValueXVal->SetTextJustify(kTextRight);
359 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
360 //value label y
361 fLblValueY = new TGLabel(fContValues, "y-Value:");
362 fLblValueY->SetTextJustify(kTextLeft);
363 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
364 //value y
365 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
366 fLblValueYVal->SetTextJustify(kTextRight);
367 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
368 // draw button
369 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
370 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
371 fBtnDumpRuns->Connect("Clicked()", "AliCalibViewerGUItime", this, "DoDumpRuns()");
372 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
373 // save button
374 fBtnSave = new TGTextButton(fContRight, "&Save picture");
375 fContRight->AddFrame(fBtnSave, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
376 fBtnSave->SetToolTipText("Press to save the current picture in the canvas");
377 fBtnSave->Connect("Clicked()", "AliCalibViewerGUItime", this, "SavePicture()");
378
379 //group frame for loading a file
380 fContLoad = new TGGroupFrame(fContRight, "Load file", kVerticalFrame | kFitWidth | kFitHeight);
381 fContRight->AddFrame(fContLoad, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
382
383 fContFilename = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
384 fContLoad->AddFrame(fContFilename, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
385
386 fTxtFilename = new TGTextEntry(fContFilename, "Input file", 100);
387 fContFilename->AddFrame(fTxtFilename, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
388 fTxtFilename->Connect("DoubleClicked()", "AliCalibViewerGUItime", this, "HandleLoadRunTextEntry()");
389
390 fContTreeName = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
391 fContLoad->AddFrame(fContTreeName, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
392
393 fLblTreeName = new TGLabel(fContTreeName, "Tree Name:");
394 fLblTreeName->SetTextJustify(kTextLeft);
395 fContTreeName->AddFrame(fLblTreeName, new TGLayoutHints(kLHintsNormal | kLHintsCenterY, 0, 1, 0, 0));
396
397 fTxtTreeName = new TGTextEntry(fContTreeName, "trdTree");
398 if(fDetector.Contains("TPC")) fTxtTreeName->SetText("dcs");
399 fContTreeName->AddFrame(fTxtTreeName, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
400
401 fBtnLoadFile = new TGTextButton(fContLoad, "Load file", 100);
402 fContLoad->AddFrame(fBtnLoadFile, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
403 fBtnLoadFile->SetToolTipText("Load a file into viewer");
404 fBtnLoadFile->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleLoadRunButtons()");
405
406 // =========================================================================
407 // ****************** bottom content of fContTopBottom *********************
408 // =========================================================================
409
410 // custom options container
411 // --- fComboCustom --- the custom draw line on the very low
412 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
413 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
414
415 // ------------------------- content of fContCustom -------------------------
416 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
417 fLblCustomDraw->SetTextJustify(kTextLeft);
418 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
419 // text field for custom draw command
420 fComboCustomDraw = new TGComboBox(fContCustom);
421 fComboCustomDraw->Resize(0, 22);
422 fComboCustomDraw->EnableTextInput(kTRUE);
423 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
424 fComboCustomDraw->Connect("ReturnPressed()", "AliCalibViewerGUItime", this, "DoCustomDraw()");
425 fComboCustomDraw->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoCustomDraw()");
426
427
428 // additional cuts container
429 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
430 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
431
432 // ------------------------- content of fContCustomCuts -------------------------
433 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
434 fLblCustomCuts->SetTextJustify(kTextLeft);
435 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
436 // combo text field for additional cuts
437 fComboCustomCuts = new TGComboBox(fContCustomCuts);
438// fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
439 fComboCustomCuts->Resize(0, 22);
440 fComboCustomCuts->EnableTextInput(kTRUE);
441 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
442 fComboCustomCuts->Connect("ReturnPressed()", "AliCalibViewerGUItime", this, "DoCustomCutsDraw()");
443 fComboCustomCuts->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoCustomCutsDraw()");
444
445 if(fDetector.Contains("TPC")) SetWindowName("AliTPCCalibViewer GUI - Time");
446 else if (fDetector.Contains("TRD")) SetWindowName("AliTRDCalibViewer GUI - Time");
447 else SetWindowName("Unknown detector");
448 MapSubwindows();
449 Resize(GetDefaultSize());
450 MapWindow();
451}
452
453//______________________________________________________________________________
454void AliCalibViewerGUItime::SetInitialValues(){
455 //
456 // Set inital selections of the gui
457 //
458 fRadioXrun->SetState(kButtonDown);
459 fRadioXtime->SetState(kButtonUp);
460}
461
462//______________________________________________________________________________
463void AliCalibViewerGUItime::UseFile(const char* fileName, const char* treeName) {
464 //
465 // retrieve tree from file
466 //
467 TString s(fileName);
468 TObjArray *arr=s.Tokenize(" ");
469 TIter next(arr);
470 TObject *o=0;
471 if (fTree) delete fTree;
472 fTree=new TChain(treeName);
473 while ( (o=next()) ){
474 TString tmpString(o->GetName());
475 std::cout << "Adding " << tmpString.Data() << " to the chain" << std::endl;
476 if(tmpString.Contains(".root"))
477 fTree->AddFile(tmpString.Data());
478 else {
479 tmpString += "/*.root";
480 fTree->Add(tmpString.Data());
481 }
482 }
483 delete arr;
484 if (!CheckChain())
485 return;
486 // UseConfigFile(fConfigFile.Data());
487 FillCalibTypes();
488 Reload();
489}
490
491//______________________________________________________________________________
492void AliCalibViewerGUItime::UseChain(TChain* chain)
493{
494 //
495 // load a chain
496 //
497 fTree=chain;
498 if (!CheckChain()) {
499 std::cout << "AliCalibViewerGUItime::UseChain !checkchain OUT" << std::endl;
500 return;
501 }
502 //set configuration file
503 // UseConfigFile(fConfigFile.Data());
504 FillCalibTypes();
505 Reload();
506}
507
508//______________________________________________________________________________
509Bool_t AliCalibViewerGUItime::CheckChain()
510{
511 //
512 // check whether cahin has entries
513 // decide whether to draw graphs in 2D
514 //
515 if (!fTree) {
516 return kFALSE;
517 }
518 fTree->Lookup();
519 Long64_t entries=fTree->GetEntries();
520 if (entries==0){
521 AliError("No entries found in chain");
522 return kFALSE;
523 }
524 //check whether to draw graphs
525 CheckDrawGraph();
526 return kTRUE;
527}
528
529//______________________________________________________________________________
530void AliCalibViewerGUItime::FillRunTypes()
531{
532 //
533 //Loop over the tree entries and fill the run types
534 //
535 if (!fTree) {
536 return;
537 }
538 Int_t id=0;
539 fComboRunType->RemoveAll();
540 fComboRunType->AddEntry("ALL",id++);
541 fComboRunType->Select(0,kFALSE);
542 if (!fTree->GetBranch("runType.")) {
543 return;
544 }
545 TObjString *runType=0x0;
546 Int_t nevets=fTree->GetEntries();
547 fTree->SetBranchStatus("*",0);
548 fTree->SetBranchStatus("runType.*",1);
549 fTree->SetBranchAddress("runType.",&runType);
550 for (Int_t iev=0;iev<nevets;++iev){
551 fTree->GetEntry(iev);
552 TString type=runType->String();
553 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
554 }
555 fTree->ResetBranchAddresses();
556 fTree->SetBranchStatus("*",1);
557}
558
559//______________________________________________________________________________
560void AliCalibViewerGUItime::FillCalibTypes()
561{
562 //
563 // loop over configuration and fill calibration types
564 //
565 Int_t id=0;
566 fListCalibType->RemoveAll();
567 // TObject *o=0x0;
568 // fConfigParser->ResetIter();
569 TString type="UNSPECIFIED";
570 fListCalibType->AddEntry(type.Data(),id);
571 fListCalibType->Select(id++);
572}
573
574//______________________________________________________________________________
575void AliCalibViewerGUItime::CheckDrawGraph()
576{
577 //
578 // Check whether to draw graphs in 2D mode based on the number of entries in the chain
579 // GetEstimate() returns the maximum size of the arrays stored in GetV1()...
580 //
581 if (!fTree) {
582 return;
583 }
584 fNoGraph=kTRUE;
585 if (fTree->GetEntries()<fTree->GetEstimate()) fNoGraph=kFALSE;
586}
587
588//______________________________________________________________________________
589void AliCalibViewerGUItime::Reload(Int_t first)
590{
591 //
592 // reload the gui contents, this is needed after the input tree has changed
593 //
594 first = first;
595 if ( !fTree ) {
596 return;
597 }
598
599 FillRunTypes();
600
601 //activate all branches
602 fTree->SetBranchStatus("*",1);
603 //reset variables list
604 fListVariables->RemoveAll();
605 //get selected calibration types
606 TList calibTypes;
607 fListCalibType->GetSelectedEntries(&calibTypes);
608
609 TObjArray *branchList = fTree->GetListOfBranches();
610 if ( !branchList ) return;
611 TIter nextBranch(branchList);
612 Int_t idCount=0,id=0;
613 TObject *objBranch=0;
614 while ( (objBranch=nextBranch()) ){
615 TString branchName(objBranch->GetName());
616 TString branchTitle(objBranch->GetName());
617 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
618 Bool_t active=kTRUE;
619 TString calibType="UNSPECIFIED";
620
621 //check if branch is in selected calibration types
622 //if not, don't show it in the list and deactivate the branch.
623 Bool_t calibActive=kFALSE;
624 TIter nextCalib(&calibTypes);
625 TObject *objCalib=0;
626 while ( (objCalib=nextCalib()) ) {
627 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
628 }
629 active&=calibActive;
630 if (!active){
631 TString s=branchName;
632 if (branchName.EndsWith(".")) s+="*";
633 fTree->SetBranchStatus(s.Data(),0);
634 continue;
635 }
636 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
637 //fListVariables->Select(id);
638 ++idCount;
639 }
640 //trick to display modifications
641 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
642 fListCalibType->Resize(fListCalibType->GetWidth()+1, fListCalibType->GetHeight());
643}
644
645//______________________________________________________________________________
646void AliCalibViewerGUItime::AddReferenceTree(const char* treeFileName, const char* refName)
647{
648 //
649 // map of reference trees that should always be attached to the CalibViewerGUI
650 //
651 fMapRefTrees->Add(new TObjString(refName), new TObjString(treeFileName));
652}
653
654//______________________________________________________________________________
655const char* AliCalibViewerGUItime::GetDrawString(){
656 //
657 // create draw string for ttree by combining the user requestsa
658 //
659
660 TString selectedVariable="";
661 Int_t id=-1;
662 if (!fListVariables->GetSelectedEntry()) {
663 return "";
664 }
665 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
666 id=fListVariables->GetSelectedEntry()->EntryId();
667 TString branchName=selectedVariable;
668 // const TObject *key=(*fConfigParser)(id);
669 // if (key) branchName=(*fConfigParser)(id)->GetName();
670 //treat case of TVector
671 if (branchName.EndsWith(".")){
672 Int_t par = (Int_t)(fNmbPar->GetNumber());
673 branchName.Append(Form("fElements[%d]",par));
674 }
675
676 return branchName.Data();
677}
678//______________________________________________________________________________
73bbf779 679const char* AliCalibViewerGUItime::GetDrawOption() const {
11a2ac51 680 //
681 // get user selected draw options
682 //
683 TString drawOpt;
684 if (fComboAddDrawOpt->GetSelectedEntry()) drawOpt=fComboAddDrawOpt->GetSelectedEntry()->GetTitle();
685 if (fChkDrawOptSame->GetState()==kButtonDown && !drawOpt.Contains("same",TString::kIgnoreCase))
686 drawOpt+="same";
687 return drawOpt.Data();
688}
689//______________________________________________________________________________
690void AliCalibViewerGUItime::GetCutString(TString &cutStr){
691 //
692 // create cut string
693 //
694 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
695 TString runType="";
696 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
697 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
698 cutStr=cuts.GetTitle();
699}
700//______________________________________________________________________________
701void AliCalibViewerGUItime::UpdateValueArrays(Bool_t withGraph)
702{
703 //
704 // Update arrays of runs
705 //
706 if (!withGraph){
707 fValuesX.ResizeTo(1);
708 fValuesY.ResizeTo(1);
709 fRunNumbers.ResizeTo(1);
710 fTimeStamps.ResizeTo(1);
711 } else {
712 fValuesX.ResizeTo(fTree->GetSelectedRows());
713 fValuesY.ResizeTo(fTree->GetSelectedRows());
714 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
715 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
716 fValuesY.SetElements(fTree->GetV3());
717 fRunNumbers.SetElements(fTree->GetV1());
718 fTimeStamps.SetElements(fTree->GetV2());
719 }
720}
721
722//______________________________________________________________________________
723void AliCalibViewerGUItime::GetHistogramTitle(TString &title)
724{
725 //
726 // Create string for histogram title
727 //
728
729 title=fDrawString;
730 Int_t pos=title.First(">>");
731 if (pos>0) title=title(0,pos);
732 if (!fIsCustomDraw){
733 if (fRadioXrun->GetState()==kButtonDown){
734 title+=":Run";
735 } else if (fRadioXtime->GetState()==kButtonDown){
736 title+=":Date";
737 }
738 }
739 TString cuts;
740 GetCutString(cuts);
741 TObjArray *arr=title.Tokenize(":");
742 TObject *o=0x0;
743 title+=" {";
744 title+=cuts;
745 title+="}";
746 TIter next(arr,kIterBackward);
747 while ( (o=next()) ){
748 TString varName=o->GetName();
749 title+=";";
750 title+=varName;
751 }
752 delete arr;
753}
754
755//______________________________________________________________________________
756void AliCalibViewerGUItime::AdjustYRange()
757{
758 //
759 // adjust the range of the Y axis
760 //
761 TIter nextGraphicObject(fTrashBox);
762 TObject *o=0x0;
763 Float_t min=0,max=0;
764 while ( (o=nextGraphicObject()) ){
765 if (o->IsA()==TGraph::Class()){
766 TGraph *gr=(TGraph*)o;
767 if (min==max) {
768 min=TMath::MinElement(gr->GetN(),gr->GetY());
769 max=TMath::MaxElement(gr->GetN(),gr->GetY());
770 } else {
771 Float_t currmin=TMath::MinElement(gr->GetN(),gr->GetY());
772 Float_t currmax=TMath::MaxElement(gr->GetN(),gr->GetY());
773 if (currmax>max) max=currmax;
774 if (currmin<min) min=currmin;
775 }
776 }
777 }
778 if (min!=max){
779 if (min!=0) min=min-(max-min)/10;
780 if (max!=0) max=max+(max-min)/10;
781 fCurrentHist->SetMinimum(min);
782 fCurrentHist->SetMaximum(max);
783 }
784}
785//______________________________________________________________________________
786void AliCalibViewerGUItime::DoDraw() {
787 //
788 // Draw graphics
789 //
790 TString drawString=fDrawString;
791 TString cutString;
792 GetCutString(cutString);
793 TString optString = GetDrawOption();
794 Bool_t graphOutput=!fNoGraph; //ttree buffer for V1, V2... too small
795 graphOutput&=(drawString.First(">>")<0); //histogram output in custom draw
796 graphOutput&=fRadioXhist->GetState()!=kButtonDown; //histogram drawing selected
797 graphOutput&=!(fIsCustomDraw&&!fDrawString.Contains(":")); //custom draw 1D
798 Bool_t drawSame=optString.Contains("same",TString::kIgnoreCase);
799// optString+="goff";
800 if (graphOutput) {
801 drawString.Prepend("run:time:");
802 optString="goff";
803 }else{
804 if (!fIsCustomDraw){
805 if (fRadioXrun->GetState()==kButtonDown){
806 drawString+=":run";
807 } else if (fRadioXtime->GetState()==kButtonDown){
808 drawString+=":time";
809 }
810 }
811 }
812 TVirtualPad *padsave=gPad;
813 fCanvMain->GetCanvas()->cd();
814 //delete old histograms and graphs
815 if (!drawSame){
816 fTrashBox->Delete();
817 fCurrentGraph=0x0;
818 fCurrentHist=0x0;
819 }
820
821 //select data
822 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
823 if (fTree->GetSelectedRows()==-1) {
824 return;
825 }
826 UpdateValueArrays(graphOutput);
827 TString title;
828 GetHistogramTitle(title);
829 Bool_t drawGraph=kFALSE;
830 if (graphOutput){
831 if (fIsCustomDraw){
832 if (fDrawString.Contains(":")){
833 fValuesX.SetElements(fTree->GetV4());
834 drawGraph=kTRUE;
835 } else {
836 drawGraph=kFALSE;
837 }
838 }else{
839 drawGraph=kTRUE;
840 if (fRadioXrun->GetState()==kButtonDown){
841 fValuesX.SetElements(fTree->GetV1());
842 } else if (fRadioXtime->GetState()==kButtonDown){
843 fValuesX.SetElements(fTree->GetV2());
844 } else {
845 drawGraph=kFALSE;
846 }
847 }
848 }//create graph according to selection
849 if (drawGraph){
850 TGraph *graph=new TGraph(fValuesX,fValuesY);
851 TString grDraw="p";
852 if (!drawSame) grDraw+="a";
853 if (!fIsCustomDraw) grDraw+="l";
854 graph->Draw(grDraw.Data());
855 graph->SetEditable(kFALSE);
856 TH1 *hist=graph->GetHistogram();
857 hist->SetTitle(title.Data());
858 fTrashBox->Add(graph);
859 graph->SetLineColor(fTrashBox->GetEntries());
860 graph->SetMarkerColor(fTrashBox->GetEntries());
861 if (!drawSame) {
862 fCurrentGraph=graph;
863 fCurrentHist=hist;
864 }
865 } else {
866 TH1 *hist=fTree->GetHistogram();
867 hist->SetTitle(title.Data());
868 fTrashBox->Add(hist);
869 hist->SetLineColor(fTrashBox->GetEntries());
870 hist->SetMarkerColor(fTrashBox->GetEntries());
871 if (!drawSame) fCurrentHist=hist;
872 }
873
874 //Set time axis if choosen as x-variables
875 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw&&!drawSame){
876 TAxis *xaxis=fCurrentHist->GetXaxis();
877 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
878 xaxis->SetTimeDisplay(1);
879 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
880 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
881 }
882 if (!drawSame) {
883 //Set title offset
884 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
885 } else {
886 //adjust y-range
887 AdjustYRange();
888 }
889 gPad->Modified();
890 gPad->Update();
891 padsave->cd();
892}
893
894//______________________________________________________________________________
895void AliCalibViewerGUItime::DoDumpRuns()
896{
897 //
898 // Dump the current run numbers to stdout
899 //
900 Int_t npoints=fRunNumbers.GetNrows();
901 Int_t *sortIndex = new Int_t[npoints];
902 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
903 Int_t run=0, prevRun=-1;
904
905 for (Int_t irun=0;irun<npoints;++irun){
906 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
907 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
908 prevRun=run;
909 }
b5ed6afb 910 delete [] sortIndex;
11a2ac51 911}
912
913//______________________________________________________________________________
914void AliCalibViewerGUItime::DoParLimitChange()
915{
916 //
917 // DoParLimitChange()
918 //
919 UpdateParName();
920 DoDraw();
921}
922
923//______________________________________________________________________________
924void AliCalibViewerGUItime::DoNewSelection() {
925 //
926 // decides whether to redraw if user makes another selection
927 //
928 UpdateParLimits();
929 fDrawString=GetDrawString();
930 fIsCustomDraw=kFALSE;
931 DoDraw();
932}
933
934//______________________________________________________________________________
935void AliCalibViewerGUItime::DoCustomDraw()
936{
937 //
938 // Custom draw (TTree::Draw syntax)
939 //
940 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
941 fNmbPar->SetState(kFALSE);
942 fIsCustomDraw=kTRUE;
943 DoDraw();
944}
945
946//______________________________________________________________________________
947void AliCalibViewerGUItime::DoCustomCutsDraw()
948{
949 //
950 // Custom cuts (TTree::Draw syntax)
951 //
952 if (fIsCustomDraw) DoCustomDraw();
953 else {
954 fDrawString=GetDrawString();
955 fIsCustomDraw=kFALSE;
956 DoDraw();
957 }
958}
959
960//______________________________________________________________________________
961void AliCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
962{
963 //
964 // Draw selection button handling (x-variable)
965 //
966
967 if (id == -1) {
968 TGButton *btn = (TGButton *) gTQSender;
969 id = btn->WidgetId();
970 }
971
972 Bool_t doDraw=kFALSE;
973 switch (id) {
974 case (kRadioXhist):
975 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
976 if (doDraw){
977 fRadioXrun->SetState(kButtonUp);
978 fRadioXtime->SetState(kButtonUp);
979 }
980 break;
981 case (kRadioXrun):
982 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
983 if (doDraw){
984 fRadioXhist->SetState(kButtonUp);
985 fRadioXtime->SetState(kButtonUp);
986 }
987 break;
988 case (kRadioXtime):
989 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
990 if (doDraw){
991 fRadioXrun->SetState(kButtonUp);
992 fRadioXhist->SetState(kButtonUp);
993 }
994 break;
995 }
996 if (doDraw) DoCustomCutsDraw();
997}
998//______________________________________________________________________________
999void AliCalibViewerGUItime::UpdateParName()
1000{
1001 //
1002 // change parameter name
1003 //
1004
1005 Int_t par = (Int_t)(fNmbPar->GetNumber());
1006 TString parName="";
1007 parName.Form("%d",par);
1008 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
1009 fDrawString=GetDrawString();
1010 fIsCustomDraw=kFALSE;
1011}
1012
1013//______________________________________________________________________________
1014void AliCalibViewerGUItime::UpdateParLimits()
1015{
1016 //
1017 // Adjust limits for TVectorT based variables
1018 //
1019 if (!fTree) return;
1020 TString selectedVariableTitle="";
1021 Int_t id=-1;
1022 if (!fListVariables->GetSelectedEntry()) return;
1023 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
1024 id=fListVariables->GetSelectedEntry()->EntryId();
1025 TString selectedVariable=selectedVariableTitle;
1026 // const TObject *key=(*fConfigParser)(id);
1027 // if (key) selectedVariable=(*fConfigParser)(id)->GetName();
1028
1029 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
1030 fNmbPar->SetState(kFALSE);
1031 fLblPar->SetText("Parameter: none");
1032 return;
1033 }
1034 TVectorD *vD=0x0;
1035 TVectorF *vF=0x0;
1036 Int_t maxPar=0;
1037 fTree->GetEntry(1);
1038 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
1039 TString branchClass=branch->GetClassName();
1040 Int_t event=0;
1041 if (branchClass=="TVectorT<double>"){
1042// branch->SetAddress(&vD);
1043 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
1044 while (maxPar<2&&event<fTree->GetEntries()){
1045 fTree->GetEntry(event++);
1046 maxPar=vD->GetNrows();
1047 }
1048 } else if (branchClass=="TVectorT<float>"){
1049// branch->SetAddress(&vF);
1050 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
1051 while (maxPar<2&&event<fTree->GetEntries()){
1052 fTree->GetEntry(event++);
1053 maxPar=vF->GetNrows();
1054 }
1055 } else {
1056 //class not known
1057 fNmbPar->SetState(kFALSE);
1058 return;
1059 }
1060 fTree->SetBranchAddress(selectedVariable.Data(),0x0);
1061 if (fNmbPar->GetNumMax()!=maxPar-1) fNmbPar->SetNumber(0);
1062 fNmbPar->SetLimitValues(0,maxPar-1);
1063 fNmbPar->SetState(kTRUE);
1064 UpdateParName();
1065}
1066//______________________________________________________________________________
1067void AliCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
1068{
1069 //
1070 // handle mouse events in the draw canvas
1071 //
1072 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
1073 Double_t valx=0.,valy=0.;
1074 if (!fCurrentGraph) {
1075 fLblRunNumberVal->SetText(Form("%07u",run));
1076 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
1077 fLblValueXVal->SetText(Form("%.3e", valx));
1078 fLblValueYVal->SetText(Form("%.3e", valy));
1079 return;
1080 }
1081 TVirtualPad *padsave=gPad;
1082 fCanvMain->GetCanvas()->cd();
1083 Int_t n=fValuesY.GetNrows();
1084 Double_t *arr=0x0;
1085 arr=fValuesX.GetMatrixArray();
1086
1087 Int_t minDist=1000000;
1088 Int_t minPoint=-1;
1089 for (Int_t i=0;i<n;++i){
1090 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
1091 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
1092 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
1093 if (d < minDist) {
1094 minDist = d;
1095 minPoint = i;
1096 }
1097 }
1098 if (minDist<2){
1099 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
1100 t.GetDate(kTRUE,0,&yy,&mm,&dd);
1101 t.GetTime(kTRUE,0,&HH,&MM,&SS);
1102 run=(UInt_t)fRunNumbers[minPoint];
1103 valx=fValuesX[minPoint];
1104 valy=fValuesY[minPoint];
1105 } else {
1106 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
1107 valx=0.;
1108 valy=0.;
1109 }
1110 fLblRunNumberVal->SetText(Form("%07u",run));
1111 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
1112 if (fIsCustomDraw){
1113 fLblValueXVal->SetText(Form("%.3e", valx));
1114 }else{
1115 if (fRadioXrun->GetState()==kButtonDown){
1116 fLblValueXVal->SetText("Run");
1117 } else if (fRadioXtime->GetState()==kButtonDown){
1118 fLblValueXVal->SetText("Time");
1119 }
1120 }
1121 fLblValueYVal->SetText(Form("%.3e", valy));
1122 padsave->cd();
1123 if (run==0) {
1124 return;
1125 }
1126 if (event == kButton1Double ){
1127 SetGuiTree(run);
1128 }
1129 //find closes point of current selection
1130}
1131
1132//______________________________________________________________________________
1133void AliCalibViewerGUItime::SetGuiTree(Int_t run)
1134{
1135 //
1136 // create the AliCalibViewerGUI tree for run
1137 // cache tree in directory fOutputCacheDir
1138 // retrieve file from this directory if it already exists
1139 //
1140
1141 //try to find file for run in fOutputCacheDir
1142 TString fileName=fOutputCacheDir;
1143 if (!fileName.EndsWith("/")) fileName+="/";
1144 if(fDetector.Contains("TPC")) fileName+=Form("guiTreeRun_%d.root",run);
1145 else if(fDetector.Contains("TRD")) fileName+=Form("trdOCDBDetails_run%d.root", run);
1146 else return;
1147 Bool_t load=kTRUE;
1148 TFile f(fileName.Data());
1149 if (!f.IsOpen()){
1150 if(fDetector.Contains("TRD"))
1151 load = fCalibViewerGUI->CreateDetailsTree(run, fileName.Data(), "nothing");
1152 if(fDetector.Contains("TPC"))
1153 load = fCalibViewerGUI->CreateDetailsTree(run, fileName.Data(), "nothing");
1154
1155 if (!load){
1156 fCalibViewerGUI->Reset();
1157 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
1158 return;
1159 }
1160 }
1161 f.Close();
1162 if(fDetector.Contains("TPC")) fCalibViewerGUI->Initialize(fileName.Data(), "calPads");
1163 else fCalibViewerGUI->Initialize(fileName.Data(), "TRDcalibDetails");
1164 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %07d",run)));
1165 TIter nextRefTree(fMapRefTrees);
1166 TObject *o=0x0;
1167 while ( (o=nextRefTree()) ){
1168 if(fDetector.Contains("TPC"))
1169 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"calPads",o->GetName());
1170 else
1171 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"TRDcalibDetails",o->GetName());
1172 }
1173 //if(fDetector.Contains("TPC")) ((AliTPCCalibViewerGUI_new*)fCalibViewerGUI)->Reload();
1174 //else ((AliTRDCalibViewerGUI*)fCalibViewerGUI)->Reload();
1175 fCalibViewerGUI->Reload();
1176}
1177
1178//______________________________________________________________________________
1179const char* AliCalibViewerGUItime::SubstituteUnderscores(const char* in)
1180{
1181 //
1182 // Substitute underscores from the branch names
1183 //
1184 TString s(in);
1185 s.ReplaceAll("_{","|{");
1186 s.ReplaceAll("_"," ");
1187 s.ReplaceAll("|{","_{");
1188 return s.Data();
1189}
1190
1191//______________________________________________________________________________
1192void AliCalibViewerGUItime::SavePicture() {
1193 //
1194 // saves the current picture
1195 //
1196
1197 const char *kSaveAsTypes[] = {
1198 "Postscript", "*.ps",
1199 "Encapsulated Postscript", "*.eps",
1200 "PDF", "*.pdf",
1201 "JPEG", "*.jpg",
1202 "PNG", "*.png",
1203 "TIFF", "*.tiff",
1204 "GIF", "*.gif",
1205 "XPM", "*.xpm",
1206 "SVG", "*.svg",
1207 "XML", "*.xml",
1208 "C++ macro", "*.cxx",
1209 "Macro file", "*.C",
1210 "ROOT file", "*.root",
1211 "All file", "*",
1212 0, 0
1213 };
1214 TString dir(".");
1215 TGFileInfo fi;
1216 fi.fFileTypes = kSaveAsTypes;
1217 // fi.fIniDir = StrDup(dir);
1218 fi.fOverwrite = kFALSE;
1219 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
1220 if (fi.fFilename && strlen(fi.fFilename)) {
1221 fCanvMain->GetCanvas()->Print(fi.fFilename);
1222 }
1223}
1224
1225//______________________________________________________________________________
1226void AliCalibViewerGUItime::HandleLoadRunButtons() {
1227 //
1228 // Handle the buttons
1229 //
1230 Int_t id = ((TGTextButton*)gTQSender)->WidgetId();
1231 if(id==100) {
1232 UseFile(fTxtFilename->GetText(), fTxtTreeName->GetText());
1233 return;
1234 }
1235 else
1236 return;
1237}
1238
1239//______________________________________________________________________________
1240void AliCalibViewerGUItime::HandleLoadRunTextEntry() {
1241 //
1242 // Handle the text entries
1243 //
1244 // buttons ID
1245 // 100 - fTxtFilename
1246 // 101 - fTxtConfigFile
1247
1248 Int_t id = ((TGTextEntry*)gTQSender)->WidgetId();
1249 if(id>=100 && id<=103) {
1250 const char *kTypes[] = {
1251 "All files", "*",
1252 0, 0
1253 };
1254 TString dir(".");
1255 TGFileInfo fi;
1256 fi.fFileTypes = kTypes;
1257 fi.fOverwrite = kFALSE;
1258 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
1259 if(fi.fFilename && strlen(fi.fFilename)) {
1260 if(id==100) {
1261 fTxtFilename->SetText(fi.fFilename);
1262 }
1263 if(id==101) {
1264 // fTxtConfigFile->SetText(fi.fFilename);
1265 // fConfigFile=fi.fFilename;
1266 }
1267 if(id==102) {
1268 //fTxtRunList->SetText(fi.fFilename);
1269 }
1270 if(id==103) {
1271 //fTxtOutputOCDB->SetText(fi.fFilename);
1272 }
1273 }
1274 return;
1275 }
1276 else {
1277 return;
1278 }
1279}
1280
1281//__________________________________________________________________
1282TObjArray* AliCalibViewerGUItime::ShowGUI(TChain* chain) {
1283 //
1284 // Launch the time trending GUI. Load the TChain chain into the viewer
1285 //
1286 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 650);
1287 frmMain->SetWindowName("Calib Viewer - time trend");
1288 frmMain->SetCleanup(kDeepCleanup);
1289
1290 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1291 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1292
1293 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1294
1295 AliCalibViewerGUItime* calibViewerTime = new AliCalibViewerGUItime(tabCont1, 1000, 650);
1296 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1297 calibViewerTime->UseChain(chain);
1298
1299 TObjArray *guiArray = new TObjArray();
1300 guiArray->Add(calibViewerTime);
1301
1302 frmMain->MapSubwindows();
1303 frmMain->Resize();
1304 frmMain->MapWindow();
1305 return guiArray;
1306}
1307
1308//__________________________________________________________________
1309TObjArray* AliCalibViewerGUItime::ShowGUI() {
1310 //
1311 // Launch the time trending GUI. The GUI will be empty but trees can be loaded by using the GUI interface
1312 //
1313 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 650);
1314 frmMain->SetWindowName("Calib Viewer - time trend");
1315 frmMain->SetCleanup(kDeepCleanup);
1316
1317 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1318 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1319
1320 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1321
1322 AliCalibViewerGUItime* calibViewerTime = new AliCalibViewerGUItime(tabCont1, 1000, 650);
1323 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1324
1325 TObjArray *guiArray = new TObjArray();
1326 guiArray->Add(calibViewerTime);
1327
1328 frmMain->MapSubwindows();
1329 frmMain->Resize();
1330 frmMain->MapWindow();
1331 return guiArray;
1332}