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>
41 #include <TIterator.h>
44 #include <TTimeStamp.h>
47 #include <TGFileDialog.h>
48 #include <TGInputDialog.h>
51 #include <TGListBox.h>
52 #include <TGComboBox.h>
53 #include <TGNumberEntry.h>
55 #include <TRootEmbeddedCanvas.h>
56 #include <TGSplitter.h>
57 #include <TGButtonGroup.h>
64 #include "AliTPCCalibViewerGUI.h"
65 #include "AliTPCcalibDB.h"
66 #include "AliTPCConfigParser.h"
68 #include "AliTPCCalibViewerGUItime.h"
70 ClassImp(AliTPCCalibViewerGUItime)
72 AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
73 TGCompositeFrame(p,w,h),
77 fCalibViewerGUItab(0x0),
80 fCurrentRunDetails(-1),
81 fOutputCacheDir("/tmp"),
83 fConfigFile("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt"),
85 fIsCustomDraw(kFALSE),
91 //main canvas Top part, bottom part
93 //top left, centre, right
98 fContDrawSelSubRunTime(0x0),
119 fLblRunNumberVal(0x0),
126 fContCustomCuts(0x0),
129 fComboCustomDraw(0x0),
130 fComboCustomCuts(0x0)
138 //______________________________________________________________________________
139 AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
145 //______________________________________________________________________________
146 void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
150 // ======================================================================
151 // ************************* Display everything *************************
152 // ======================================================================
154 SetCleanup(kDeepCleanup);
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));
163 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
164 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
166 // ***********************************************************************
167 // ************************* content of fContLCR *************************
168 // ***********************************************************************
170 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
171 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
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));
179 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
180 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
183 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
184 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
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));
192 // ========================================================================
193 // ************************* content of fContLeft *************************
194 // ========================================================================
195 // --- draw button and tabLeft ---
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));
204 // ------------------------- content of fContDrawOpt -------------------------
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");
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");
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");
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()");
231 //-------------------- run type selection ------------------------
233 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
234 fLblRunType->SetTextJustify(kTextLeft);
235 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
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);
244 //-------------------- parameter selection ------------------------
246 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
247 fLblPar->SetTextJustify(kTextLeft);
248 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
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);
255 //-------------------- calibration type selection ------------------------
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));
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();
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);
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));
288 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
289 //value information labels
292 fLblRunNumber = new TGLabel(fContValues, "Run:");
293 fLblRunNumber->SetTextJustify(kTextLeft);
294 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
296 fLblRunNumberVal = new TGLabel(fContValues, "00000");
297 fLblRunNumberVal->SetTextJustify(kTextLeft);
298 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
300 fLblRunTime = new TGLabel(fContValues, "Time:");
301 fLblRunTime->SetTextJustify(kTextLeft);
302 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
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));
308 fLblValueX = new TGLabel(fContValues, "x-Value:");
309 fLblValueX->SetTextJustify(kTextLeft);
310 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
312 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
313 fLblValueXVal->SetTextJustify(kTextRight);
314 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
316 fLblValueY = new TGLabel(fContValues, "y-Value:");
317 fLblValueY->SetTextJustify(kTextLeft);
318 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
320 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
321 fLblValueYVal->SetTextJustify(kTextRight);
322 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
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.");
329 // =========================================================================
330 // ****************** bottom content of fContTopBottom *********************
331 // =========================================================================
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));
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()");
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));
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()");
369 SetWindowName("AliTPCCalibViewer GUI - Time");
371 Resize(GetDefaultSize());
374 //______________________________________________________________________________
375 void AliTPCCalibViewerGUItime::SetInitialValues(){
377 // Set inital selections of the gui
379 fRadioXrun->SetState(kButtonDown);
380 fRadioXtime->SetState(kButtonUp);
383 //______________________________________________________________________________
384 void AliTPCCalibViewerGUItime::UseFile(const char* fileName) {
386 // retrieve tree from file
388 //TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
390 TObjArray *arr=s.Tokenize("\n");
393 if (fTree) delete fTree;
394 fTree=new TChain("dcs");
395 while ( (o=next()) ){
396 fTree->AddFile(o->GetName());
400 if (fTree->GetEntries()==0){
401 AliError("No entries found in chain");
404 /* TDirectory *save=gDirectory;
405 if (fFile) delete fFile;
406 fFile = TFile::Open(fileName);
408 if (!fFile->IsOpen()) return;
409 fTree=(TTree*)fFile->Get("dcs");
411 AliError(Form("Could not get tree from file '%s'",fileName));
416 if (fConfigParser) delete fConfigParser;
417 fConfigParser=new AliTPCConfigParser(gSystem->ExpandPathName(fConfigFile.Data()));
421 //______________________________________________________________________________
422 void AliTPCCalibViewerGUItime::FillRunTypes()
425 //Loop over the tree entries and fill the run types
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.");
438 // branch->ResetAddress();
439 // fTree->SetBranchStatus("*",1);
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++);
449 // branch->ResetAddress();
450 fTree->ResetBranchAddresses();
451 fTree->SetBranchStatus("*",1);
453 //______________________________________________________________________________
454 void AliTPCCalibViewerGUItime::FillCalibTypes()
457 // loop over configuration and fill calibration types
459 if (!fConfigParser) return;
461 fListCalibType->RemoveAll();
463 fConfigParser->ResetIter();
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++);
477 //add type for unspecified calibration type
479 if (!fListCalibType->FindEntry(type.Data())) {
480 fListCalibType->AddEntry(SubstituteUnderscores(type.Data()),id);
481 fListCalibType->Select(id++);
484 //______________________________________________________________________________
485 void AliTPCCalibViewerGUItime::Reload(Int_t first){
487 // reload the gui contents, this is needed after the input tree has changed
490 if ( !fTree ) return;
491 //in case of the first call create run type and calibration type entries
496 //activate all branches
497 fTree->SetBranchStatus("*",1);
498 //reset variables list
499 fListVariables->RemoveAll();
500 //get selected calibration types
502 fListCalibType->GetSelectedEntries(&calibTypes);
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;
514 TString calibType="UNSPECIFIED";
516 const TObject *key=(*fConfigParser)(branchName.Data());
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);
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);
536 while ( (objCalib=nextCalib()) )
537 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
540 TString s=branchName;
541 if (branchName.EndsWith(".")) s+="*";
542 fTree->SetBranchStatus(s.Data(),0);
545 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
548 //trick to display modifications
550 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
551 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
554 //______________________________________________________________________________
555 const char* AliTPCCalibViewerGUItime::GetDrawString(){
557 // create draw string for ttree by combining the user requestsa
560 TString selectedVariable="";
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));
574 // if (fRadioXrun->GetState()==kButtonDown)
575 // selectedVariable.Append(":run");
576 // if (fRadioXtime->GetState()==kButtonDown)
577 // selectedVariable.Append(":time");
579 return branchName.Data();
581 //______________________________________________________________________________
582 const char* AliTPCCalibViewerGUItime::GetCutString(){
586 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
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();
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
602 delete fCurrentGraph;
604 //fCurrentHist in case of graph is the interrnal histogram,
605 // which is deleted by the graph itself.
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());
623 Bool_t drawGraph=kFALSE;
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());
636 TString yname=fDrawString.Data();
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){
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);
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());
659 title=Form("%s:%s",fDrawString.Data(),yname.Data());
662 //create graph according to selection
664 fCurrentGraph=new TGraph(fValuesX,fValuesY);
665 fCurrentGraph->Draw(fIsCustomDraw?"ap":"alp");
666 fCurrentHist=fCurrentGraph->GetHistogram();
667 fCurrentHist->SetTitle(title.Data());
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();
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);
685 fCurrentGraph->SetEditable(kFALSE);
686 fCurrentGraph->SetMarkerStyle(20);
687 fCurrentGraph->SetMarkerSize(0.5);
690 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
696 //______________________________________________________________________________
697 void AliTPCCalibViewerGUItime::DoDumpRuns()
700 // Dump the current run numbers to stdout
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;
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;
714 //______________________________________________________________________________
715 void AliTPCCalibViewerGUItime::DoParLimitChange()
723 //______________________________________________________________________________
724 void AliTPCCalibViewerGUItime::DoNewSelection() {
726 // decides whether to redraw if user makes another selection
729 fDrawString=GetDrawString();
730 fIsCustomDraw=kFALSE;
733 //______________________________________________________________________________
734 void AliTPCCalibViewerGUItime::DoCustomDraw()
739 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
740 if (fDrawString.Contains(">>")){
741 Warning("DoCustomDraw","Currently no user defined histograms allowed!");
747 //______________________________________________________________________________
748 void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
753 if (fIsCustomDraw) DoCustomDraw();
755 fDrawString=GetDrawString();
756 fIsCustomDraw=kFALSE;
760 //______________________________________________________________________________
761 void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
764 // Draw selection button handling (x-variable)
768 TGButton *btn = (TGButton *) gTQSender;
769 id = btn->WidgetId();
772 Bool_t doDraw=kFALSE;
775 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
777 fRadioXrun->SetState(kButtonUp);
778 fRadioXtime->SetState(kButtonUp);
782 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
784 fRadioXhist->SetState(kButtonUp);
785 fRadioXtime->SetState(kButtonUp);
789 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
791 fRadioXrun->SetState(kButtonUp);
792 fRadioXhist->SetState(kButtonUp);
796 if (doDraw) DoCustomCutsDraw();
798 //______________________________________________________________________________
799 void AliTPCCalibViewerGUItime::UpdateParName()
802 // change parameter name
805 Int_t par = (Int_t)(fNmbPar->GetNumber());
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;
814 //______________________________________________________________________________
815 void AliTPCCalibViewerGUItime::UpdateParLimits()
818 // Adjust limits for TVectorT based variables
821 TString selectedVariableTitle="";
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();
831 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
832 fNmbPar->SetState(kFALSE);
833 fLblPar->SetText("Parameter: none");
840 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
841 TString branchClass=branch->GetClassName();
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();
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();
859 fNmbPar->SetState(kFALSE);
862 // branch->ResetAddress();
863 fTree->ResetBranchAddresses();
864 fNmbPar->SetNumber(0);
865 fNmbPar->SetLimitValues(0,maxPar-1);
866 fNmbPar->SetState(kTRUE);
869 //______________________________________________________________________________
870 void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
873 // handle mouse events in the draw canvas
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));
884 TVirtualPad *padsave=gPad;
885 fCanvMain->GetCanvas()->cd();
886 Int_t n=fValuesY.GetNrows();
888 arr=fValuesX.GetMatrixArray();
890 Int_t minDist=1000000;
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)));
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];
909 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
913 fLblRunNumberVal->SetText(Form("%05u",run));
914 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
916 fLblValueXVal->SetText(Form("%.3e", valx));
918 if (fRadioXrun->GetState()==kButtonDown){
919 fLblValueXVal->SetText("Run");
920 } else if (fRadioXtime->GetState()==kButtonDown){
921 fLblValueXVal->SetText("Time");
924 fLblValueYVal->SetText(Form("%.3e", valy));
927 if (event == kButton1Double ){
930 //find closes point of current selection
932 //______________________________________________________________________________
933 void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
936 // create the AliTPCCalibViewerGUI tree for run
937 // cache tree in directory fOutputCacheDir
938 // retrieve file from this directory if it already exists
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());
948 fCalibViewerGUI->Initialize(fileName.Data());
949 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
953 Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
955 fCalibViewerGUI->Initialize(fileName.Data());
956 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
958 fCalibViewerGUI->Reset();
959 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
962 //______________________________________________________________________________
963 const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
969 s.ReplaceAll("_{","|{");
970 s.ReplaceAll("_"," ");
971 s.ReplaceAll("|{","_{");
974 //______________________________________________________________________________
975 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName) {
977 // Initialize and show GUI for presentation for demonstration purposes
978 // or for fast standalone use
980 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
981 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
982 frmMain->SetCleanup(kDeepCleanup);
984 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
985 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
987 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
988 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
990 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
991 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
992 calibViewerTime->UseFile(fileName);
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));
1000 TObjArray *guiArray = new TObjArray();
1001 guiArray->Add(calibViewerTime);
1002 guiArray->Add(calibViewer);
1004 frmMain->MapSubwindows();
1006 frmMain->MapWindow();