MapCalibrationObjects.root Include Number of pads per row mapping
[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
312 fLblValueXVal = new TGLabel(fContValues, "00000.000");
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
320 fLblValueYVal = new TGLabel(fContValues, "00000.000");
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 //
e6970ab5 388 // TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
389 TString s=fileName;
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);
521 branchTitle=fConfigParser->GetData(key,kBranchTitle);
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;
604 //fCurrentHist in case of graph is the internal histogram,
605 // which is deletet by the graph itself.
606 fCurrentHist=0x0;
607 }
608 if (fCurrentHist) delete fCurrentHist;
609 //select data
610 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
611 if (fTree->GetSelectedRows()==-1) return;
612 fValuesX.ResizeTo(fTree->GetSelectedRows());
613 fValuesY.ResizeTo(fTree->GetSelectedRows());
614 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
615 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
616 fValuesY.SetElements(fTree->GetV3());
617 fRunNumbers.SetElements(fTree->GetV1());
618 fTimeStamps.SetElements(fTree->GetV2());
619 TString title="";
620 Bool_t drawGraph=kFALSE;
621 if (fIsCustomDraw){
622 if (fDrawString.Contains(":")){
623 fValuesX.SetElements(fTree->GetV4());
624 TString yname=fDrawString(0,fDrawString.First(':'));
625 TString xname=fDrawString(fDrawString.First(':')+1,fDrawString.Length());
626 title=Form("%s;%s;%s",fDrawString.Data(),xname.Data(),yname.Data());
627 drawGraph=kTRUE;
628 } else {
629 drawGraph=kFALSE;
630 }
631 }else{
632 drawGraph=kTRUE;
6fb51ca4 633 TString yname=fDrawString.Data();
634 if (fConfigParser ){
635 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
636 if ((*fConfigParser)(id)) yname=fConfigParser->GetData((*fConfigParser)(id),kBranchTitle);
637 yname=SubstituteUnderscores(yname.Data());
638 if (fNmbPar->GetButtonUp()->GetState()!=kButtonDisabled){
639 yname+=": ";
640 Int_t par = (Int_t)(fNmbPar->GetNumber());
641 if (fConfigParser && (*fConfigParser)(id)) {
642 TString yparname=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
643 yparname=SubstituteUnderscores(yparname);
644 yname+=yparname;
645 }
646 }
647 }
5312f439 648 if (fRadioXrun->GetState()==kButtonDown){
649 fValuesX.SetElements(fTree->GetV1());
6fb51ca4 650 title=Form("%s:Run;Run;%s",fDrawString.Data(),yname.Data());
5312f439 651 } else if (fRadioXtime->GetState()==kButtonDown){
652 fValuesX.SetElements(fTree->GetV2());
6fb51ca4 653 title=Form("%s:Time;Time;%s",fDrawString.Data(),yname.Data());
5312f439 654 } else {
655 drawGraph=kFALSE;
656 }
657 }
658 //create graph according to selection
659 if (drawGraph){
660 fCurrentGraph=new TGraph(fValuesX,fValuesY);
e6970ab5 661 fCurrentGraph->Draw(fIsCustomDraw?"ap":"alp");
5312f439 662 fCurrentHist=fCurrentGraph->GetHistogram();
663 fCurrentHist->SetTitle(title.Data());
664 } else {
665 fCurrentGraph=0x0;
666 Float_t add=TMath::Abs(fValuesY.Min()*.05);
667 fCurrentHist=new TH1D("hist",Form("%s;%s",fDrawString.Data(),fDrawString.Data()),100,fValuesY.Min()-add,fValuesY.Max()+add);
668 fCurrentHist->FillN(fValuesY.GetNrows(),fValuesY.GetMatrixArray(),0);
669 fCurrentHist->Draw();
670 }
671
5312f439 672 //Set time axis if choosen as x-variables
673 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw){
674 TAxis *xaxis=fCurrentHist->GetXaxis();
675 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
676 xaxis->SetTimeDisplay(1);
677 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
678 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
679 }
680 if (fCurrentGraph){
681 fCurrentGraph->SetEditable(kFALSE);
682 fCurrentGraph->SetMarkerStyle(20);
683 fCurrentGraph->SetMarkerSize(0.5);
684 }
6fb51ca4 685 //Set title offset
686 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
5312f439 687 gPad->Modified();
688 gPad->Update();
689 padsave->cd();
690}
691
692//______________________________________________________________________________
693void AliTPCCalibViewerGUItime::DoDumpRuns()
694{
695 //
696 // Dump the current run numbers to stdout
697 //
6fb51ca4 698 Int_t npoints=fRunNumbers.GetNrows();
699 Int_t *sortIndex = new Int_t[npoints];
700 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
701 Int_t run=0, prevRun=-1;
702
703 for (Int_t irun=0;irun<npoints;++irun){
704 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
705 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
706 prevRun=run;
5312f439 707 }
6fb51ca4 708 delete sortIndex;
5312f439 709}
710//______________________________________________________________________________
711void AliTPCCalibViewerGUItime::DoParLimitChange()
712{
713 //
714 //
715 //
6fb51ca4 716 UpdateParName();
5312f439 717 DoDraw();
718}
719//______________________________________________________________________________
720void AliTPCCalibViewerGUItime::DoNewSelection() {
721 //
722 // decides whether to redraw if user makes another selection
723 //
724 UpdateParLimits();
725 fDrawString=GetDrawString();
726 fIsCustomDraw=kFALSE;
727 DoDraw();
728}
729//______________________________________________________________________________
730void AliTPCCalibViewerGUItime::DoCustomDraw()
731{
732 //
733 //
734 //
735 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
736 if (fDrawString.Contains(">>")){
737 Warning("DoCustomDraw","Currently no user defined histograms allowed!");
738 return;
739 }
740 fIsCustomDraw=kTRUE;
741 DoDraw();
742}
743//______________________________________________________________________________
744void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
745{
746 //
747 //
748 //
749 if (fIsCustomDraw) DoCustomDraw();
750 else {
751 fDrawString=GetDrawString();
752 fIsCustomDraw=kFALSE;
753 DoDraw();
754 }
755}
756//______________________________________________________________________________
757void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
758{
759 //
760 // Draw selection button handling (x-variable)
761 //
762
763 if (id == -1) {
764 TGButton *btn = (TGButton *) gTQSender;
765 id = btn->WidgetId();
766 }
767
768 Bool_t doDraw=kFALSE;
769 switch (id) {
770 case (kRadioXhist):
771 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
772 if (doDraw){
773 fRadioXrun->SetState(kButtonUp);
774 fRadioXtime->SetState(kButtonUp);
775 }
776 break;
777 case (kRadioXrun):
778 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
779 if (doDraw){
780 fRadioXhist->SetState(kButtonUp);
781 fRadioXtime->SetState(kButtonUp);
782 }
783 break;
784 case (kRadioXtime):
785 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
786 if (doDraw){
787 fRadioXrun->SetState(kButtonUp);
788 fRadioXhist->SetState(kButtonUp);
789 }
790 break;
791 }
6fb51ca4 792 if (doDraw) DoCustomCutsDraw();
5312f439 793}
794//______________________________________________________________________________
6fb51ca4 795void AliTPCCalibViewerGUItime::UpdateParName()
796{
797 //
798 // change parameter name
799 //
800
801 Int_t par = (Int_t)(fNmbPar->GetNumber());
802 TString parName=par;
803 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
804 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
805 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
806 fDrawString=GetDrawString();
807 fIsCustomDraw=kFALSE;
808}
809
810//______________________________________________________________________________
5312f439 811void AliTPCCalibViewerGUItime::UpdateParLimits()
812{
813 //
814 // Adjust limits for TVectorT based variables
815 //
816 if (!fTree) return;
6fb51ca4 817 TString selectedVariableTitle="";
818 Int_t id=-1;
819 if (!fListVariables->GetSelectedEntry()) return;
820 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
821 id=fListVariables->GetSelectedEntry()->EntryId();
822// printf("id: %d\n",id);
823 TString selectedVariable=selectedVariableTitle;
824 const TObject *key=(*fConfigParser)(id);
825 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
826
5312f439 827 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
828 fNmbPar->SetState(kFALSE);
6fb51ca4 829 fLblPar->SetText("Parameter: none");
5312f439 830 return;
831 }
832 TVectorD *vD=0x0;
833 TVectorF *vF=0x0;
834 Int_t maxPar=0;
e6970ab5 835 fTree->GetEntry(1);
836 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
5312f439 837 TString branchClass=branch->GetClassName();
e6970ab5 838 Int_t event=0;
5312f439 839 if (branchClass=="TVectorT<double>"){
e6970ab5 840// branch->SetAddress(&vD);
841 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
842 while (maxPar<2&&event<fTree->GetEntries()){
843 fTree->GetEntry(event++);
844 maxPar=vD->GetNrows();
845 }
5312f439 846 } else if (branchClass=="TVectorT<float>"){
e6970ab5 847// branch->SetAddress(&vF);
848 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
849 while (maxPar<2&&event<fTree->GetEntries()){
850 fTree->GetEntry(event++);
851 maxPar=vF->GetNrows();
852 }
5312f439 853 } else {
854 //class not known
855 fNmbPar->SetState(kFALSE);
856 return;
857 }
e6970ab5 858// branch->ResetAddress();
859 fTree->ResetBranchAddresses();
5312f439 860 fNmbPar->SetNumber(0);
861 fNmbPar->SetLimitValues(0,maxPar-1);
862 fNmbPar->SetState(kTRUE);
6fb51ca4 863 UpdateParName();
5312f439 864}
865//______________________________________________________________________________
6fb51ca4 866void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
5312f439 867{
868 //
869 // handle mouse events in the draw canvas
870 //
5312f439 871 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
872 Double_t valx=0.,valy=0.;
873 if (!fCurrentGraph) {
874 fLblRunNumberVal->SetText(Form("%05u",run));
e6970ab5 875 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
5312f439 876 fLblValueXVal->SetText(Form("%.3f", valx));
877 fLblValueYVal->SetText(Form("%.3f", valy));
878 return;
879 }
880 TVirtualPad *padsave=gPad;
881 fCanvMain->GetCanvas()->cd();
882 Int_t n=fValuesY.GetNrows();
883 Double_t *arr=0x0;
884 arr=fValuesX.GetMatrixArray();
885
886 Int_t minDist=1000000;
887 Int_t minPoint=-1;
888 for (Int_t i=0;i<n;++i){
889 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
890 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
e6970ab5 891 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
5312f439 892 if (d < minDist) {
893 minDist = d;
894 minPoint = i;
895 }
896 }
897 if (minDist<2){
898 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
899 t.GetDate(kTRUE,0,&yy,&mm,&dd);
900 t.GetTime(kTRUE,0,&HH,&MM,&SS);
901 run=(UInt_t)fRunNumbers[minPoint];
902 valx=fValuesX[minPoint];
903 valy=fValuesY[minPoint];
904 } else {
905 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
906 valx=0.;
907 valy=0.;
908 }
909 fLblRunNumberVal->SetText(Form("%05u",run));
910 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
911 if (fIsCustomDraw){
912 fLblValueXVal->SetText(Form("%.3f", valx));
913 }else{
914 if (fRadioXrun->GetState()==kButtonDown){
915 fLblValueXVal->SetText("Run");
916 } else if (fRadioXtime->GetState()==kButtonDown){
917 fLblValueXVal->SetText("Time");
918 }
919 }
920 fLblValueYVal->SetText(Form("%.3f", valy));
921 padsave->cd();
922 if (run==0) return;
923 if (event == kButton1Double ){
924 SetGuiTree(run);
925 }
926 //find closes point of current selection
927}
928//______________________________________________________________________________
929void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
930{
931 //
932 // create the AliTPCCalibViewerGUI tree for run
933 // cache tree in directory fOutputCacheDir
934 // retrieve file from this directory if it already exists
935 //
936
937 //try to find file for run in fOutputCacheDir
938 TString fileName=fOutputCacheDir;
939 if (!fileName.EndsWith("/")) fileName+="/";
940 fileName+=Form("guiTreeRun_%d.root",run);
941 TFile f(fileName.Data());
942 if (f.IsOpen()){
943 f.Close();
944 fCalibViewerGUI->Initialize(fileName.Data());
945 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
946 return;
947 }
948 f.Close();
949 Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
950 if (sucess){
951 fCalibViewerGUI->Initialize(fileName.Data());
952 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
953 }else{
954 fCalibViewerGUI->Reset();
955 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
956 }
957}
958//______________________________________________________________________________
6fb51ca4 959const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
960{
961 //
962 //
963 //
964 TString s(in);
965 s.ReplaceAll("_{","|{");
966 s.ReplaceAll("_"," ");
967 s.ReplaceAll("|{","_{");
968 return s.Data();
969}
970//______________________________________________________________________________
5312f439 971TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName) {
972 //
973 // Initialize and show GUI for presentation for demonstration purposes
974 // or for fast standalone use
975 //
976 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
977 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
978 frmMain->SetCleanup(kDeepCleanup);
979
980 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
981 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
982
983 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
984 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
985
986 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
987 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
988 calibViewerTime->UseFile(fileName);
989
990 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
991 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
992 calibViewerTime->SetCalibViewerGUI(calibViewer);
993 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
994
995
996 TObjArray *guiArray = new TObjArray();
997 guiArray->Add(calibViewerTime);
998 guiArray->Add(calibViewer);
999
1000 frmMain->MapSubwindows();
1001 frmMain->Resize();
1002 frmMain->MapWindow();
1003
1004 return guiArray;
1005}
1006