Hotfix for online display GUI application (Matevz)
[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
22#include <iostream>
23//Root includes
24#include <TROOT.h>
25#include <TDirectory.h>
26#include <TStyle.h>
27#include <TCanvas.h>
28#include <TPad.h>
29#include <TVirtualPad.h>
30#include <TObject.h>
31#include <TObjArray.h>
32#include <TObjString.h>
6fb51ca4 33#include <TSystem.h>
5312f439 34#include <TVector.h>
35#include <TH1.h>
36#include <TCut.h>
37#include <TFile.h>
38#include <TTree.h>
e6970ab5 39#include <TChain.h>
5312f439 40#include <TBranch.h>
41#include <TIterator.h>
42#include <TGraph.h>
43#include <TAxis.h>
44#include <TTimeStamp.h>
45#include <TMath.h>
46//
47#include <TGFileDialog.h>
48#include <TGInputDialog.h>
49//
50#include <TGButton.h>
51#include <TGListBox.h>
52#include <TGComboBox.h>
53#include <TGNumberEntry.h>
54#include <TGLayout.h>
55#include <TRootEmbeddedCanvas.h>
56#include <TGSplitter.h>
57#include <TGButtonGroup.h>
58#include <TGLabel.h>
59#include <TGTab.h>
60#include <TGString.h>
61
62//AliRoot includes
6fb51ca4 63#include <AliLog.h>
5312f439 64#include "AliTPCCalibViewerGUI.h"
65#include "AliTPCcalibDB.h"
6fb51ca4 66#include "AliTPCConfigParser.h"
5312f439 67
68#include "AliTPCCalibViewerGUItime.h"
69
70ClassImp(AliTPCCalibViewerGUItime)
71
72AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
73TGCompositeFrame(p,w,h),
74 fFile(0x0),
75 fTree(0x0),
76 fCalibViewerGUI(0x0),
77 fCalibViewerGUItab(0x0),
78 fCurrentHist(0x0),
79 fCurrentGraph(0x0),
80 fCurrentRunDetails(-1),
81 fOutputCacheDir("/tmp"),
82 fDrawString(""),
6fb51ca4 83 fConfigFile("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt"),
84 fConfigParser(0x0),
5312f439 85 fIsCustomDraw(kFALSE),
86 fRunNumbers(10),
87 fTimeStamps(10),
88 fValuesX(10),
89 fValuesY(10),
90 //GUI elements
91 //main canvas Top part, bottom part
92 fContTopBottom(0x0),
93 //top left, centre, right
94 fContLCR(0x0),
95 //content left
96 fContLeft(0x0),
97 fContDrawSel(0x0),
98 fContDrawSelSubRunTime(0x0),
99 fRadioXhist(0x0),
100 fRadioXrun(0x0),
101 fRadioXtime(0x0),
102 fListVariables(0x0),
103 fComboRunType(0x0),
104 fLblRunType(0x0),
105 fNmbPar(0x0),
106 fLblPar(0x0),
6fb51ca4 107 fListCalibType(0x0),
108 fContCalibType(0x0),
5312f439 109 //content centre
110 fContCenter(0x0),
111 fCanvMain(0x0),
112 //content right
113 fContRight(0x0),
114 fContValues(0x0),
115 fLblRunNumber(0x0),
116 fLblRunTime(0x0),
117 fLblValueX(0x0),
118 fLblValueY(0x0),
119 fLblRunNumberVal(0x0),
120 fLblRunTimeVal(0x0),
121 fLblValueXVal(0x0),
122 fLblValueYVal(0x0),
123 fBtnDumpRuns(0x0),
124 //content bottom
125 fContCustom(0x0),
126 fContCustomCuts(0x0),
127 fLblCustomDraw(0x0),
128 fLblCustomCuts(0x0),
129 fComboCustomDraw(0x0),
130 fComboCustomCuts(0x0)
131{
132 //
133 // ctor
134 //
135 DrawGUI(p,w,h);
136 SetInitialValues();
137}
138//______________________________________________________________________________
139AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
140 //
141 // dtor
142 //
143
144}
145//______________________________________________________________________________
6fb51ca4 146void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
5312f439 147 //
148 // draw the GUI
149 //
150 // ======================================================================
151 // ************************* Display everything *************************
152 // ======================================================================
153
154 SetCleanup(kDeepCleanup);
5312f439 155
156 // *****************************************************************************
157 // ************************* content of this MainFrame *************************
158 // *****************************************************************************
159 // top level container with horizontal layout
160 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
161 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
162
163 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
164 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
165
166 // ***********************************************************************
167 // ************************* content of fContLCR *************************
168 // ***********************************************************************
169 // left container
170 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
171 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
172
173 // left vertical splitter
174 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
175 splitLeft->SetFrame(fContLeft, kTRUE);
176 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
177
178 // right container
179 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
180 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
181
182 // center container
183 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
184 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
185
186 // right vertical splitter
187 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
188 splitRight->SetFrame(fContRight, kFALSE);
189 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
190
191
192 // ========================================================================
193 // ************************* content of fContLeft *************************
194 // ========================================================================
195 // --- draw button and tabLeft ---
196
197 // draw selection group
198 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
199 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
200 //x-axis variables selection, Run of Time
201 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
202 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
203
204 // ------------------------- content of fContDrawOpt -------------------------
205 //
206 // Run radio button
207 // Time radio button
208 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
209 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
210 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
211 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
212
213 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
214 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
215 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
216 fRadioXrun->SetToolTipText("Use run number as x-value");
217
218 // Time radio button
219 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
220 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
221 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
222 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
223
224
225 // list of variables
226 fListVariables = new TGListBox(fContDrawSel);
227 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
228 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
229
6fb51ca4 230
231//-------------------- run type selection ------------------------
5312f439 232 // Parameter label
233 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
234 fLblRunType->SetTextJustify(kTextLeft);
235 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
236
237 fComboRunType = new TGComboBox(fContDrawSel);
238 fComboRunType->EnableTextInput(kFALSE);
239 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
240 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
241// fComboRunType->SetEnabled(kFALSE);
242 fComboRunType->Resize(0, 22);
243
244 //-------------------- parameter selection ------------------------
245 // Parameter label
246 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
247 fLblPar->SetTextJustify(kTextLeft);
248 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
249
250 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
251 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
252 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
253 fNmbPar->SetState(kFALSE);
254
6fb51ca4 255 //-------------------- calibration type selection ------------------------
256 // label
257 // draw selection group
258 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
259 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
260
261 // list of variables
262 fListCalibType = new TGListBox(fContCalibType);
263 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
264 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
265 fListCalibType->Resize(0,88);
266 fListCalibType->SetMultipleSelections();
267
5312f439 268
269 // ==========================================================================
270 // ************************* content of fContCenter *************************
271 // ========================================================================
272 // main drawing canvas
273 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
274 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
275 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
276// fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
277 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
6fb51ca4 278 fCanvMain->GetCanvas()->SetRightMargin(0.062);
279 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
5312f439 280
281 // =========================================================================
282 // ************************* content of fContRight *************************
283 // ========================================================================
284 //group frame for value information
285 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
286 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
287 //set layout manager
288 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
289 //value information labels
290
291 //run number label
292 fLblRunNumber = new TGLabel(fContValues, "Run:");
293 fLblRunNumber->SetTextJustify(kTextLeft);
294 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
295 //run number
296 fLblRunNumberVal = new TGLabel(fContValues, "00000");
297 fLblRunNumberVal->SetTextJustify(kTextLeft);
298 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
299 //time stamp label
300 fLblRunTime = new TGLabel(fContValues, "Time:");
301 fLblRunTime->SetTextJustify(kTextLeft);
302 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
303 //run number
304 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
305 fLblRunTimeVal->SetTextJustify(kTextLeft);
306 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
307 //value label x
308 fLblValueX = new TGLabel(fContValues, "x-Value:");
309 fLblValueX->SetTextJustify(kTextLeft);
310 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
311 //value x
892226be 312 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
5312f439 313 fLblValueXVal->SetTextJustify(kTextRight);
314 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
315 //value label y
316 fLblValueY = new TGLabel(fContValues, "y-Value:");
317 fLblValueY->SetTextJustify(kTextLeft);
318 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
319 //value y
892226be 320 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
5312f439 321 fLblValueYVal->SetTextJustify(kTextRight);
322 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
323 // draw button
324 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
6fb51ca4 325 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
5312f439 326 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
327 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
328
329 // =========================================================================
330 // ****************** bottom content of fContTopBottom *********************
331 // =========================================================================
332
333 // custom options container
334 // --- fComboCustom --- the custom draw line on the very low
335 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
336 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
337
338 // ------------------------- content of fContCustom -------------------------
339 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
340 fLblCustomDraw->SetTextJustify(kTextLeft);
341 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
342 // text field for custom draw command
343 fComboCustomDraw = new TGComboBox(fContCustom);
344// fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
345 fComboCustomDraw->Resize(0, 22);
346 fComboCustomDraw->EnableTextInput(kTRUE);
347 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
348 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
349 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
350
351
352 // additional cuts container
353 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
354 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
355
356 // ------------------------- content of fContCustomCuts -------------------------
357 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
358 fLblCustomCuts->SetTextJustify(kTextLeft);
359 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
360 // combo text field for additional cuts
361 fComboCustomCuts = new TGComboBox(fContCustomCuts);
362// fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
363 fComboCustomCuts->Resize(0, 22);
364 fComboCustomCuts->EnableTextInput(kTRUE);
365 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
6fb51ca4 366 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
367 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
5312f439 368
369 SetWindowName("AliTPCCalibViewer GUI - Time");
370 MapSubwindows();
371 Resize(GetDefaultSize());
372 MapWindow();
373}
374//______________________________________________________________________________
375void AliTPCCalibViewerGUItime::SetInitialValues(){
376 //
377 // Set inital selections of the gui
378 //
379 fRadioXrun->SetState(kButtonDown);
380 fRadioXtime->SetState(kButtonUp);
381}
382
383//______________________________________________________________________________
384void AliTPCCalibViewerGUItime::UseFile(const char* fileName) {
385 //
386 // retrieve tree from file
387 //
892226be 388 //TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
389 TString s(fileName);
e6970ab5 390 TObjArray *arr=s.Tokenize("\n");
391 TIter next(arr);
392 TObject *o=0;
393 if (fTree) delete fTree;
394 fTree=new TChain("dcs");
395 while ( (o=next()) ){
396 fTree->AddFile(o->GetName());
397 }
398 delete arr;
399 fTree->Lookup();
400 if (fTree->GetEntries()==0){
401 AliError("No entries found in chain");
402 return;
403 }
404/* TDirectory *save=gDirectory;
5312f439 405 if (fFile) delete fFile;
406 fFile = TFile::Open(fileName);
6fb51ca4 407 if (!fFile) return;
408 if (!fFile->IsOpen()) return;
5312f439 409 fTree=(TTree*)fFile->Get("dcs");
6fb51ca4 410 if (!fTree){
411 AliError(Form("Could not get tree from file '%s'",fileName));
412 return;
413 }
5312f439 414 save->cd();
e6970ab5 415 */
6fb51ca4 416 if (fConfigParser) delete fConfigParser;
417 fConfigParser=new AliTPCConfigParser(gSystem->ExpandPathName(fConfigFile.Data()));
5312f439 418 Reload();
e6970ab5 419
5312f439 420}
421//______________________________________________________________________________
6fb51ca4 422void AliTPCCalibViewerGUItime::FillRunTypes()
423{
5312f439 424 //
6fb51ca4 425 //Loop over the tree entries and fill the run types
5312f439 426 //
6fb51ca4 427 if (!fTree) return;
5312f439 428 Int_t id=0;
5312f439 429 fComboRunType->RemoveAll();
430 fComboRunType->AddEntry("ALL",id++);
431 fComboRunType->Select(0,kFALSE);
432 TObjString *runType=0x0;
433 Int_t nevets=fTree->GetEntries();
5312f439 434 fTree->SetBranchStatus("*",0);
435 fTree->SetBranchStatus("runType.*",1);
e6970ab5 436// TBranch *branch=fTree->GetBranch("runType.");
437// if (!branch) {
438// branch->ResetAddress();
439// fTree->SetBranchStatus("*",1);
440// return;
441// }
442// branch->SetAddress(&runType);
443 fTree->SetBranchAddress("runType.",&runType);
5312f439 444 for (Int_t iev=0;iev<nevets;++iev){
445 fTree->GetEntry(iev);
446 TString type=runType->String();
447 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
448 }
e6970ab5 449// branch->ResetAddress();
450 fTree->ResetBranchAddresses();
5312f439 451 fTree->SetBranchStatus("*",1);
452}
453//______________________________________________________________________________
6fb51ca4 454void AliTPCCalibViewerGUItime::FillCalibTypes()
455{
456 //
457 // loop over configuration and fill calibration types
458 //
459 if (!fConfigParser) return;
460 Int_t id=0;
461 fListCalibType->RemoveAll();
462 TObject *o=0x0;
463 fConfigParser->ResetIter();
464 TString type;
465 while ( (o=fConfigParser->NextKey()) ){
466 type=fConfigParser->GetData(o,kCalibType);
467 //remove whitespcaces
468 type.Remove(TString::kBoth,' ');
469 type.Remove(TString::kBoth,'\t');
470 if (type.IsNull()) type="UNSPECIFIED";
471// printf("CalibType: '%s'\n",type.Data());
472 if (!fListCalibType->FindEntry(type.Data())) {
473 fListCalibType->AddEntry(type,id);
474 fListCalibType->Select(id++);
475 }
476 }
477 //add type for unspecified calibration type
478 type="UNSPECIFIED";
479 if (!fListCalibType->FindEntry(type.Data())) {
480 fListCalibType->AddEntry(SubstituteUnderscores(type.Data()),id);
481 fListCalibType->Select(id++);
482 }
483}
484//______________________________________________________________________________
485void AliTPCCalibViewerGUItime::Reload(Int_t first){
486 //
487 // reload the gui contents, this is needed after the input tree has changed
488 //
489
490 if ( !fTree ) return;
491 //in case of the first call create run type and calibration type entries
492 if (first){
493 FillRunTypes();
494 FillCalibTypes();
495 }
496 //activate all branches
497 fTree->SetBranchStatus("*",1);
498 //reset variables list
499 fListVariables->RemoveAll();
500 //get selected calibration types
501 TList calibTypes;
502 fListCalibType->GetSelectedEntries(&calibTypes);
503
504 TObjArray *branchList = fTree->GetListOfBranches();
505 if ( !branchList ) return;
506 TIter nextBranch(branchList);
507 Int_t idCount=0,id=0;
508 TObject *objBranch=0;
509 while ( (objBranch=nextBranch()) ){
510 TString branchName(objBranch->GetName());
511 TString branchTitle(objBranch->GetName());
512 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
513 Bool_t active=kTRUE;
514 TString calibType="UNSPECIFIED";
515 if (fConfigParser){
516 const TObject *key=(*fConfigParser)(branchName.Data());
517 if (key){
518 //test if branch is active
519 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
520 id=(*fConfigParser)()->IndexOf(key);
892226be 521// branchTitle=fConfigParser->GetData(key,kBranchTitle);
6fb51ca4 522 calibType=fConfigParser->GetData(key,kCalibType);
523 }
524 else{
525 id=1000+idCount;
526 }
527 } else {
528 id=idCount;
529 }
e6970ab5 530 if (calibType.IsNull()) calibType="UNSPECIFIED";
6fb51ca4 531 //check if branch is in selected calibration types
532 //if not, don't show it in the list and deactivate the branch.
533 Bool_t calibActive=kFALSE;
534 TIter nextCalib(&calibTypes);
535 TObject *objCalib=0;
e6970ab5 536 while ( (objCalib=nextCalib()) )
6fb51ca4 537 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
538 active&=calibActive;
539 if (!active){
540 TString s=branchName;
541 if (branchName.EndsWith(".")) s+="*";
542 fTree->SetBranchStatus(s.Data(),0);
543 continue;
544 }
545 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
546 ++idCount;
547 }
548 //trick to display modifications
549 if (!first){
550 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
551 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
552 }
553}
554//______________________________________________________________________________
5312f439 555const char* AliTPCCalibViewerGUItime::GetDrawString(){
556 //
557 // create draw string for ttree by combining the user requestsa
558 //
559
560 TString selectedVariable="";
6fb51ca4 561 Int_t id=-1;
562 if (!fListVariables->GetSelectedEntry()) return "";
563 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
564 id=fListVariables->GetSelectedEntry()->EntryId();
565// printf("id: %d\n",id);
566 TString branchName=selectedVariable;
567 const TObject *key=(*fConfigParser)(id);
568 if (key) branchName=(*fConfigParser)(id)->GetName();
5312f439 569 //treat case of TVector
6fb51ca4 570 if (branchName.EndsWith(".")){
5312f439 571 Int_t par = (Int_t)(fNmbPar->GetNumber());
6fb51ca4 572 branchName.Append(Form("fElements[%d]",par));
5312f439 573 }
574// if (fRadioXrun->GetState()==kButtonDown)
575// selectedVariable.Append(":run");
576// if (fRadioXtime->GetState()==kButtonDown)
577// selectedVariable.Append(":time");
578
6fb51ca4 579 return branchName.Data();
5312f439 580}
581//______________________________________________________________________________
582const char* AliTPCCalibViewerGUItime::GetCutString(){
583 //
584 // create cut string
585 //
586 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
587 TString runType="";
588 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
589 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
590 return cuts.GetTitle();
591}
592//______________________________________________________________________________
593void AliTPCCalibViewerGUItime::DoDraw() {
594 TString drawString=fDrawString;
595 drawString.Prepend("run:time:");
596 TString cutString = GetCutString();
597 TString optString = "goff";
598 TVirtualPad *padsave=gPad;
599 fCanvMain->GetCanvas()->cd();
600 //delete old histogram and graph
601 if (fCurrentGraph) {
602 delete fCurrentGraph;
603 fCurrentGraph=0x0;
892226be 604 //fCurrentHist in case of graph is the interrnal histogram,
605 // which is deleted by the graph itself.
606 fCurrentHist=0x0;
607 }
608 if (fCurrentHist) {
609 delete fCurrentHist;
5312f439 610 fCurrentHist=0x0;
611 }
5312f439 612 //select data
613 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
614 if (fTree->GetSelectedRows()==-1) return;
615 fValuesX.ResizeTo(fTree->GetSelectedRows());
616 fValuesY.ResizeTo(fTree->GetSelectedRows());
617 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
618 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
619 fValuesY.SetElements(fTree->GetV3());
620 fRunNumbers.SetElements(fTree->GetV1());
621 fTimeStamps.SetElements(fTree->GetV2());
622 TString title="";
623 Bool_t drawGraph=kFALSE;
624 if (fIsCustomDraw){
625 if (fDrawString.Contains(":")){
626 fValuesX.SetElements(fTree->GetV4());
627 TString yname=fDrawString(0,fDrawString.First(':'));
628 TString xname=fDrawString(fDrawString.First(':')+1,fDrawString.Length());
629 title=Form("%s;%s;%s",fDrawString.Data(),xname.Data(),yname.Data());
630 drawGraph=kTRUE;
631 } else {
632 drawGraph=kFALSE;
633 }
634 }else{
635 drawGraph=kTRUE;
6fb51ca4 636 TString yname=fDrawString.Data();
637 if (fConfigParser ){
638 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
639 if ((*fConfigParser)(id)) yname=fConfigParser->GetData((*fConfigParser)(id),kBranchTitle);
640 yname=SubstituteUnderscores(yname.Data());
641 if (fNmbPar->GetButtonUp()->GetState()!=kButtonDisabled){
642 yname+=": ";
643 Int_t par = (Int_t)(fNmbPar->GetNumber());
644 if (fConfigParser && (*fConfigParser)(id)) {
645 TString yparname=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
646 yparname=SubstituteUnderscores(yparname);
647 yname+=yparname;
648 }
649 }
650 }
5312f439 651 if (fRadioXrun->GetState()==kButtonDown){
652 fValuesX.SetElements(fTree->GetV1());
6fb51ca4 653 title=Form("%s:Run;Run;%s",fDrawString.Data(),yname.Data());
5312f439 654 } else if (fRadioXtime->GetState()==kButtonDown){
655 fValuesX.SetElements(fTree->GetV2());
6fb51ca4 656 title=Form("%s:Time;Time;%s",fDrawString.Data(),yname.Data());
5312f439 657 } else {
658 drawGraph=kFALSE;
892226be 659 title=Form("%s:%s",fDrawString.Data(),yname.Data());
5312f439 660 }
661 }
662 //create graph according to selection
663 if (drawGraph){
664 fCurrentGraph=new TGraph(fValuesX,fValuesY);
e6970ab5 665 fCurrentGraph->Draw(fIsCustomDraw?"ap":"alp");
5312f439 666 fCurrentHist=fCurrentGraph->GetHistogram();
667 fCurrentHist->SetTitle(title.Data());
668 } else {
669 fCurrentGraph=0x0;
670 Float_t add=TMath::Abs(fValuesY.Min()*.05);
892226be 671 fCurrentHist=new TH1D("hist",title.Data(),100,fValuesY.Min()-add,fValuesY.Max()+add);
5312f439 672 fCurrentHist->FillN(fValuesY.GetNrows(),fValuesY.GetMatrixArray(),0);
673 fCurrentHist->Draw();
674 }
675
5312f439 676 //Set time axis if choosen as x-variables
677 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw){
678 TAxis *xaxis=fCurrentHist->GetXaxis();
679 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
680 xaxis->SetTimeDisplay(1);
681 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
682 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
683 }
684 if (fCurrentGraph){
685 fCurrentGraph->SetEditable(kFALSE);
686 fCurrentGraph->SetMarkerStyle(20);
687 fCurrentGraph->SetMarkerSize(0.5);
688 }
6fb51ca4 689 //Set title offset
690 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
5312f439 691 gPad->Modified();
692 gPad->Update();
693 padsave->cd();
694}
695
696//______________________________________________________________________________
697void AliTPCCalibViewerGUItime::DoDumpRuns()
698{
699 //
700 // Dump the current run numbers to stdout
701 //
6fb51ca4 702 Int_t npoints=fRunNumbers.GetNrows();
703 Int_t *sortIndex = new Int_t[npoints];
704 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
705 Int_t run=0, prevRun=-1;
706
707 for (Int_t irun=0;irun<npoints;++irun){
708 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
709 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
710 prevRun=run;
5312f439 711 }
6fb51ca4 712 delete sortIndex;
5312f439 713}
714//______________________________________________________________________________
715void AliTPCCalibViewerGUItime::DoParLimitChange()
716{
717 //
718 //
719 //
6fb51ca4 720 UpdateParName();
5312f439 721 DoDraw();
722}
723//______________________________________________________________________________
724void AliTPCCalibViewerGUItime::DoNewSelection() {
725 //
726 // decides whether to redraw if user makes another selection
727 //
728 UpdateParLimits();
729 fDrawString=GetDrawString();
730 fIsCustomDraw=kFALSE;
731 DoDraw();
732}
733//______________________________________________________________________________
734void AliTPCCalibViewerGUItime::DoCustomDraw()
735{
736 //
737 //
738 //
739 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
740 if (fDrawString.Contains(">>")){
741 Warning("DoCustomDraw","Currently no user defined histograms allowed!");
742 return;
743 }
744 fIsCustomDraw=kTRUE;
745 DoDraw();
746}
747//______________________________________________________________________________
748void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
749{
750 //
751 //
752 //
753 if (fIsCustomDraw) DoCustomDraw();
754 else {
755 fDrawString=GetDrawString();
756 fIsCustomDraw=kFALSE;
757 DoDraw();
758 }
759}
760//______________________________________________________________________________
761void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
762{
763 //
764 // Draw selection button handling (x-variable)
765 //
766
767 if (id == -1) {
768 TGButton *btn = (TGButton *) gTQSender;
769 id = btn->WidgetId();
770 }
771
772 Bool_t doDraw=kFALSE;
773 switch (id) {
774 case (kRadioXhist):
775 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
776 if (doDraw){
777 fRadioXrun->SetState(kButtonUp);
778 fRadioXtime->SetState(kButtonUp);
779 }
780 break;
781 case (kRadioXrun):
782 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
783 if (doDraw){
784 fRadioXhist->SetState(kButtonUp);
785 fRadioXtime->SetState(kButtonUp);
786 }
787 break;
788 case (kRadioXtime):
789 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
790 if (doDraw){
791 fRadioXrun->SetState(kButtonUp);
792 fRadioXhist->SetState(kButtonUp);
793 }
794 break;
795 }
6fb51ca4 796 if (doDraw) DoCustomCutsDraw();
5312f439 797}
798//______________________________________________________________________________
6fb51ca4 799void AliTPCCalibViewerGUItime::UpdateParName()
800{
801 //
802 // change parameter name
803 //
804
805 Int_t par = (Int_t)(fNmbPar->GetNumber());
806 TString parName=par;
807 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
808 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
809 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
810 fDrawString=GetDrawString();
811 fIsCustomDraw=kFALSE;
812}
813
814//______________________________________________________________________________
5312f439 815void AliTPCCalibViewerGUItime::UpdateParLimits()
816{
817 //
818 // Adjust limits for TVectorT based variables
819 //
820 if (!fTree) return;
6fb51ca4 821 TString selectedVariableTitle="";
822 Int_t id=-1;
823 if (!fListVariables->GetSelectedEntry()) return;
824 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
825 id=fListVariables->GetSelectedEntry()->EntryId();
826// printf("id: %d\n",id);
827 TString selectedVariable=selectedVariableTitle;
828 const TObject *key=(*fConfigParser)(id);
829 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
830
5312f439 831 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
832 fNmbPar->SetState(kFALSE);
6fb51ca4 833 fLblPar->SetText("Parameter: none");
5312f439 834 return;
835 }
836 TVectorD *vD=0x0;
837 TVectorF *vF=0x0;
838 Int_t maxPar=0;
e6970ab5 839 fTree->GetEntry(1);
840 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
5312f439 841 TString branchClass=branch->GetClassName();
e6970ab5 842 Int_t event=0;
5312f439 843 if (branchClass=="TVectorT<double>"){
e6970ab5 844// branch->SetAddress(&vD);
845 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
846 while (maxPar<2&&event<fTree->GetEntries()){
847 fTree->GetEntry(event++);
848 maxPar=vD->GetNrows();
849 }
5312f439 850 } else if (branchClass=="TVectorT<float>"){
e6970ab5 851// branch->SetAddress(&vF);
852 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
853 while (maxPar<2&&event<fTree->GetEntries()){
854 fTree->GetEntry(event++);
855 maxPar=vF->GetNrows();
856 }
5312f439 857 } else {
858 //class not known
859 fNmbPar->SetState(kFALSE);
860 return;
861 }
e6970ab5 862// branch->ResetAddress();
863 fTree->ResetBranchAddresses();
5312f439 864 fNmbPar->SetNumber(0);
865 fNmbPar->SetLimitValues(0,maxPar-1);
866 fNmbPar->SetState(kTRUE);
6fb51ca4 867 UpdateParName();
5312f439 868}
869//______________________________________________________________________________
6fb51ca4 870void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
5312f439 871{
872 //
873 // handle mouse events in the draw canvas
874 //
5312f439 875 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
876 Double_t valx=0.,valy=0.;
877 if (!fCurrentGraph) {
878 fLblRunNumberVal->SetText(Form("%05u",run));
e6970ab5 879 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
892226be 880 fLblValueXVal->SetText(Form("%.3e", valx));
881 fLblValueYVal->SetText(Form("%.3e", valy));
5312f439 882 return;
883 }
884 TVirtualPad *padsave=gPad;
885 fCanvMain->GetCanvas()->cd();
886 Int_t n=fValuesY.GetNrows();
887 Double_t *arr=0x0;
888 arr=fValuesX.GetMatrixArray();
889
890 Int_t minDist=1000000;
891 Int_t minPoint=-1;
892 for (Int_t i=0;i<n;++i){
893 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
894 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
e6970ab5 895 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
5312f439 896 if (d < minDist) {
897 minDist = d;
898 minPoint = i;
899 }
900 }
901 if (minDist<2){
902 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
903 t.GetDate(kTRUE,0,&yy,&mm,&dd);
904 t.GetTime(kTRUE,0,&HH,&MM,&SS);
905 run=(UInt_t)fRunNumbers[minPoint];
906 valx=fValuesX[minPoint];
907 valy=fValuesY[minPoint];
908 } else {
909 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
910 valx=0.;
911 valy=0.;
912 }
913 fLblRunNumberVal->SetText(Form("%05u",run));
914 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
915 if (fIsCustomDraw){
892226be 916 fLblValueXVal->SetText(Form("%.3e", valx));
5312f439 917 }else{
918 if (fRadioXrun->GetState()==kButtonDown){
919 fLblValueXVal->SetText("Run");
920 } else if (fRadioXtime->GetState()==kButtonDown){
921 fLblValueXVal->SetText("Time");
922 }
923 }
892226be 924 fLblValueYVal->SetText(Form("%.3e", valy));
5312f439 925 padsave->cd();
926 if (run==0) return;
927 if (event == kButton1Double ){
928 SetGuiTree(run);
929 }
930 //find closes point of current selection
931}
932//______________________________________________________________________________
933void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
934{
935 //
936 // create the AliTPCCalibViewerGUI tree for run
937 // cache tree in directory fOutputCacheDir
938 // retrieve file from this directory if it already exists
939 //
940
941 //try to find file for run in fOutputCacheDir
942 TString fileName=fOutputCacheDir;
943 if (!fileName.EndsWith("/")) fileName+="/";
944 fileName+=Form("guiTreeRun_%d.root",run);
945 TFile f(fileName.Data());
946 if (f.IsOpen()){
947 f.Close();
948 fCalibViewerGUI->Initialize(fileName.Data());
949 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
950 return;
951 }
952 f.Close();
953 Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
954 if (sucess){
955 fCalibViewerGUI->Initialize(fileName.Data());
956 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
957 }else{
958 fCalibViewerGUI->Reset();
959 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
960 }
961}
962//______________________________________________________________________________
6fb51ca4 963const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
964{
965 //
966 //
967 //
968 TString s(in);
969 s.ReplaceAll("_{","|{");
970 s.ReplaceAll("_"," ");
971 s.ReplaceAll("|{","_{");
972 return s.Data();
973}
974//______________________________________________________________________________
5312f439 975TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName) {
976 //
977 // Initialize and show GUI for presentation for demonstration purposes
978 // or for fast standalone use
979 //
980 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
981 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
982 frmMain->SetCleanup(kDeepCleanup);
983
984 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
985 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
986
987 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
988 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
989
990 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
991 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
992 calibViewerTime->UseFile(fileName);
993
994 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
995 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
996 calibViewerTime->SetCalibViewerGUI(calibViewer);
997 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
998
999
1000 TObjArray *guiArray = new TObjArray();
1001 guiArray->Add(calibViewerTime);
1002 guiArray->Add(calibViewer);
1003
1004 frmMain->MapSubwindows();
1005 frmMain->Resize();
1006 frmMain->MapWindow();
1007
1008 return guiArray;
1009}
1010