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