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