]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCCalibViewerGUItime.cxx
0eb6b45bf1e5e1b06735d8e880c4e1f943117c18
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibViewerGUItime.cxx
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>
33 #include <TSystem.h>
34 #include <TVector.h>
35 #include <TH1.h>
36 #include <TCut.h>
37 #include <TFile.h>
38 #include <TTree.h>
39 #include <TChain.h>
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
63 #include <AliLog.h>
64 #include "AliTPCCalibViewerGUI.h"
65 #include "AliTPCcalibDB.h"
66 #include "AliTPCConfigParser.h"
67
68 #include "AliTPCCalibViewerGUItime.h"
69
70 ClassImp(AliTPCCalibViewerGUItime)
71
72 AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
73 TGCompositeFrame(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(""),
83   fConfigFile("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt"),
84   fConfigParser(0x0),
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),
107   fListCalibType(0x0),
108   fContCalibType(0x0),
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 //______________________________________________________________________________
139 AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
140   //
141   // dtor
142   //
143
144 }
145 //______________________________________________________________________________
146 void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
147    //
148    // draw the GUI
149    //
150    // ======================================================================
151    // ************************* Display everything *************************
152    // ======================================================================
153   
154   SetCleanup(kDeepCleanup);
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
230   
231 //-------------------- run type selection ------------------------
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   
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   
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.");
278   fCanvMain->GetCanvas()->SetRightMargin(0.062);
279   fCanvMain->GetCanvas()->SetLeftMargin(0.15);
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, "00.000e+00");
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, "00.000e+00");
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");
325   fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
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));
366   fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
367   fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
368
369   SetWindowName("AliTPCCalibViewer GUI - Time");
370   MapSubwindows();
371   Resize(GetDefaultSize());
372   MapWindow();
373 }
374 //______________________________________________________________________________
375 void AliTPCCalibViewerGUItime::SetInitialValues(){
376   //
377   // Set inital selections of the gui
378   //
379   fRadioXrun->SetState(kButtonDown);
380   fRadioXtime->SetState(kButtonUp);
381 }
382
383 //______________________________________________________________________________
384 void AliTPCCalibViewerGUItime::UseFile(const char* fileName) {
385   //
386   // retrieve tree from file
387   //
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;
405   if (fFile) delete fFile;
406   fFile = TFile::Open(fileName);
407   if (!fFile) return;
408   if (!fFile->IsOpen()) return;
409   fTree=(TTree*)fFile->Get("dcs");
410   if (!fTree){
411     AliError(Form("Could not get tree from file '%s'",fileName));
412     return;
413   }
414   save->cd();
415   */
416   if (fConfigParser) delete fConfigParser;
417   fConfigParser=new AliTPCConfigParser(gSystem->ExpandPathName(fConfigFile.Data()));
418   Reload();
419   
420 }
421 //______________________________________________________________________________
422 void AliTPCCalibViewerGUItime::FillRunTypes()
423 {
424   //
425   //Loop over the tree entries and fill the run types
426   //
427   if (!fTree) return;
428   Int_t id=0;
429   fComboRunType->RemoveAll();
430   fComboRunType->AddEntry("ALL",id++);
431   fComboRunType->Select(0,kFALSE);
432   TObjString *runType=0x0;
433   Int_t nevets=fTree->GetEntries();
434   fTree->SetBranchStatus("*",0);
435   fTree->SetBranchStatus("runType.*",1);
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);
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   }
449 //   branch->ResetAddress();
450   fTree->ResetBranchAddresses();
451   fTree->SetBranchStatus("*",1);
452 }
453 //______________________________________________________________________________
454 void 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 //______________________________________________________________________________
485 void 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     }
530     if (calibType.IsNull()) calibType="UNSPECIFIED";
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;
536     while ( (objCalib=nextCalib()) )
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 //______________________________________________________________________________
555 const char* AliTPCCalibViewerGUItime::GetDrawString(){
556   //
557   // create draw string for ttree by combining the user requestsa
558   //
559   
560   TString selectedVariable="";
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();
569   //treat case of TVector
570   if (branchName.EndsWith(".")){
571     Int_t par = (Int_t)(fNmbPar->GetNumber());
572     branchName.Append(Form("fElements[%d]",par));
573   }
574 //   if (fRadioXrun->GetState()==kButtonDown)
575 //     selectedVariable.Append(":run");
576 //   if (fRadioXtime->GetState()==kButtonDown)
577 //     selectedVariable.Append(":time");
578   
579   return branchName.Data();
580 }
581 //______________________________________________________________________________
582 const 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 //______________________________________________________________________________
593 void 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 interrnal histogram,
605     //  which is deleted by the graph itself.
606     fCurrentHist=0x0;
607   }
608   if (fCurrentHist)  {
609     delete fCurrentHist;
610     fCurrentHist=0x0;
611   }
612   //select data
613   fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
614   if (fTree->GetSelectedRows()==-1) return;
615   fValuesX.ResizeTo(fTree->GetSelectedRows());
616   fValuesY.ResizeTo(fTree->GetSelectedRows());
617   fRunNumbers.ResizeTo(fTree->GetSelectedRows());
618   fTimeStamps.ResizeTo(fTree->GetSelectedRows());
619   fValuesY.SetElements(fTree->GetV3());
620   fRunNumbers.SetElements(fTree->GetV1());
621   fTimeStamps.SetElements(fTree->GetV2());
622   TString title="";
623   Bool_t drawGraph=kFALSE;
624   if (fIsCustomDraw){
625     if (fDrawString.Contains(":")){
626       fValuesX.SetElements(fTree->GetV4());
627       TString yname=fDrawString(0,fDrawString.First(':'));
628       TString xname=fDrawString(fDrawString.First(':')+1,fDrawString.Length());
629       title=Form("%s;%s;%s",fDrawString.Data(),xname.Data(),yname.Data());
630       drawGraph=kTRUE;
631     } else {
632       drawGraph=kFALSE;
633     }
634   }else{
635     drawGraph=kTRUE;
636     TString yname=fDrawString.Data();
637     if (fConfigParser ){
638       Int_t id=fListVariables->GetSelectedEntry()->EntryId();
639       if ((*fConfigParser)(id)) yname=fConfigParser->GetData((*fConfigParser)(id),kBranchTitle);
640       yname=SubstituteUnderscores(yname.Data());
641       if (fNmbPar->GetButtonUp()->GetState()!=kButtonDisabled){
642         yname+=": ";
643         Int_t par = (Int_t)(fNmbPar->GetNumber());
644         if (fConfigParser && (*fConfigParser)(id)) {
645           TString yparname=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
646           yparname=SubstituteUnderscores(yparname);
647           yname+=yparname;
648         }
649       }
650     }
651     if (fRadioXrun->GetState()==kButtonDown){
652       fValuesX.SetElements(fTree->GetV1());
653       title=Form("%s:Run;Run;%s",fDrawString.Data(),yname.Data());
654     } else if (fRadioXtime->GetState()==kButtonDown){
655       fValuesX.SetElements(fTree->GetV2());
656       title=Form("%s:Time;Time;%s",fDrawString.Data(),yname.Data());
657     } else {
658       drawGraph=kFALSE;
659       title=Form("%s:%s",fDrawString.Data(),yname.Data());
660     }
661   }
662   //create graph according to selection
663   if (drawGraph){
664     fCurrentGraph=new TGraph(fValuesX,fValuesY);
665     fCurrentGraph->Draw(fIsCustomDraw?"ap":"alp");
666     fCurrentHist=fCurrentGraph->GetHistogram();
667     fCurrentHist->SetTitle(title.Data());
668   } else {
669     fCurrentGraph=0x0;
670     Float_t add=TMath::Abs(fValuesY.Min()*.05);
671     fCurrentHist=new TH1D("hist",title.Data(),100,fValuesY.Min()-add,fValuesY.Max()+add);
672     fCurrentHist->FillN(fValuesY.GetNrows(),fValuesY.GetMatrixArray(),0);
673     fCurrentHist->Draw();
674   }
675   
676   //Set time axis if choosen as x-variables
677   if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw){
678     TAxis *xaxis=fCurrentHist->GetXaxis();
679     xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
680     xaxis->SetTimeDisplay(1);
681     xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
682     xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
683   }
684   if (fCurrentGraph){
685     fCurrentGraph->SetEditable(kFALSE);
686     fCurrentGraph->SetMarkerStyle(20);
687     fCurrentGraph->SetMarkerSize(0.5);
688   }
689   //Set title offset
690   fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
691   gPad->Modified();
692   gPad->Update();
693   padsave->cd();
694 }
695
696 //______________________________________________________________________________
697 void AliTPCCalibViewerGUItime::DoDumpRuns()
698 {
699   //
700   // Dump the current run numbers to stdout
701   //
702   Int_t npoints=fRunNumbers.GetNrows();
703   Int_t    *sortIndex = new Int_t[npoints];
704   TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
705   Int_t run=0, prevRun=-1;
706   
707   for (Int_t irun=0;irun<npoints;++irun){
708     run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
709     if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
710     prevRun=run;
711   }
712   delete sortIndex;
713 }
714 //______________________________________________________________________________
715 void AliTPCCalibViewerGUItime::DoParLimitChange()
716 {
717   //
718   //
719   //
720   UpdateParName();
721   DoDraw();
722 }
723 //______________________________________________________________________________
724 void AliTPCCalibViewerGUItime::DoNewSelection() {
725    //
726    // decides whether to redraw if user makes another selection
727    //
728   UpdateParLimits();
729   fDrawString=GetDrawString();
730   fIsCustomDraw=kFALSE;
731   DoDraw();
732 }
733 //______________________________________________________________________________
734 void AliTPCCalibViewerGUItime::DoCustomDraw()
735 {
736   //
737   //
738   //
739   fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
740   if (fDrawString.Contains(">>")){
741     Warning("DoCustomDraw","Currently no user defined histograms allowed!");
742     return;
743   }
744   fIsCustomDraw=kTRUE;
745   DoDraw();
746 }
747 //______________________________________________________________________________
748 void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
749 {
750   //
751   //
752   //
753   if (fIsCustomDraw) DoCustomDraw();
754   else {
755     fDrawString=GetDrawString();
756     fIsCustomDraw=kFALSE;
757     DoDraw();
758   }
759 }
760 //______________________________________________________________________________
761 void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
762 {
763   //
764   // Draw selection button handling (x-variable)
765   //
766
767   if (id == -1) {
768     TGButton *btn = (TGButton *) gTQSender;
769     id = btn->WidgetId();
770   }
771   
772   Bool_t doDraw=kFALSE;
773   switch (id) {
774   case (kRadioXhist):
775     doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
776     if (doDraw){
777       fRadioXrun->SetState(kButtonUp);
778       fRadioXtime->SetState(kButtonUp);
779     }
780     break;
781   case (kRadioXrun):
782     doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
783     if (doDraw){
784       fRadioXhist->SetState(kButtonUp);
785       fRadioXtime->SetState(kButtonUp);
786     }
787     break;
788   case (kRadioXtime):
789     doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
790     if (doDraw){
791       fRadioXrun->SetState(kButtonUp);
792       fRadioXhist->SetState(kButtonUp);
793     }
794     break;
795   }
796   if (doDraw) DoCustomCutsDraw();
797 }
798 //______________________________________________________________________________
799 void AliTPCCalibViewerGUItime::UpdateParName()
800 {
801   //
802   // change parameter name
803   //
804   
805   Int_t par = (Int_t)(fNmbPar->GetNumber());
806   TString parName=par;
807   Int_t id=fListVariables->GetSelectedEntry()->EntryId();
808   if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
809   fLblPar->SetText(Form("Parameter: %s",parName.Data()));
810   fDrawString=GetDrawString();
811   fIsCustomDraw=kFALSE;
812 }
813
814 //______________________________________________________________________________
815 void AliTPCCalibViewerGUItime::UpdateParLimits()
816 {
817   //
818   // Adjust limits for TVectorT based variables
819   //
820   if (!fTree) return;
821   TString selectedVariableTitle="";
822   Int_t id=-1;
823   if (!fListVariables->GetSelectedEntry()) return;
824   selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
825   id=fListVariables->GetSelectedEntry()->EntryId();
826 //   printf("id: %d\n",id);
827   TString selectedVariable=selectedVariableTitle;
828   const TObject *key=(*fConfigParser)(id);
829   if (key) selectedVariable=(*fConfigParser)(id)->GetName();
830   
831   if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
832     fNmbPar->SetState(kFALSE);
833     fLblPar->SetText("Parameter: none");
834     return;
835   }
836   TVectorD *vD=0x0;
837   TVectorF *vF=0x0;
838   Int_t maxPar=0;
839   fTree->GetEntry(1);
840   TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
841   TString branchClass=branch->GetClassName();
842   Int_t event=0;
843   if (branchClass=="TVectorT<double>"){
844 //     branch->SetAddress(&vD);
845     fTree->SetBranchAddress(selectedVariable.Data(),&vD);
846     while (maxPar<2&&event<fTree->GetEntries()){
847       fTree->GetEntry(event++);
848       maxPar=vD->GetNrows();
849     }
850   } else if (branchClass=="TVectorT<float>"){
851 //     branch->SetAddress(&vF);
852     fTree->SetBranchAddress(selectedVariable.Data(),&vF);
853     while (maxPar<2&&event<fTree->GetEntries()){
854       fTree->GetEntry(event++);
855       maxPar=vF->GetNrows();
856     }
857   } else {
858     //class not known
859     fNmbPar->SetState(kFALSE);
860     return;
861   }
862 //   branch->ResetAddress();
863   fTree->ResetBranchAddresses();
864   fNmbPar->SetNumber(0);
865   fNmbPar->SetLimitValues(0,maxPar-1);
866   fNmbPar->SetState(kTRUE);
867   UpdateParName();
868 }
869 //______________________________________________________________________________
870 void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
871 {
872   //
873   // handle mouse events in the draw canvas
874   //
875   UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
876   Double_t valx=0.,valy=0.;
877   if (!fCurrentGraph) {
878     fLblRunNumberVal->SetText(Form("%05u",run));
879     fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
880     fLblValueXVal->SetText(Form("%.3e", valx));
881     fLblValueYVal->SetText(Form("%.3e", valy));
882     return;
883   }
884   TVirtualPad *padsave=gPad;
885   fCanvMain->GetCanvas()->cd();
886   Int_t n=fValuesY.GetNrows();
887   Double_t *arr=0x0;
888   arr=fValuesX.GetMatrixArray();
889
890   Int_t minDist=1000000;
891   Int_t minPoint=-1;
892   for (Int_t i=0;i<n;++i){
893     Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
894     Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
895     Int_t d   = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
896     if (d < minDist) {
897       minDist  = d;
898       minPoint = i;
899     }
900   }
901   if (minDist<2){
902     TTimeStamp t((Int_t)fTimeStamps[minPoint]);
903     t.GetDate(kTRUE,0,&yy,&mm,&dd);
904     t.GetTime(kTRUE,0,&HH,&MM,&SS);
905     run=(UInt_t)fRunNumbers[minPoint];
906     valx=fValuesX[minPoint];
907     valy=fValuesY[minPoint];
908   } else {
909     dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
910     valx=0.;
911     valy=0.;
912   }
913   fLblRunNumberVal->SetText(Form("%05u",run));
914   fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
915   if (fIsCustomDraw){
916     fLblValueXVal->SetText(Form("%.3e", valx));
917   }else{
918     if (fRadioXrun->GetState()==kButtonDown){
919       fLblValueXVal->SetText("Run");
920     } else if (fRadioXtime->GetState()==kButtonDown){
921       fLblValueXVal->SetText("Time");
922     }
923   }
924   fLblValueYVal->SetText(Form("%.3e", valy));
925   padsave->cd();
926   if (run==0) return;
927   if (event == kButton1Double ){
928     SetGuiTree(run);
929   }
930   //find closes point of current selection
931 }
932 //______________________________________________________________________________
933 void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
934 {
935   //
936   // create the AliTPCCalibViewerGUI tree for run
937   // cache tree in directory fOutputCacheDir
938   // retrieve file from this directory if it already exists
939   //
940
941   //try to find file for run in fOutputCacheDir
942   TString fileName=fOutputCacheDir;
943   if (!fileName.EndsWith("/")) fileName+="/";
944   fileName+=Form("guiTreeRun_%d.root",run);
945   TFile f(fileName.Data());
946   if (f.IsOpen()){
947     f.Close();
948     fCalibViewerGUI->Initialize(fileName.Data());
949     if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
950     return;
951   }
952   f.Close();
953   Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
954   if (sucess){
955     fCalibViewerGUI->Initialize(fileName.Data());
956     if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
957   }else{
958     fCalibViewerGUI->Reset();
959     if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
960   }
961 }
962 //______________________________________________________________________________
963 const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
964 {
965   //
966   //
967   //
968   TString s(in);
969   s.ReplaceAll("_{","|{");
970   s.ReplaceAll("_"," ");
971   s.ReplaceAll("|{","_{");
972   return s.Data();
973 }
974 //______________________________________________________________________________
975 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName) {
976    //
977    // Initialize and show GUI for presentation for demonstration purposes
978    // or for fast standalone use
979    //
980   TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
981   frmMain->SetWindowName("AliTPCCalibViewer GUItime");
982   frmMain->SetCleanup(kDeepCleanup);
983   
984   TGTab* tabMain = new TGTab(frmMain, 1000, 600);
985   frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
986   
987   TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
988   TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
989   
990   AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
991   tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
992   calibViewerTime->UseFile(fileName);
993   
994   AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
995   tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
996   calibViewerTime->SetCalibViewerGUI(calibViewer);
997   calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
998   
999   
1000   TObjArray *guiArray = new TObjArray();
1001   guiArray->Add(calibViewerTime);
1002   guiArray->Add(calibViewer);
1003   
1004   frmMain->MapSubwindows();
1005   frmMain->Resize();
1006   frmMain->MapWindow();
1007   
1008   return guiArray;
1009 }
1010