]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TPC/AliTPCCalibViewerGUItime.cxx
store ntuple in same file as histos (Renu)
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibViewerGUItime.cxx
... / ...
CommitLineData
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// //
20///////////////////////////////////////////////////////////////////////////////
21
22
23#include <iostream>
24//Root includes
25#include <TROOT.h>
26#include <TDirectory.h>
27#include <TStyle.h>
28#include <TCanvas.h>
29#include <TPad.h>
30#include <TVirtualPad.h>
31#include <TObject.h>
32#include <TObjArray.h>
33#include <TObjString.h>
34#include <TSystem.h>
35#include <TVector.h>
36#include <TH1.h>
37#include <TCut.h>
38#include <TFile.h>
39#include <TTree.h>
40#include <TChain.h>
41#include <TBranch.h>
42#include <TIterator.h>
43#include <TGraph.h>
44#include <TAxis.h>
45#include <TTimeStamp.h>
46#include <TMath.h>
47#include <TMap.h>
48//
49#include <TGFileDialog.h>
50#include <TGInputDialog.h>
51//
52#include <TGButton.h>
53#include <TGListBox.h>
54#include <TGComboBox.h>
55#include <TGNumberEntry.h>
56#include <TGLayout.h>
57#include <TRootEmbeddedCanvas.h>
58#include <TGSplitter.h>
59#include <TGButtonGroup.h>
60#include <TGLabel.h>
61#include <TGTab.h>
62#include <TGString.h>
63
64//AliRoot includes
65#include <AliLog.h>
66#include "AliTPCCalibViewerGUI.h"
67#include "AliTPCCalibViewer.h"
68#include "AliTPCcalibDB.h"
69#include "AliTPCcalibDButil.h"
70#include "AliTPCConfigParser.h"
71
72#include "AliTPCCalibViewerGUItime.h"
73
74ClassImp(AliTPCCalibViewerGUItime)
75
76AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
77TGCompositeFrame(p,w,h),
78 fFile(0x0),
79 fTree(0x0),
80 fCalibViewerGUI(0x0),
81 fCalibViewerGUItab(0x0),
82 fCurrentHist(0x0),
83 fCurrentGraph(0x0),
84 fCurrentRunDetails(-1),
85 fOutputCacheDir("/tmp"),
86 fDrawString(""),
87 fConfigFile(""),
88 fConfigParser(new AliTPCConfigParser),
89 fIsCustomDraw(kFALSE),
90 fRunNumbers(10),
91 fTimeStamps(10),
92 fValuesX(10),
93 fValuesY(10),
94 fNoGraph(kFALSE),
95 fGraphLimitEntries(10000),
96 fMapRefTrees(new TMap),
97 //GUI elements
98 //main canvas Top part, bottom part
99 fContTopBottom(0x0),
100 //top left, centre, right
101 fContLCR(0x0),
102 //content left
103 fContLeft(0x0),
104 fContDrawOpt(0x0),
105 fChkDrawOptSame(0x0),
106 fComboAddDrawOpt(0x0),
107 fContDrawSel(0x0),
108 fContDrawSelSubRunTime(0x0),
109 fRadioXhist(0x0),
110 fRadioXrun(0x0),
111 fRadioXtime(0x0),
112 fListVariables(0x0),
113 fComboRunType(0x0),
114 fLblRunType(0x0),
115 fNmbPar(0x0),
116 fLblPar(0x0),
117 fListCalibType(0x0),
118 fContCalibType(0x0),
119 //content centre
120 fContCenter(0x0),
121 fCanvMain(0x0),
122 //content right
123 fContRight(0x0),
124 fContValues(0x0),
125 fLblRunNumber(0x0),
126 fLblRunTime(0x0),
127 fLblValueX(0x0),
128 fLblValueY(0x0),
129 fLblRunNumberVal(0x0),
130 fLblRunTimeVal(0x0),
131 fLblValueXVal(0x0),
132 fLblValueYVal(0x0),
133 fBtnDumpRuns(0x0),
134 fContAliases(0x0),
135 fListAliases(0x0),
136 //content bottom
137 fContCustom(0x0),
138 fContCustomCuts(0x0),
139 fLblCustomDraw(0x0),
140 fLblCustomCuts(0x0),
141 fComboCustomDraw(0x0),
142 fComboCustomCuts(0x0),
143 fTrashBox(new TObjArray)
144{
145 //
146 // ctor
147 //
148 fMapRefTrees->SetOwnerKeyValue();
149 fTrashBox->SetOwner();
150 DrawGUI(p,w,h);
151 gStyle->SetMarkerStyle(20);
152 gStyle->SetMarkerSize(0.5);
153 SetInitialValues();
154}
155//______________________________________________________________________________
156AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
157 //
158 // dtor
159 //
160 delete fConfigParser;
161 delete fTrashBox;
162 delete fMapRefTrees;
163}
164//______________________________________________________________________________
165void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
166 //
167 // draw the GUI
168 //
169 // ======================================================================
170 // ************************* Display everything *************************
171 // ======================================================================
172
173 SetCleanup(kDeepCleanup);
174
175 // *****************************************************************************
176 // ************************* content of this MainFrame *************************
177 // *****************************************************************************
178 // top level container with horizontal layout
179 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
180 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
181
182 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
183 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
184
185 // ***********************************************************************
186 // ************************* content of fContLCR *************************
187 // ***********************************************************************
188 // left container
189 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
190 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
191
192 // left vertical splitter
193 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
194 splitLeft->SetFrame(fContLeft, kTRUE);
195 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
196
197 // right container
198 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
199 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
200
201 // center container
202 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
203 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
204
205 // right vertical splitter
206 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
207 splitRight->SetFrame(fContRight, kFALSE);
208 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
209
210
211 // ========================================================================
212 // ************************* content of fContLeft *************************
213 // ========================================================================
214 // --- draw button and tabLeft ---
215 // draw options
216 fContDrawOpt = new TGGroupFrame(fContLeft, "Draw options", kVerticalFrame | kFitWidth | kFitHeight);
217 fContLeft->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
218 fChkDrawOptSame = new TGCheckButton(fContDrawOpt, "Same");
219 fContDrawOpt->AddFrame(fChkDrawOptSame, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
220 fChkDrawOptSame->SetToolTipText("Add draw option 'same'");
221 // additional draw options combo box
222 fComboAddDrawOpt = new TGComboBox(fContDrawOpt);
223 fComboAddDrawOpt->Resize(0, 22);
224 fComboAddDrawOpt->EnableTextInput(kTRUE);
225 fContDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
226// fComboAddDrawOpt->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral(=14)");
227// fComboAddDrawOpt->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
228 fComboAddDrawOpt->GetTextEntry()->SetText("",kFALSE);
229
230 // draw selection group
231 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
232 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
233 //x-axis variables selection, Run of Time
234 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
235 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
236
237 // ------------------------- content of fContDrawOpt -------------------------
238 //
239 // Run radio button
240 // Time radio button
241 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
242 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
243 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
244 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
245
246 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
247 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
248 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
249 fRadioXrun->SetToolTipText("Use run number as x-value");
250
251 // Time radio button
252 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
253 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
254 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
255 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
256
257
258 // list of variables
259 fListVariables = new TGListBox(fContDrawSel);
260 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
261 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
262
263
264//-------------------- run type selection ------------------------
265 // Parameter label
266 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
267 fLblRunType->SetTextJustify(kTextLeft);
268 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
269
270 fComboRunType = new TGComboBox(fContDrawSel);
271 fComboRunType->EnableTextInput(kFALSE);
272 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
273 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
274// fComboRunType->SetEnabled(kFALSE);
275 fComboRunType->Resize(0, 22);
276
277 //-------------------- parameter selection ------------------------
278 // Parameter label
279 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
280 fLblPar->SetTextJustify(kTextLeft);
281 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
282
283 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
284 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
285 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
286 fNmbPar->SetState(kFALSE);
287
288 //-------------------- calibration type selection ------------------------
289 // label
290 // draw selection group
291 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
292 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
293
294 // list of variables
295 fListCalibType = new TGListBox(fContCalibType);
296 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
297 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
298 fListCalibType->Resize(0,88);
299 fListCalibType->SetMultipleSelections();
300
301
302 // ==========================================================================
303 // ************************* content of fContCenter *************************
304 // ========================================================================
305 // main drawing canvas
306 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
307 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
308 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
309// fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
310 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
311 fCanvMain->GetCanvas()->SetRightMargin(0.062);
312 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
313
314 // =========================================================================
315 // ************************* content of fContRight *************************
316 // ========================================================================
317 //group frame for value information
318 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
319 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
320 //set layout manager
321 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
322 //value information labels
323
324 //run number label
325 fLblRunNumber = new TGLabel(fContValues, "Run:");
326 fLblRunNumber->SetTextJustify(kTextLeft);
327 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
328 //run number
329 fLblRunNumberVal = new TGLabel(fContValues, "000000");
330 fLblRunNumberVal->SetTextJustify(kTextLeft);
331 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
332 //time stamp label
333 fLblRunTime = new TGLabel(fContValues, "Time:");
334 fLblRunTime->SetTextJustify(kTextLeft);
335 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
336 //run number
337 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
338 fLblRunTimeVal->SetTextJustify(kTextLeft);
339 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
340 //value label x
341 fLblValueX = new TGLabel(fContValues, "x-Value:");
342 fLblValueX->SetTextJustify(kTextLeft);
343 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
344 //value x
345 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
346 fLblValueXVal->SetTextJustify(kTextRight);
347 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
348 //value label y
349 fLblValueY = new TGLabel(fContValues, "y-Value:");
350 fLblValueY->SetTextJustify(kTextLeft);
351 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
352 //value y
353 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
354 fLblValueYVal->SetTextJustify(kTextRight);
355 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
356 // draw button
357 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
358 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
359 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
360 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
361 //group frame for value information
362 fContAliases = new TGGroupFrame(fContRight, "Aliases", kVerticalFrame | kFitWidth | kFitHeight);
363 fContRight->AddFrame(fContAliases, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
364 // list of aliases
365 fListAliases = new TGListBox(fContAliases);
366 fContAliases->AddFrame(fListAliases, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
367 fListAliases->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelectionAliases()");
368// fListAliases->Resize(0,88);
369 //buttons
370 TGCompositeFrame *frame1 = new TGCompositeFrame(fContAliases, 200, 23, kHorizontalFrame | kFitWidth | kFitHeight);
371 fContAliases->AddFrame(frame1, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
372 // add button
373 TGTextButton *btnAdd = new TGTextButton(frame1, "&Add");
374 frame1->AddFrame(btnAdd, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
375 btnAdd->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoAddAlias()");
376 btnAdd->SetToolTipText("Press to add an alias.");
377 btnAdd->Resize(0,22);
378 // del button
379 TGTextButton *btnDel = new TGTextButton(frame1, "&Del");
380 frame1->AddFrame(btnDel, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
381 btnDel->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDelAlias()");
382 btnDel->SetToolTipText("Press to delete the selected alias.");
383 btnDel->Resize(0,22);
384 // update button
385 TGTextButton *btnUp = new TGTextButton(frame1, "&Upd");
386 frame1->AddFrame(btnUp, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
387 btnUp->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "UpdateAliasList()");
388 btnUp->SetToolTipText("Press to update the alias list.");
389 btnUp->Resize(0,22);
390
391
392
393 // =========================================================================
394 // ****************** bottom content of fContTopBottom *********************
395 // =========================================================================
396
397 // custom options container
398 // --- fComboCustom --- the custom draw line on the very low
399 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
400 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
401
402 // ------------------------- content of fContCustom -------------------------
403 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
404 fLblCustomDraw->SetTextJustify(kTextLeft);
405 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
406 // text field for custom draw command
407 fComboCustomDraw = new TGComboBox(fContCustom);
408// fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
409 fComboCustomDraw->Resize(0, 22);
410 fComboCustomDraw->EnableTextInput(kTRUE);
411 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
412 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
413 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
414 fComboCustomDraw->GetTextEntry()->SetText("",kFALSE);
415
416 // additional cuts container
417 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
418 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
419
420 // ------------------------- content of fContCustomCuts -------------------------
421 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
422 fLblCustomCuts->SetTextJustify(kTextLeft);
423 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
424 // combo text field for additional cuts
425 fComboCustomCuts = new TGComboBox(fContCustomCuts);
426// fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
427 fComboCustomCuts->Resize(0, 22);
428 fComboCustomCuts->EnableTextInput(kTRUE);
429 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
430 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
431 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
432 fComboCustomCuts->GetTextEntry()->SetText("",kFALSE);
433
434 SetWindowName("AliTPCCalibViewer GUI - Time");
435 MapSubwindows();
436 Resize(GetDefaultSize());
437 MapWindow();
438}
439//______________________________________________________________________________
440void AliTPCCalibViewerGUItime::SetInitialValues(){
441 //
442 // Set inital selections of the gui
443 //
444 fRadioXrun->SetState(kButtonDown);
445 fRadioXtime->SetState(kButtonUp);
446}
447
448//______________________________________________________________________________
449void AliTPCCalibViewerGUItime::UseFile(const char* fileName, const char* treeName) {
450 //
451 // retrieve tree from file
452 //
453 TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
454// TString s(fileName);
455 TObjArray *arr=s.Tokenize("\n");
456 TIter next(arr);
457 TObject *o=0;
458 if (fTree) delete fTree;
459 fTree=new TChain(treeName);
460 while ( (o=next()) ){
461 fTree->AddFile(o->GetName());
462 }
463 delete arr;
464 if (!CheckChain()) return;
465 UseConfigFile(fConfigFile.Data());
466 Reload();
467
468}
469//______________________________________________________________________________
470void AliTPCCalibViewerGUItime::UseChain(TChain *const chain = 0)
471{
472 //
473 //
474 //
475 fTree=chain;
476 if (!CheckChain()) return;
477 //set configuration file
478 UseConfigFile(fConfigFile.Data());
479 Reload();
480}
481//______________________________________________________________________________
482Bool_t AliTPCCalibViewerGUItime::CheckChain()
483{
484 //
485 // check whether cahin has entries
486 // decide whether to draw graphs in 2D
487 //
488 if (!fTree) return kFALSE;
489 fTree->Lookup();
490 Long64_t entries=fTree->GetEntries();
491 if (entries==0){
492 AliError("No entries found in chain");
493 return kFALSE;
494 }
495 //check whether to draw graphs
496 CheckDrawGraph();
497 return kTRUE;
498}
499//______________________________________________________________________________
500void AliTPCCalibViewerGUItime::UseConfigFile(const char* file)
501{
502 //
503 // Use 'file' as configuration file
504 //
505 fConfigFile=file;
506 fConfigParser->ParseConfigFileTxt(fConfigFile.Data());
507 FillCalibTypes();
508}
509//______________________________________________________________________________
510void AliTPCCalibViewerGUItime::FillRunTypes()
511{
512 //
513 //Loop over the tree entries and fill the run types
514 //
515 if (!fTree) return;
516 Int_t id=0;
517 fComboRunType->RemoveAll();
518 fComboRunType->AddEntry("ALL",id++);
519 fComboRunType->Select(0,kFALSE);
520 if (!fTree->GetBranch("runType.")) return;
521 TObjString *runType=0x0;
522 Int_t nevets=fTree->GetEntries();
523 fTree->SetBranchStatus("*",0);
524 fTree->SetBranchStatus("runType.*",1);
525 fTree->SetBranchAddress("runType.",&runType);
526 for (Int_t iev=0;iev<nevets;++iev){
527 fTree->GetEntry(iev);
528 TString type=runType->String();
529 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
530 }
531 fTree->ResetBranchAddresses();
532 fTree->SetBranchStatus("*",1);
533}
534//______________________________________________________________________________
535void AliTPCCalibViewerGUItime::FillCalibTypes()
536{
537 //
538 // loop over configuration and fill calibration types
539 //
540 Int_t id=0;
541 fListCalibType->RemoveAll();
542 TObject *o=0x0;
543 fConfigParser->ResetIter();
544 TString type;
545 while ( (o=fConfigParser->NextKey()) ){
546 type=fConfigParser->GetData(o,kCalibType);
547 //remove whitespcaces
548 type.Remove(TString::kBoth,' ');
549 type.Remove(TString::kBoth,'\t');
550 if (type.IsNull()) type="UNSPECIFIED";
551// printf("CalibType: '%s'\n",type.Data());
552 if (!fListCalibType->FindEntry(type.Data())) {
553 fListCalibType->AddEntry(type.Data(),id);
554 fListCalibType->Select(id++);
555 }
556 }
557 //add type for unspecified calibration type
558 type="UNSPECIFIED";
559 if (!fListCalibType->FindEntry(type.Data())) {
560 fListCalibType->AddEntry(type.Data(),id);
561 fListCalibType->Select(id++);
562 }
563}
564//______________________________________________________________________________
565void AliTPCCalibViewerGUItime::CheckDrawGraph()
566{
567 //
568 // Check whether to draw graphs in 2D mode based on the number of entries in the chain
569 // GetEstimate() returns the maximum size of the arrays stored in GetV1()...
570 //
571 if (!fTree) return;
572 fNoGraph=kTRUE;
573 if (fTree->GetEntries()<fTree->GetEstimate()) fNoGraph=kFALSE;
574}
575//______________________________________________________________________________
576void AliTPCCalibViewerGUItime::Reload(Int_t first)
577{
578 //
579 // reload the gui contents, this is needed after the input tree has changed
580 //
581
582 if ( !fTree ) return;
583 //in case of the first call create run type and calibration type entries
584 if (first){
585 FillRunTypes();
586 FillCalibTypes();
587 }
588 //activate all branches
589 fTree->SetBranchStatus("*",1);
590 //reset variables list
591 fListVariables->RemoveAll();
592 //get selected calibration types
593 TList calibTypes;
594 fListCalibType->GetSelectedEntries(&calibTypes);
595
596 TObjArray *branchList = fTree->GetListOfBranches();
597 if ( !branchList ) return;
598 TIter nextBranch(branchList);
599 Int_t idCount=0,id=0;
600 TObject *objBranch=0;
601 while ( (objBranch=nextBranch()) ){
602 TString branchName(objBranch->GetName());
603 TString branchTitle(objBranch->GetName());
604 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
605 Bool_t active=kTRUE;
606 TString calibType="UNSPECIFIED";
607 if (fConfigParser){
608 const TObject *key=(*fConfigParser)(branchName.Data());
609 if (key){
610 //test if branch is active
611 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
612 id=(*fConfigParser)()->IndexOf(key);
613// branchTitle=fConfigParser->GetData(key,kBranchTitle);
614 calibType=fConfigParser->GetData(key,kCalibType);
615 }
616 else{
617 id=1000+idCount;
618 }
619 } else {
620 id=idCount;
621 }
622 if (calibType.IsNull()) calibType="UNSPECIFIED";
623 //check if branch is in selected calibration types
624 //if not, don't show it in the list and deactivate the branch.
625 Bool_t calibActive=kFALSE;
626 TIter nextCalib(&calibTypes);
627 TObject *objCalib=0;
628 while ( (objCalib=nextCalib()) )
629 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
630 active&=calibActive;
631 if (!active){
632 TString s=branchName;
633 if (branchName.EndsWith(".")) s+="*";
634// fTree->SetBranchStatus(s.Data(),0);
635 continue;
636 }
637// fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
638 fListVariables->AddEntry(branchTitle.Data(),id);
639 ++idCount;
640 }
641 //trick to display modifications
642 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
643 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
644}
645//______________________________________________________________________________
646void AliTPCCalibViewerGUItime::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 TString AliTPCCalibViewerGUItime::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()) return "";
663 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
664 id=fListVariables->GetSelectedEntry()->EntryId();
665// printf("id: %d\n",id);
666 TString branchName=selectedVariable;
667 if (fConfigParser){
668 const TObject *key=(*fConfigParser)(id);
669 if (key) branchName=(*fConfigParser)(id)->GetName();
670 }
671 //treat case of TVector
672 if (branchName.EndsWith(".")){
673 Int_t par = (Int_t)(fNmbPar->GetNumber());
674 branchName.Append(Form("fElements[%d]",par));
675 }
676// if (fRadioXrun->GetState()==kButtonDown)
677// selectedVariable.Append(":run");
678// if (fRadioXtime->GetState()==kButtonDown)
679// selectedVariable.Append(":time");
680
681 return branchName;
682}
683//______________________________________________________________________________
684const TString AliTPCCalibViewerGUItime::GetDrawOptionString(){
685 //
686 // get user selected draw options
687 //
688 TString drawOpt;
689 if (fComboAddDrawOpt->GetSelectedEntry()) drawOpt=fComboAddDrawOpt->GetSelectedEntry()->GetTitle();
690 if (fChkDrawOptSame->GetState()==kButtonDown && !drawOpt.Contains("same",TString::kIgnoreCase))
691 drawOpt+="same";
692 return drawOpt;
693}
694//______________________________________________________________________________
695void AliTPCCalibViewerGUItime::GetCutString(TString &cutStr){
696 //
697 // create cut string
698 //
699 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
700 TString runType="";
701 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
702 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
703 cutStr=cuts.GetTitle();
704}
705//______________________________________________________________________________
706void AliTPCCalibViewerGUItime::UpdateValueArrays(Bool_t withGraph, const Double_t *xArr)
707{
708 //
709 //
710 //
711 if (!withGraph){
712 fValuesX.ResizeTo(1);
713 fValuesY.ResizeTo(1);
714 fRunNumbers.ResizeTo(1);
715 fTimeStamps.ResizeTo(1);
716 } else {
717 const Long64_t nrows=fTree->GetSelectedRows();
718 fValuesX.ResizeTo(nrows);
719 fValuesY.ResizeTo(nrows);
720 fRunNumbers.ResizeTo(nrows);
721 fTimeStamps.ResizeTo(nrows);
722 long long *index=new long long[nrows];
723 TMath::Sort(nrows,fTree->GetV2(),index,kFALSE);
724 for (Long64_t i=0; i<nrows; ++i){
725 fValuesX.GetMatrixArray()[i]=xArr[index[i]];
726 fValuesY.GetMatrixArray()[i]=fTree->GetV3()[index[i]];
727 fRunNumbers.GetMatrixArray()[i]=fTree->GetV1()[index[i]];
728 fTimeStamps.GetMatrixArray()[i]=fTree->GetV2()[index[i]];
729 }
730 delete [] index;
731 }
732}
733//______________________________________________________________________________
734void AliTPCCalibViewerGUItime::GetHistogramTitle(TString &title)
735{
736 //
737 // Create string for histogram title
738 //
739
740 title=fDrawString;
741 Int_t pos=title.First(">>");
742 if (pos>0) title=title(0,pos);
743// if (!fIsCustomDraw){
744 if (fRadioXrun->GetState()==kButtonDown){
745 title+=":Run";
746 } else if (fRadioXtime->GetState()==kButtonDown){
747 title+=":Date";
748 }
749// }
750 TString cuts;
751 GetCutString(cuts);
752 TObjArray *arr=title.Tokenize(":");
753 TObject *o=0x0;
754 title+=" {";
755 title+=cuts;
756 title+="}";
757 TIter next(arr,kIterBackward);
758 while ( (o=next()) ){
759 TString varName=o->GetName();
760 title+=";";
761 //substitue variable names with names in configuration file if available
762 if ((*fConfigParser)()->GetEntries()){
763 TString branchName=varName;
764 Int_t par=0;
765 if (branchName.Contains('.')) branchName=branchName(0,branchName.First('.')+1);
766 //chek if a configuration for that branch is available
767 const TObject *oBranch=(*fConfigParser)(branchName.Data());
768 if (oBranch){
769 TString branchTitle=fConfigParser->GetData(oBranch,kBranchTitle);
770 if (!branchTitle.IsNull()){
771 //check for TVectorT type branch
772 //add parameter name if available
773 if (varName.Contains("fElements")){
774 TString parStr=varName(varName.First('[')+1,varName.Length()-varName.First('[')-2);
775 par=parStr.Atoi();
776 branchTitle+=": ";
777 TString yparname=fConfigParser->GetData(oBranch,par+kParamNames);
778 if (!yparname.IsNull()){
779 branchTitle+=yparname;
780 } else {
781 branchTitle+="[";
782 branchTitle+=par;
783 branchTitle+="]";
784 }
785 }
786 }
787 varName=branchTitle;
788 SubstituteUnderscores(varName);
789 }
790 }
791 title+=varName;
792 }
793 delete arr;
794}
795//______________________________________________________________________________
796void AliTPCCalibViewerGUItime::AdjustYRange()
797{
798 //
799 //
800 //
801 TIter nextGraphicObject(fTrashBox);
802 TObject *o=0x0;
803 Float_t min=0,max=0;
804 while ( (o=nextGraphicObject()) ){
805 if (o->IsA()==TGraph::Class()){
806 TGraph *gr=(TGraph*)o;
807 if (min==max) {
808 min=TMath::MinElement(gr->GetN(),gr->GetY());
809 max=TMath::MaxElement(gr->GetN(),gr->GetY());
810 } else {
811 Float_t currmin=TMath::MinElement(gr->GetN(),gr->GetY());
812 Float_t currmax=TMath::MaxElement(gr->GetN(),gr->GetY());
813 if (currmax>max) max=currmax;
814 if (currmin<min) min=currmin;
815 }
816 }
817 }
818 if (min!=max){
819 if (min!=0) min=min-(max-min)/10;
820 if (max!=0) max=max+(max-min)/10;
821 fCurrentHist->SetMinimum(min);
822 fCurrentHist->SetMaximum(max);
823 }
824}
825//______________________________________________________________________________
826void AliTPCCalibViewerGUItime::DoDraw() {
827 //
828 // Draw graphics
829 //
830 TString drawString=fDrawString;
831 TString cutString;
832 GetCutString(cutString);
833 TString optString = GetDrawOptionString();
834 Bool_t graphOutput=!fNoGraph; //ttree buffer for V1, V2... too small
835 graphOutput&=(drawString.First(">>")<0); //histogram output in custom draw
836 graphOutput&=fRadioXhist->GetState()!=kButtonDown; //histogram drawing selected
837// graphOutput&=!(fIsCustomDraw&&!fDrawString.Contains(":")); //custom draw 1D
838// graphOutput&=fDrawString.CountChar(':')<2; //custom draw 1D
839 if (fIsCustomDraw&&fDrawString.Contains(":")) HandleButtonsDrawSel(-kRadioXhist);
840 if (fIsCustomDraw&&fDrawString.Contains(":")) HandleButtonsDrawSel(-kRadioXhist);
841 Bool_t drawSame=optString.Contains("same",TString::kIgnoreCase);
842// optString+="goff";
843 if (graphOutput) {
844 drawString.Prepend("run:time:");
845 optString="goff";
846 }else{
847// if (!fIsCustomDraw){
848 if (fRadioXrun->GetState()==kButtonDown){
849 drawString+=":run";
850 } else if (fRadioXtime->GetState()==kButtonDown){
851 drawString+=":time";
852 }
853// }
854 }
855 TVirtualPad *padsave=gPad;
856 fCanvMain->GetCanvas()->cd();
857 //delete old histograms and graphs
858 if (!drawSame){
859 fTrashBox->Delete();
860 fCurrentGraph=0x0;
861 fCurrentHist=0x0;
862 }
863// printf("%s (%s) [%s]\n",drawString.Data(), cutString.Data(), optString.Data());
864 //select data
865 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
866 if (fTree->GetSelectedRows()==-1) return;
867
868 TString title;
869 GetHistogramTitle(title);
870 Bool_t drawGraph=kFALSE;
871 Double_t *xArr=0;
872 if (graphOutput){
873 drawGraph=kTRUE;
874 if (fIsCustomDraw&&fDrawString.Contains(":")){
875// fValuesX.SetElements(fTree->GetV4());
876 xArr=fTree->GetV4();
877 }else{
878 if (fRadioXrun->GetState()==kButtonDown){
879// fValuesX.SetElements(fTree->GetV1());
880 xArr=fTree->GetV1();
881 } else if (fRadioXtime->GetState()==kButtonDown){
882// fValuesX.SetElements(fTree->GetV2());
883 xArr=fTree->GetV2();
884 } else {
885 drawGraph=kFALSE;
886 }
887 }
888 }
889 if (xArr) UpdateValueArrays(graphOutput, xArr);
890// if (graphOutput){
891// if (fIsCustomDraw){
892// if (fDrawString.Contains(":")){
893// fValuesX.SetElements(fTree->GetV4());
894// drawGraph=kTRUE;
895// } else {
896// drawGraph=kFALSE;
897// }
898// }else{
899// drawGraph=kTRUE;
900// if (fRadioXrun->GetState()==kButtonDown){
901// fValuesX.SetElements(fTree->GetV1());
902// } else if (fRadioXtime->GetState()==kButtonDown){
903// fValuesX.SetElements(fTree->GetV2());
904// } else {
905// drawGraph=kFALSE;
906// }
907// }
908// }
909//create graph according to selection
910 if (drawGraph){
911 TGraph *graph=new TGraph(fValuesX,fValuesY);
912 TString grDraw="p";
913 if (!drawSame) grDraw+="a";
914 if (!fIsCustomDraw) grDraw+="l";
915 graph->Draw(grDraw.Data());
916 graph->SetEditable(kFALSE);
917 TH1 *hist=graph->GetHistogram();
918 hist->SetTitle(title.Data());
919 fTrashBox->Add(graph);
920 graph->SetLineColor(fTrashBox->GetEntries());
921 graph->SetMarkerColor(fTrashBox->GetEntries());
922 if (!drawSame) {
923 fCurrentGraph=graph;
924 fCurrentHist=hist;
925 }
926 } else {
927 TH1 *hist=fTree->GetHistogram();
928 hist->SetTitle(title.Data());
929// hist->Draw(optString.Data());
930 fTrashBox->Add(hist);
931 hist->SetLineColor(fTrashBox->GetEntries());
932 hist->SetMarkerColor(fTrashBox->GetEntries());
933 if (!drawSame) fCurrentHist=hist;
934 }
935
936 //Set time axis if choosen as x-variables
937// if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw&&!drawSame){
938 if (fRadioXtime->GetState()==kButtonDown&&!drawSame){
939 TAxis *xaxis=fCurrentHist->GetXaxis();
940 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
941 xaxis->SetTimeDisplay(1);
942 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
943 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
944 }
945 if (!drawSame) {
946 //Set title offset
947 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
948 } else {
949 //adjust y-range
950 AdjustYRange();
951 }
952 gPad->Modified();
953 gPad->Update();
954 padsave->cd();
955}
956
957//______________________________________________________________________________
958void AliTPCCalibViewerGUItime::DoDumpRuns()
959{
960 //
961 // Dump the current run numbers to stdout
962 //
963 Int_t npoints=fRunNumbers.GetNrows();
964 Int_t *sortIndex = new Int_t[npoints];
965 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
966 Int_t run=0, prevRun=-1;
967
968 for (Int_t irun=0;irun<npoints;++irun){
969 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
970 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
971 prevRun=run;
972 }
973 delete [] sortIndex;
974}
975//______________________________________________________________________________
976void AliTPCCalibViewerGUItime::DoParLimitChange()
977{
978 //
979 //
980 //
981 UpdateParName();
982 DoDraw();
983}
984//______________________________________________________________________________
985void AliTPCCalibViewerGUItime::DoNewSelection() {
986 //
987 // decides whether to redraw if user makes another selection
988 //
989 UpdateParLimits();
990 fDrawString=GetDrawString();
991 fIsCustomDraw=kFALSE;
992 DoDraw();
993}
994//______________________________________________________________________________
995void AliTPCCalibViewerGUItime::DoCustomDraw()
996{
997 //
998 //
999 //
1000 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
1001// if (fDrawString.Contains(">>")){
1002// Warning("DoCustomDraw","Currently no user defined histograms allowed!");
1003// return;
1004// }
1005 fNmbPar->SetState(kFALSE);
1006 fIsCustomDraw=kTRUE;
1007 DoDraw();
1008}
1009//______________________________________________________________________________
1010void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
1011{
1012 //
1013 //
1014 //
1015 if (fIsCustomDraw) DoCustomDraw();
1016 else {
1017 fDrawString=GetDrawString();
1018 fIsCustomDraw=kFALSE;
1019 DoDraw();
1020 }
1021}
1022//______________________________________________________________________________
1023void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
1024{
1025 //
1026 // Draw selection button handling (x-variable)
1027 //
1028
1029 if (id == -1) {
1030 TGButton *btn = (TGButton *) gTQSender;
1031 id = btn->WidgetId();
1032 }
1033
1034 Bool_t doDraw=kFALSE;
1035 Bool_t noDraw=kFALSE;
1036 if (id<-1){
1037 noDraw=kTRUE;
1038 id=TMath::Abs(id);
1039 }
1040 switch (id) {
1041 case (kRadioXhist):
1042 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
1043 if (doDraw){
1044 fRadioXrun->SetState(kButtonUp);
1045 fRadioXtime->SetState(kButtonUp);
1046 fRadioXhist->SetState(kButtonDown);
1047 }
1048 break;
1049 case (kRadioXrun):
1050 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
1051 if (doDraw){
1052 fRadioXhist->SetState(kButtonUp);
1053 fRadioXtime->SetState(kButtonUp);
1054 fRadioXrun->SetState(kButtonDown);
1055 }
1056 break;
1057 case (kRadioXtime):
1058 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
1059 if (doDraw){
1060 fRadioXrun->SetState(kButtonUp);
1061 fRadioXhist->SetState(kButtonUp);
1062 fRadioXtime->SetState(kButtonDown);
1063 }
1064 break;
1065 }
1066 if (doDraw&&!noDraw) DoCustomCutsDraw();
1067}
1068//______________________________________________________________________________
1069void AliTPCCalibViewerGUItime::UpdateParName()
1070{
1071 //
1072 // change parameter name
1073 //
1074
1075 Int_t par = (Int_t)(fNmbPar->GetNumber());
1076 TString parName="";
1077 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
1078 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
1079 if (parName=="") parName.Form("%d",par);
1080 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
1081 fDrawString=GetDrawString();
1082 fIsCustomDraw=kFALSE;
1083}
1084
1085//______________________________________________________________________________
1086void AliTPCCalibViewerGUItime::UpdateParLimits()
1087{
1088 //
1089 // Adjust limits for TVectorT based variables
1090 //
1091 if (!fTree) return;
1092 TString selectedVariableTitle="";
1093 Int_t id=-1;
1094 if (!fListVariables->GetSelectedEntry()) return;
1095 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
1096 id=fListVariables->GetSelectedEntry()->EntryId();
1097// printf("id: %d\n",id);
1098 TString selectedVariable=selectedVariableTitle;
1099 const TObject *key=(*fConfigParser)(id);
1100 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
1101
1102 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
1103 fNmbPar->SetState(kFALSE);
1104 fLblPar->SetText("Parameter: none");
1105 return;
1106 }
1107 TVectorD *vD=0x0;
1108 TVectorF *vF=0x0;
1109 Int_t maxPar=0;
1110 fTree->GetEntry(1);
1111 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
1112 TString branchClass=branch->GetClassName();
1113 Int_t event=0;
1114 if (branchClass=="TVectorT<double>"){
1115// branch->SetAddress(&vD);
1116 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
1117 while (maxPar<2&&event<fTree->GetEntries()){
1118 fTree->GetEntry(event++);
1119 maxPar=vD->GetNrows();
1120 }
1121 } else if (branchClass=="TVectorT<float>"){
1122// branch->SetAddress(&vF);
1123 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
1124 while (maxPar<2&&event<fTree->GetEntries()){
1125 fTree->GetEntry(event++);
1126 maxPar=vF->GetNrows();
1127 }
1128 } else {
1129 //class not known
1130 fNmbPar->SetState(kFALSE);
1131 return;
1132 }
1133// branch->ResetAddress();
1134 fTree->SetBranchAddress(selectedVariable.Data(),0x0);
1135 if (fNmbPar->GetNumMax()!=maxPar-1) fNmbPar->SetNumber(0);
1136 fNmbPar->SetLimitValues(0,maxPar-1);
1137 fNmbPar->SetState(kTRUE);
1138 UpdateParName();
1139}
1140//______________________________________________________________________________
1141void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
1142{
1143 //
1144 // handle mouse events in the draw canvas
1145 //
1146 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
1147 Double_t valx=0.,valy=0.;
1148 if (!fCurrentGraph) {
1149 fLblRunNumberVal->SetText(Form("%06u",run));
1150 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
1151 fLblValueXVal->SetText(Form("%.3e", valx));
1152 fLblValueYVal->SetText(Form("%.3e", valy));
1153 return;
1154 }
1155 TVirtualPad *padsave=gPad;
1156 fCanvMain->GetCanvas()->cd();
1157 Int_t n=fValuesY.GetNrows();
1158 Double_t *arr=0x0;
1159 arr=fValuesX.GetMatrixArray();
1160
1161 Int_t minDist=1000000;
1162 Int_t minPoint=-1;
1163 for (Int_t i=0;i<n;++i){
1164 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
1165 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
1166 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
1167 if (d < minDist) {
1168 minDist = d;
1169 minPoint = i;
1170 }
1171 }
1172 if (minDist<2){
1173 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
1174 t.GetDate(kTRUE,0,&yy,&mm,&dd);
1175 t.GetTime(kTRUE,0,&HH,&MM,&SS);
1176 run=(UInt_t)fRunNumbers[minPoint];
1177 valx=fValuesX[minPoint];
1178 valy=fValuesY[minPoint];
1179 } else {
1180 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
1181 valx=0.;
1182 valy=0.;
1183 }
1184 fLblRunNumberVal->SetText(Form("%06u",run));
1185 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
1186 if (fIsCustomDraw){
1187 fLblValueXVal->SetText(Form("%.3e", valx));
1188 }else{
1189 if (fRadioXrun->GetState()==kButtonDown){
1190 fLblValueXVal->SetText("Run");
1191 } else if (fRadioXtime->GetState()==kButtonDown){
1192 fLblValueXVal->SetText("Time");
1193 }
1194 }
1195 fLblValueYVal->SetText(Form("%.3e", valy));
1196 padsave->cd();
1197 if (run==0) return;
1198 if (event == kButton1Double ){
1199 SetGuiTree(run);
1200 }
1201 //find closes point of current selection
1202}
1203//______________________________________________________________________________
1204void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
1205{
1206 //
1207 // create the AliTPCCalibViewerGUI tree for run
1208 // cache tree in directory fOutputCacheDir
1209 // retrieve file from this directory if it already exists
1210 //
1211
1212 //
1213 //Create and set GUI tree
1214 //
1215 //try to find file for run in fOutputCacheDir
1216 TString fileName=fOutputCacheDir;
1217 if (!fileName.EndsWith("/")) fileName+="/";
1218 fileName+=Form("guiTreeRun_%d.root",run);
1219 Bool_t load=kTRUE;
1220 if (gSystem->AccessPathName(fileName.Data())){
1221 load=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
1222 if (!load){
1223 fCalibViewerGUI->Reset();
1224 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
1225 return;
1226 }
1227 }
1228 fCalibViewerGUI->Initialize(fileName.Data());
1229 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
1230
1231 //
1232 //Create and set Reference GUI tree
1233 //
1234 AliTPCcalibDButil util;
1235 util.SetReferenceRun(run);
1236 fileName=fOutputCacheDir;
1237 if (!fileName.EndsWith("/")) fileName+="/";
1238 fileName+=util.GetGUIRefTreeDefaultName();
1239 //only update if file does not exist
1240 if (gSystem->AccessPathName(fileName.Data())){
1241 util.UpdateRefDataFromOCDB();
1242 util.CreateGUIRefTree(fileName.Data());
1243 }
1244
1245 fCalibViewerGUI->GetViewer()->AddReferenceTree(fileName.Data(),"calPads","Ref");
1246
1247 //
1248 // Process additional reference trees
1249 //
1250 TIter nextRefTree(fMapRefTrees);
1251 TObject *o=0x0;
1252 //Set static reference data
1253 while ( (o=nextRefTree()) ){
1254 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"calPads",o->GetName());
1255 }
1256 fCalibViewerGUI->Reload();
1257}
1258//______________________________________________________________________________
1259void AliTPCCalibViewerGUItime::SubstituteUnderscores(TString &s)
1260{
1261 //
1262 //
1263 //
1264 s.ReplaceAll("_{","|{");
1265 s.ReplaceAll("_"," ");
1266 s.ReplaceAll("|{","_{");
1267}
1268
1269//______________________________________________________________________________
1270void AliTPCCalibViewerGUItime::DoNewSelectionAliases()
1271{
1272 //
1273 //
1274 //
1275 if (!fTree) return;
1276 TList *l=fTree->GetListOfAliases();
1277 if (!l) return;
1278 TString selectedVariable="";
1279 if (!fListAliases->GetSelectedEntry()) return;
1280 selectedVariable = fListAliases->GetSelectedEntry()->GetTitle();
1281 fDrawString=selectedVariable;
1282 fIsCustomDraw=kFALSE;
1283 DoDraw();
1284}
1285//______________________________________________________________________________
1286void AliTPCCalibViewerGUItime::DoAddAlias()
1287{
1288 //
1289 //
1290 //
1291 new AliTPCCalibViewerGUItimeAddAliasFrame(gClient->GetRoot(), fContTopBottom, 400, 200, kVerticalFrame, this);
1292}
1293//______________________________________________________________________________
1294void AliTPCCalibViewerGUItime::DoDelAlias()
1295{
1296 //
1297 //
1298 //
1299 if (!fTree) return;
1300 TList *l=fTree->GetListOfAliases();
1301 if (!l) return;
1302 TString selectedVariable="";
1303 if (!fListAliases->GetSelectedEntry()) return;
1304 selectedVariable = fListAliases->GetSelectedEntry()->GetTitle();
1305 l->Remove(l->FindObject(selectedVariable.Data()));
1306 UpdateAliasList();
1307}
1308
1309//______________________________________________________________________________
1310void AliTPCCalibViewerGUItime::UpdateAliasList()
1311{
1312 //
1313 //
1314 //
1315 printf("UpdateAliasList\n");
1316 if (!fTree) return;
1317 TList *l=fTree->GetListOfAliases();
1318 if (!l) return;
1319 TIter nextAlias(l);
1320 TObject *o;
1321 fListAliases->RemoveAll();
1322 Int_t id=0;
1323 while( (o=nextAlias()) ){
1324 fListAliases->AddEntry(o->GetName(),id++);
1325 }
1326 fListAliases->Resize(fListAliases->GetWidth()-1, fListAliases->GetHeight());
1327 fListAliases->Resize(fListAliases->GetWidth()+1, fListAliases->GetHeight());
1328}
1329//______________________________________________________________________________
1330TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName, const char* treeName) {
1331 //
1332 // Initialize and show GUI for presentation for demonstration purposes
1333 // or for fast standalone use
1334 //
1335 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1336 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1337 frmMain->SetCleanup(kDeepCleanup);
1338
1339 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1340 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1341
1342 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1343 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
1344
1345 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1346 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1347 calibViewerTime->SetConfigFileName("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt");
1348 calibViewerTime->UseFile(fileName, treeName);
1349
1350 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
1351 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1352 calibViewerTime->SetCalibViewerGUI(calibViewer);
1353 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
1354
1355
1356 TObjArray *guiArray = new TObjArray();
1357 guiArray->Add(calibViewerTime);
1358 guiArray->Add(calibViewer);
1359
1360 frmMain->MapSubwindows();
1361 frmMain->Resize();
1362 frmMain->MapWindow();
1363
1364 return guiArray;
1365}
1366
1367//______________________________________________________________________________
1368TObjArray* AliTPCCalibViewerGUItime::ShowGUI(TChain *chain) {
1369 //
1370 // Initialize and show GUI for presentation for demonstration purposes
1371 // or for fast standalone use
1372 //
1373 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1374 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1375 frmMain->SetCleanup(kDeepCleanup);
1376
1377 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1378 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1379
1380 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1381
1382 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1383 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1384 calibViewerTime->UseChain(chain);
1385
1386 TObjArray *guiArray = new TObjArray();
1387 guiArray->Add(calibViewerTime);
1388
1389 frmMain->MapSubwindows();
1390 frmMain->Resize();
1391 frmMain->MapWindow();
1392
1393 return guiArray;
1394}
1395
1396
1397////////////////////////////////////////////////////////////////////////
1398//
1399// GUI Alias frame
1400//
1401////////////////////////////////////////////////////////////////////////
1402
1403
1404ClassImp(AliTPCCalibViewerGUItimeAddAliasFrame)
1405
1406AliTPCCalibViewerGUItimeAddAliasFrame::AliTPCCalibViewerGUItimeAddAliasFrame(const TGWindow *p, const TGWindow *main,
1407 UInt_t w, UInt_t h, UInt_t options,
1408 AliTPCCalibViewerGUItime *gui, TString strAlias) :
1409 fMain(0x0),
1410 fTxt1(0x0),
1411 fTxt2(0x0),
1412 fGUI(0x0)
1413{
1414 fMain = new TGTransientFrame(p, main, w, h, options);
1415 fMain->Connect("CloseWindow()", "AliTPCCalibViewerGUItimeAddAliasFrame", this, "DoCancel()");
1416 fMain->DontCallClose(); // to avoid double deletions.
1417
1418 // use hierarchical cleaning
1419 fMain->SetCleanup(kDeepCleanup);
1420
1421 //layout
1422 TGLayoutHints *l1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
1423 TGLayoutHints *l2 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX, 2, 2, 0, 5);
1424// TGLayoutHints *l3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5);
1425
1426 //input fields
1427 TGCompositeFrame *f1 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame);
1428 fMain->AddFrame(f1, l1);
1429 TGCompositeFrame *frameName = new TGCompositeFrame(f1);
1430 TGCompositeFrame *frameFormula = new TGCompositeFrame(f1);
1431 f1->AddFrame(frameName,l2);
1432 f1->AddFrame(frameFormula,l2);
1433 TGLabel *lblTxt1 = new TGLabel(frameName, "Name:");
1434 TGLabel *lblTxt2 = new TGLabel(frameFormula, "Formula:");
1435 fTxt1 = new TGTextEntry(frameName, new TGTextBuffer(1000));
1436 fTxt2 = new TGTextEntry(frameFormula, new TGTextBuffer(1000));
1437
1438 frameName->AddFrame(lblTxt1, l2);
1439 frameName->AddFrame(fTxt1, l2);
1440 frameFormula->AddFrame(lblTxt2, l2);
1441 frameFormula->AddFrame(fTxt2, l2);
1442
1443 fTxt1->Resize(350, fTxt1->GetDefaultHeight());
1444 fTxt2->Resize(350, fTxt2->GetDefaultHeight());
1445
1446 //ok and cancel buttons
1447 TGHorizontalFrame *frame = new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
1448
1449 TGTextButton *okButton = new TGTextButton(frame, "&Ok", 1);
1450 okButton->Connect("Clicked()", "AliTPCCalibViewerGUItimeAddAliasFrame", this, "DoOK()");
1451 TGTextButton *cancelButton = new TGTextButton(frame, "&Cancel", 2);
1452 cancelButton->Connect("Clicked()", "AliTPCCalibViewerGUItimeAddAliasFrame", this, "DoCancel()");
1453
1454
1455 frame->AddFrame(okButton, l1);
1456 frame->AddFrame(cancelButton, l1);
1457
1458 frame->Resize(150, okButton->GetDefaultHeight());
1459
1460 fMain->AddFrame(frame, new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
1461
1462 fGUI=gui;
1463 TString aliasName, alias;
1464 if (!strAlias.IsNull()){
1465 TChain *c=fGUI->GetChain();
1466 if (c){
1467 TList *l=c->GetListOfAliases();
1468 if (l){
1469 TNamed *d=(TNamed*)l->FindObject(strAlias);
1470 if (d){
1471 aliasName=d->GetName();
1472 alias=d->GetTitle();
1473 }
1474 }
1475 }
1476 }else{
1477 alias=fGUI->GetCustomDrawString();
1478 }
1479 fTxt1->SetText(aliasName.Data(),kFALSE);
1480 fTxt2->SetText(alias.Data(),kFALSE);
1481
1482 fMain->MapSubwindows();
1483 fMain->Resize();
1484
1485 // position relative to the parent's window
1486 fMain->CenterOnParent();
1487
1488 fMain->SetWindowName("Alias Editor");
1489
1490 fMain->MapWindow();
1491
1492}
1493//______________________________________________________________________________
1494AliTPCCalibViewerGUItimeAddAliasFrame::~AliTPCCalibViewerGUItimeAddAliasFrame()
1495{
1496 //
1497 //
1498 //
1499 fMain->DeleteWindow(); // deletes fMain
1500}
1501//______________________________________________________________________________
1502void AliTPCCalibViewerGUItimeAddAliasFrame::DoOK()
1503{
1504 //
1505 //
1506 //
1507 TString aliasName=fTxt1->GetText();
1508 TString alias=fTxt2->GetText();
1509 if (!aliasName.IsNull()&&!alias.IsNull()){
1510 TChain *c=fGUI->GetChain();
1511 if (c){
1512 c->SetAlias(aliasName.Data(),alias.Data());
1513 }
1514 }
1515 fGUI->UpdateAliasList();
1516 delete this;
1517}
1518//______________________________________________________________________________
1519void AliTPCCalibViewerGUItimeAddAliasFrame::DoCancel()
1520{
1521 //
1522 //
1523 //
1524 delete this;
1525}
1526