1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
20 ///////////////////////////////////////////////////////////////////////////////
25 #include <TDirectory.h>
29 #include <TVirtualPad.h>
31 #include <TObjArray.h>
32 #include <TObjString.h>
40 #include <TIterator.h>
43 #include <TTimeStamp.h>
46 #include <TGFileDialog.h>
47 #include <TGInputDialog.h>
50 #include <TGListBox.h>
51 #include <TGComboBox.h>
52 #include <TGNumberEntry.h>
54 #include <TRootEmbeddedCanvas.h>
55 #include <TGSplitter.h>
56 #include <TGButtonGroup.h>
63 #include "AliTPCCalibViewerGUI.h"
64 #include "AliTPCcalibDB.h"
65 #include "AliTPCConfigParser.h"
67 #include "AliTPCCalibViewerGUItime.h"
69 ClassImp(AliTPCCalibViewerGUItime)
71 AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
72 TGCompositeFrame(p,w,h),
76 fCalibViewerGUItab(0x0),
79 fCurrentRunDetails(-1),
80 fOutputCacheDir("/tmp"),
82 fConfigFile("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt"),
84 fIsCustomDraw(kFALSE),
90 //main canvas Top part, bottom part
92 //top left, centre, right
97 fContDrawSelSubRunTime(0x0),
118 fLblRunNumberVal(0x0),
125 fContCustomCuts(0x0),
128 fComboCustomDraw(0x0),
129 fComboCustomCuts(0x0)
137 //______________________________________________________________________________
138 AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
144 //______________________________________________________________________________
145 void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
149 // ======================================================================
150 // ************************* Display everything *************************
151 // ======================================================================
153 SetCleanup(kDeepCleanup);
155 // *****************************************************************************
156 // ************************* content of this MainFrame *************************
157 // *****************************************************************************
158 // top level container with horizontal layout
159 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
160 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
162 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
163 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
165 // ***********************************************************************
166 // ************************* content of fContLCR *************************
167 // ***********************************************************************
169 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
170 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
172 // left vertical splitter
173 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
174 splitLeft->SetFrame(fContLeft, kTRUE);
175 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
178 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
179 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
182 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
183 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
185 // right vertical splitter
186 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
187 splitRight->SetFrame(fContRight, kFALSE);
188 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
191 // ========================================================================
192 // ************************* content of fContLeft *************************
193 // ========================================================================
194 // --- draw button and tabLeft ---
196 // draw selection group
197 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
198 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
199 //x-axis variables selection, Run of Time
200 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
201 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
203 // ------------------------- content of fContDrawOpt -------------------------
207 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
208 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
209 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
210 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
212 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
213 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
214 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
215 fRadioXrun->SetToolTipText("Use run number as x-value");
218 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
219 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
220 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
221 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
225 fListVariables = new TGListBox(fContDrawSel);
226 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
227 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
230 //-------------------- run type selection ------------------------
232 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
233 fLblRunType->SetTextJustify(kTextLeft);
234 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
236 fComboRunType = new TGComboBox(fContDrawSel);
237 fComboRunType->EnableTextInput(kFALSE);
238 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
239 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
240 // fComboRunType->SetEnabled(kFALSE);
241 fComboRunType->Resize(0, 22);
243 //-------------------- parameter selection ------------------------
245 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
246 fLblPar->SetTextJustify(kTextLeft);
247 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
249 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
250 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
251 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
252 fNmbPar->SetState(kFALSE);
254 //-------------------- calibration type selection ------------------------
256 // draw selection group
257 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
258 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
261 fListCalibType = new TGListBox(fContCalibType);
262 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
263 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
264 fListCalibType->Resize(0,88);
265 fListCalibType->SetMultipleSelections();
268 // ==========================================================================
269 // ************************* content of fContCenter *************************
270 // ========================================================================
271 // main drawing canvas
272 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
273 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
274 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
275 // fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
276 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
277 fCanvMain->GetCanvas()->SetRightMargin(0.062);
278 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
280 // =========================================================================
281 // ************************* content of fContRight *************************
282 // ========================================================================
283 //group frame for value information
284 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
285 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
287 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
288 //value information labels
291 fLblRunNumber = new TGLabel(fContValues, "Run:");
292 fLblRunNumber->SetTextJustify(kTextLeft);
293 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
295 fLblRunNumberVal = new TGLabel(fContValues, "00000");
296 fLblRunNumberVal->SetTextJustify(kTextLeft);
297 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
299 fLblRunTime = new TGLabel(fContValues, "Time:");
300 fLblRunTime->SetTextJustify(kTextLeft);
301 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
303 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
304 fLblRunTimeVal->SetTextJustify(kTextLeft);
305 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
307 fLblValueX = new TGLabel(fContValues, "x-Value:");
308 fLblValueX->SetTextJustify(kTextLeft);
309 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
311 fLblValueXVal = new TGLabel(fContValues, "00000.000");
312 fLblValueXVal->SetTextJustify(kTextRight);
313 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
315 fLblValueY = new TGLabel(fContValues, "y-Value:");
316 fLblValueY->SetTextJustify(kTextLeft);
317 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
319 fLblValueYVal = new TGLabel(fContValues, "00000.000");
320 fLblValueYVal->SetTextJustify(kTextRight);
321 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
323 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
324 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
325 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
326 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
328 // =========================================================================
329 // ****************** bottom content of fContTopBottom *********************
330 // =========================================================================
332 // custom options container
333 // --- fComboCustom --- the custom draw line on the very low
334 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
335 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
337 // ------------------------- content of fContCustom -------------------------
338 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
339 fLblCustomDraw->SetTextJustify(kTextLeft);
340 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
341 // text field for custom draw command
342 fComboCustomDraw = new TGComboBox(fContCustom);
343 // fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
344 fComboCustomDraw->Resize(0, 22);
345 fComboCustomDraw->EnableTextInput(kTRUE);
346 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
347 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
348 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
351 // additional cuts container
352 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
353 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
355 // ------------------------- content of fContCustomCuts -------------------------
356 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
357 fLblCustomCuts->SetTextJustify(kTextLeft);
358 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
359 // combo text field for additional cuts
360 fComboCustomCuts = new TGComboBox(fContCustomCuts);
361 // fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
362 fComboCustomCuts->Resize(0, 22);
363 fComboCustomCuts->EnableTextInput(kTRUE);
364 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
365 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
366 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
368 SetWindowName("AliTPCCalibViewer GUI - Time");
370 Resize(GetDefaultSize());
373 //______________________________________________________________________________
374 void AliTPCCalibViewerGUItime::SetInitialValues(){
376 // Set inital selections of the gui
378 fRadioXrun->SetState(kButtonDown);
379 fRadioXtime->SetState(kButtonUp);
382 //______________________________________________________________________________
383 void AliTPCCalibViewerGUItime::UseFile(const char* fileName) {
385 // retrieve tree from file
387 TDirectory *save=gDirectory;
388 if (fFile) delete fFile;
389 fFile = TFile::Open(fileName);
391 if (!fFile->IsOpen()) return;
392 fTree=(TTree*)fFile->Get("dcs");
394 AliError(Form("Could not get tree from file '%s'",fileName));
398 if (fConfigParser) delete fConfigParser;
399 fConfigParser=new AliTPCConfigParser(gSystem->ExpandPathName(fConfigFile.Data()));
402 //______________________________________________________________________________
403 void AliTPCCalibViewerGUItime::FillRunTypes()
406 //Loop over the tree entries and fill the run types
410 fComboRunType->RemoveAll();
411 fComboRunType->AddEntry("ALL",id++);
412 fComboRunType->Select(0,kFALSE);
413 TObjString *runType=0x0;
414 Int_t nevets=fTree->GetEntries();
415 TBranch *branch=fTree->GetBranch("runType.");
417 branch->SetAddress(&runType);
418 fTree->SetBranchStatus("*",0);
419 fTree->SetBranchStatus("runType.*",1);
420 for (Int_t iev=0;iev<nevets;++iev){
421 fTree->GetEntry(iev);
422 TString type=runType->String();
423 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
425 branch->ResetAddress();
426 fTree->SetBranchStatus("*",1);
428 //______________________________________________________________________________
429 void AliTPCCalibViewerGUItime::FillCalibTypes()
432 // loop over configuration and fill calibration types
434 if (!fConfigParser) return;
436 fListCalibType->RemoveAll();
438 fConfigParser->ResetIter();
440 while ( (o=fConfigParser->NextKey()) ){
441 type=fConfigParser->GetData(o,kCalibType);
442 //remove whitespcaces
443 type.Remove(TString::kBoth,' ');
444 type.Remove(TString::kBoth,'\t');
445 if (type.IsNull()) type="UNSPECIFIED";
446 // printf("CalibType: '%s'\n",type.Data());
447 if (!fListCalibType->FindEntry(type.Data())) {
448 fListCalibType->AddEntry(type,id);
449 fListCalibType->Select(id++);
452 //add type for unspecified calibration type
454 if (!fListCalibType->FindEntry(type.Data())) {
455 fListCalibType->AddEntry(SubstituteUnderscores(type.Data()),id);
456 fListCalibType->Select(id++);
459 //______________________________________________________________________________
460 void AliTPCCalibViewerGUItime::Reload(Int_t first){
462 // reload the gui contents, this is needed after the input tree has changed
465 if ( !fTree ) return;
466 //in case of the first call create run type and calibration type entries
471 //activate all branches
472 fTree->SetBranchStatus("*",1);
473 //reset variables list
474 fListVariables->RemoveAll();
475 //get selected calibration types
477 fListCalibType->GetSelectedEntries(&calibTypes);
479 TObjArray *branchList = fTree->GetListOfBranches();
480 if ( !branchList ) return;
481 TIter nextBranch(branchList);
482 Int_t idCount=0,id=0;
483 TObject *objBranch=0;
484 while ( (objBranch=nextBranch()) ){
485 TString branchName(objBranch->GetName());
486 TString branchTitle(objBranch->GetName());
487 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
489 TString calibType="UNSPECIFIED";
491 const TObject *key=(*fConfigParser)(branchName.Data());
493 //test if branch is active
494 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
495 id=(*fConfigParser)()->IndexOf(key);
496 branchTitle=fConfigParser->GetData(key,kBranchTitle);
497 calibType=fConfigParser->GetData(key,kCalibType);
505 //check if branch is in selected calibration types
506 //if not, don't show it in the list and deactivate the branch.
507 Bool_t calibActive=kFALSE;
508 TIter nextCalib(&calibTypes);
510 while (objCalib=nextCalib())
511 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
514 TString s=branchName;
515 if (branchName.EndsWith(".")) s+="*";
516 fTree->SetBranchStatus(s.Data(),0);
519 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
522 //trick to display modifications
524 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
525 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
528 //______________________________________________________________________________
529 const char* AliTPCCalibViewerGUItime::GetDrawString(){
531 // create draw string for ttree by combining the user requestsa
534 TString selectedVariable="";
536 if (!fListVariables->GetSelectedEntry()) return "";
537 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
538 id=fListVariables->GetSelectedEntry()->EntryId();
539 // printf("id: %d\n",id);
540 TString branchName=selectedVariable;
541 const TObject *key=(*fConfigParser)(id);
542 if (key) branchName=(*fConfigParser)(id)->GetName();
543 //treat case of TVector
544 if (branchName.EndsWith(".")){
545 Int_t par = (Int_t)(fNmbPar->GetNumber());
546 branchName.Append(Form("fElements[%d]",par));
548 // if (fRadioXrun->GetState()==kButtonDown)
549 // selectedVariable.Append(":run");
550 // if (fRadioXtime->GetState()==kButtonDown)
551 // selectedVariable.Append(":time");
553 return branchName.Data();
555 //______________________________________________________________________________
556 const char* AliTPCCalibViewerGUItime::GetCutString(){
560 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
562 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
563 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
564 return cuts.GetTitle();
566 //______________________________________________________________________________
567 void AliTPCCalibViewerGUItime::DoDraw() {
568 TString drawString=fDrawString;
569 drawString.Prepend("run:time:");
570 TString cutString = GetCutString();
571 TString optString = "goff";
572 TVirtualPad *padsave=gPad;
573 fCanvMain->GetCanvas()->cd();
574 //delete old histogram and graph
576 delete fCurrentGraph;
578 //fCurrentHist in case of graph is the internal histogram,
579 // which is deletet by the graph itself.
582 if (fCurrentHist) delete fCurrentHist;
584 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
585 if (fTree->GetSelectedRows()==-1) return;
586 fValuesX.ResizeTo(fTree->GetSelectedRows());
587 fValuesY.ResizeTo(fTree->GetSelectedRows());
588 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
589 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
590 fValuesY.SetElements(fTree->GetV3());
591 fRunNumbers.SetElements(fTree->GetV1());
592 fTimeStamps.SetElements(fTree->GetV2());
594 Bool_t drawGraph=kFALSE;
596 if (fDrawString.Contains(":")){
597 fValuesX.SetElements(fTree->GetV4());
598 TString yname=fDrawString(0,fDrawString.First(':'));
599 TString xname=fDrawString(fDrawString.First(':')+1,fDrawString.Length());
600 title=Form("%s;%s;%s",fDrawString.Data(),xname.Data(),yname.Data());
607 TString yname=fDrawString.Data();
609 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
610 if ((*fConfigParser)(id)) yname=fConfigParser->GetData((*fConfigParser)(id),kBranchTitle);
611 yname=SubstituteUnderscores(yname.Data());
612 if (fNmbPar->GetButtonUp()->GetState()!=kButtonDisabled){
614 Int_t par = (Int_t)(fNmbPar->GetNumber());
615 if (fConfigParser && (*fConfigParser)(id)) {
616 TString yparname=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
617 yparname=SubstituteUnderscores(yparname);
622 if (fRadioXrun->GetState()==kButtonDown){
623 fValuesX.SetElements(fTree->GetV1());
624 title=Form("%s:Run;Run;%s",fDrawString.Data(),yname.Data());
625 } else if (fRadioXtime->GetState()==kButtonDown){
626 fValuesX.SetElements(fTree->GetV2());
627 title=Form("%s:Time;Time;%s",fDrawString.Data(),yname.Data());
632 //create graph according to selection
634 fCurrentGraph=new TGraph(fValuesX,fValuesY);
635 fCurrentGraph->Draw("alp");
636 fCurrentHist=fCurrentGraph->GetHistogram();
637 fCurrentHist->SetTitle(title.Data());
640 Float_t add=TMath::Abs(fValuesY.Min()*.05);
641 fCurrentHist=new TH1D("hist",Form("%s;%s",fDrawString.Data(),fDrawString.Data()),100,fValuesY.Min()-add,fValuesY.Max()+add);
642 fCurrentHist->FillN(fValuesY.GetNrows(),fValuesY.GetMatrixArray(),0);
643 fCurrentHist->Draw();
646 //Set time axis if choosen as x-variables
647 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw){
648 TAxis *xaxis=fCurrentHist->GetXaxis();
649 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
650 xaxis->SetTimeDisplay(1);
651 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
652 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
655 fCurrentGraph->SetEditable(kFALSE);
656 fCurrentGraph->SetMarkerStyle(20);
657 fCurrentGraph->SetMarkerSize(0.5);
660 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
666 //______________________________________________________________________________
667 void AliTPCCalibViewerGUItime::DoDumpRuns()
670 // Dump the current run numbers to stdout
672 Int_t npoints=fRunNumbers.GetNrows();
673 Int_t *sortIndex = new Int_t[npoints];
674 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
675 Int_t run=0, prevRun=-1;
677 for (Int_t irun=0;irun<npoints;++irun){
678 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
679 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
684 //______________________________________________________________________________
685 void AliTPCCalibViewerGUItime::DoParLimitChange()
693 //______________________________________________________________________________
694 void AliTPCCalibViewerGUItime::DoNewSelection() {
696 // decides whether to redraw if user makes another selection
699 fDrawString=GetDrawString();
700 fIsCustomDraw=kFALSE;
703 //______________________________________________________________________________
704 void AliTPCCalibViewerGUItime::DoCustomDraw()
709 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
710 if (fDrawString.Contains(">>")){
711 Warning("DoCustomDraw","Currently no user defined histograms allowed!");
717 //______________________________________________________________________________
718 void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
723 if (fIsCustomDraw) DoCustomDraw();
725 fDrawString=GetDrawString();
726 fIsCustomDraw=kFALSE;
730 //______________________________________________________________________________
731 void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
734 // Draw selection button handling (x-variable)
738 TGButton *btn = (TGButton *) gTQSender;
739 id = btn->WidgetId();
742 Bool_t doDraw=kFALSE;
745 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
747 fRadioXrun->SetState(kButtonUp);
748 fRadioXtime->SetState(kButtonUp);
752 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
754 fRadioXhist->SetState(kButtonUp);
755 fRadioXtime->SetState(kButtonUp);
759 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
761 fRadioXrun->SetState(kButtonUp);
762 fRadioXhist->SetState(kButtonUp);
766 if (doDraw) DoCustomCutsDraw();
768 //______________________________________________________________________________
769 void AliTPCCalibViewerGUItime::UpdateParName()
772 // change parameter name
775 Int_t par = (Int_t)(fNmbPar->GetNumber());
777 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
778 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
779 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
780 fDrawString=GetDrawString();
781 fIsCustomDraw=kFALSE;
784 //______________________________________________________________________________
785 void AliTPCCalibViewerGUItime::UpdateParLimits()
788 // Adjust limits for TVectorT based variables
791 TString selectedVariableTitle="";
793 if (!fListVariables->GetSelectedEntry()) return;
794 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
795 id=fListVariables->GetSelectedEntry()->EntryId();
796 // printf("id: %d\n",id);
797 TString selectedVariable=selectedVariableTitle;
798 const TObject *key=(*fConfigParser)(id);
799 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
801 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
802 fNmbPar->SetState(kFALSE);
803 fLblPar->SetText("Parameter: none");
809 TBranch *branch=fTree->GetBranch(selectedVariable.Data());
810 TString branchClass=branch->GetClassName();
811 if (branchClass=="TVectorT<double>"){
812 branch->SetAddress(&vD);
814 maxPar=vD->GetNrows();
815 } else if (branchClass=="TVectorT<float>"){
816 branch->SetAddress(&vF);
818 maxPar=vF->GetNrows();
821 fNmbPar->SetState(kFALSE);
824 branch->ResetAddress();
825 fNmbPar->SetNumber(0);
826 fNmbPar->SetLimitValues(0,maxPar-1);
827 fNmbPar->SetState(kTRUE);
830 //______________________________________________________________________________
831 void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
834 // handle mouse events in the draw canvas
836 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
837 Double_t valx=0.,valy=0.;
838 if (!fCurrentGraph) {
839 fLblRunNumberVal->SetText(Form("%05u",run));
840 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
841 fLblValueXVal->SetText(Form("%.3f", valx));
842 fLblValueYVal->SetText(Form("%.3f", valy));
845 TVirtualPad *padsave=gPad;
846 fCanvMain->GetCanvas()->cd();
847 Int_t n=fValuesY.GetNrows();
849 arr=fValuesX.GetMatrixArray();
851 Int_t minDist=1000000;
853 for (Int_t i=0;i<n;++i){
854 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
855 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
856 Int_t d = TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y));
863 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
864 t.GetDate(kTRUE,0,&yy,&mm,&dd);
865 t.GetTime(kTRUE,0,&HH,&MM,&SS);
866 run=(UInt_t)fRunNumbers[minPoint];
867 valx=fValuesX[minPoint];
868 valy=fValuesY[minPoint];
870 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
874 fLblRunNumberVal->SetText(Form("%05u",run));
875 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
877 fLblValueXVal->SetText(Form("%.3f", valx));
879 if (fRadioXrun->GetState()==kButtonDown){
880 fLblValueXVal->SetText("Run");
881 } else if (fRadioXtime->GetState()==kButtonDown){
882 fLblValueXVal->SetText("Time");
885 fLblValueYVal->SetText(Form("%.3f", valy));
888 if (event == kButton1Double ){
891 //find closes point of current selection
893 //______________________________________________________________________________
894 void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
897 // create the AliTPCCalibViewerGUI tree for run
898 // cache tree in directory fOutputCacheDir
899 // retrieve file from this directory if it already exists
902 //try to find file for run in fOutputCacheDir
903 TString fileName=fOutputCacheDir;
904 if (!fileName.EndsWith("/")) fileName+="/";
905 fileName+=Form("guiTreeRun_%d.root",run);
906 TFile f(fileName.Data());
909 fCalibViewerGUI->Initialize(fileName.Data());
910 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
914 Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
916 fCalibViewerGUI->Initialize(fileName.Data());
917 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
919 fCalibViewerGUI->Reset();
920 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
923 //______________________________________________________________________________
924 const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
930 s.ReplaceAll("_{","|{");
931 s.ReplaceAll("_"," ");
932 s.ReplaceAll("|{","_{");
935 //______________________________________________________________________________
936 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName) {
938 // Initialize and show GUI for presentation for demonstration purposes
939 // or for fast standalone use
941 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
942 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
943 frmMain->SetCleanup(kDeepCleanup);
945 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
946 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
948 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
949 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
951 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
952 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
953 calibViewerTime->UseFile(fileName);
955 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
956 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
957 calibViewerTime->SetCalibViewerGUI(calibViewer);
958 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
961 TObjArray *guiArray = new TObjArray();
962 guiArray->Add(calibViewerTime);
963 guiArray->Add(calibViewer);
965 frmMain->MapSubwindows();
967 frmMain->MapWindow();