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 ///////////////////////////////////////////////////////////////////////////////
26 #include <TDirectory.h>
30 #include <TVirtualPad.h>
32 #include <TObjArray.h>
33 #include <TObjString.h>
42 #include <TIterator.h>
45 #include <TTimeStamp.h>
48 #include <TGFileDialog.h>
49 #include <TGInputDialog.h>
52 #include <TGListBox.h>
53 #include <TGComboBox.h>
54 #include <TGNumberEntry.h>
56 #include <TRootEmbeddedCanvas.h>
57 #include <TGSplitter.h>
58 #include <TGButtonGroup.h>
65 #include "AliTPCCalibViewerGUI.h"
66 #include "AliTPCcalibDB.h"
67 #include "AliTPCConfigParser.h"
69 #include "AliTPCCalibViewerGUItime.h"
71 ClassImp(AliTPCCalibViewerGUItime)
73 AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
74 TGCompositeFrame(p,w,h),
78 fCalibViewerGUItab(0x0),
81 fCurrentRunDetails(-1),
82 fOutputCacheDir("/tmp"),
85 fConfigParser(new AliTPCConfigParser),
86 fIsCustomDraw(kFALSE),
92 fGraphLimitEntries(10000),
94 //main canvas Top part, bottom part
96 //top left, centre, right
101 fChkDrawOptSame(0x0),
102 fComboAddDrawOpt(0x0),
104 fContDrawSelSubRunTime(0x0),
125 fLblRunNumberVal(0x0),
132 fContCustomCuts(0x0),
135 fComboCustomDraw(0x0),
136 fComboCustomCuts(0x0),
137 fTrashBox(new TObjArray)
143 gStyle->SetMarkerStyle(20);
144 gStyle->SetMarkerSize(0.5);
147 //______________________________________________________________________________
148 AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
152 delete fConfigParser;
155 //______________________________________________________________________________
156 void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
160 // ======================================================================
161 // ************************* Display everything *************************
162 // ======================================================================
164 SetCleanup(kDeepCleanup);
166 // *****************************************************************************
167 // ************************* content of this MainFrame *************************
168 // *****************************************************************************
169 // top level container with horizontal layout
170 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
171 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
173 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
174 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
176 // ***********************************************************************
177 // ************************* content of fContLCR *************************
178 // ***********************************************************************
180 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
181 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
183 // left vertical splitter
184 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
185 splitLeft->SetFrame(fContLeft, kTRUE);
186 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
189 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
190 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
193 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
194 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
196 // right vertical splitter
197 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
198 splitRight->SetFrame(fContRight, kFALSE);
199 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
202 // ========================================================================
203 // ************************* content of fContLeft *************************
204 // ========================================================================
205 // --- draw button and tabLeft ---
207 fContDrawOpt = new TGGroupFrame(fContLeft, "Draw options", kVerticalFrame | kFitWidth | kFitHeight);
208 fContLeft->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
209 fChkDrawOptSame = new TGCheckButton(fContDrawOpt, "Same");
210 fContDrawOpt->AddFrame(fChkDrawOptSame, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
211 fChkDrawOptSame->SetToolTipText("Add draw option 'same'");
212 // additional draw options combo box
213 fComboAddDrawOpt = new TGComboBox(fContDrawOpt);
214 fComboAddDrawOpt->Resize(0, 22);
215 fComboAddDrawOpt->EnableTextInput(kTRUE);
216 fContDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
217 // fComboAddDrawOpt->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral(=14)");
218 // fComboAddDrawOpt->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
220 // draw selection group
221 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
222 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
223 //x-axis variables selection, Run of Time
224 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
225 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
227 // ------------------------- content of fContDrawOpt -------------------------
231 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
232 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
233 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
234 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
236 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
237 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
238 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
239 fRadioXrun->SetToolTipText("Use run number as x-value");
242 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
243 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
244 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
245 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
249 fListVariables = new TGListBox(fContDrawSel);
250 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
251 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
254 //-------------------- run type selection ------------------------
256 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
257 fLblRunType->SetTextJustify(kTextLeft);
258 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
260 fComboRunType = new TGComboBox(fContDrawSel);
261 fComboRunType->EnableTextInput(kFALSE);
262 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
263 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
264 // fComboRunType->SetEnabled(kFALSE);
265 fComboRunType->Resize(0, 22);
267 //-------------------- parameter selection ------------------------
269 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
270 fLblPar->SetTextJustify(kTextLeft);
271 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
273 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
274 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
275 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
276 fNmbPar->SetState(kFALSE);
278 //-------------------- calibration type selection ------------------------
280 // draw selection group
281 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
282 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
285 fListCalibType = new TGListBox(fContCalibType);
286 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
287 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
288 fListCalibType->Resize(0,88);
289 fListCalibType->SetMultipleSelections();
292 // ==========================================================================
293 // ************************* content of fContCenter *************************
294 // ========================================================================
295 // main drawing canvas
296 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
297 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
298 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
299 // fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
300 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
301 fCanvMain->GetCanvas()->SetRightMargin(0.062);
302 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
304 // =========================================================================
305 // ************************* content of fContRight *************************
306 // ========================================================================
307 //group frame for value information
308 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
309 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
311 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
312 //value information labels
315 fLblRunNumber = new TGLabel(fContValues, "Run:");
316 fLblRunNumber->SetTextJustify(kTextLeft);
317 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
319 fLblRunNumberVal = new TGLabel(fContValues, "00000");
320 fLblRunNumberVal->SetTextJustify(kTextLeft);
321 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
323 fLblRunTime = new TGLabel(fContValues, "Time:");
324 fLblRunTime->SetTextJustify(kTextLeft);
325 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
327 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
328 fLblRunTimeVal->SetTextJustify(kTextLeft);
329 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
331 fLblValueX = new TGLabel(fContValues, "x-Value:");
332 fLblValueX->SetTextJustify(kTextLeft);
333 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
335 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
336 fLblValueXVal->SetTextJustify(kTextRight);
337 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
339 fLblValueY = new TGLabel(fContValues, "y-Value:");
340 fLblValueY->SetTextJustify(kTextLeft);
341 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
343 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
344 fLblValueYVal->SetTextJustify(kTextRight);
345 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
347 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
348 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
349 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
350 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
352 // =========================================================================
353 // ****************** bottom content of fContTopBottom *********************
354 // =========================================================================
356 // custom options container
357 // --- fComboCustom --- the custom draw line on the very low
358 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
359 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
361 // ------------------------- content of fContCustom -------------------------
362 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
363 fLblCustomDraw->SetTextJustify(kTextLeft);
364 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
365 // text field for custom draw command
366 fComboCustomDraw = new TGComboBox(fContCustom);
367 // fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
368 fComboCustomDraw->Resize(0, 22);
369 fComboCustomDraw->EnableTextInput(kTRUE);
370 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
371 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
372 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
375 // additional cuts container
376 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
377 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
379 // ------------------------- content of fContCustomCuts -------------------------
380 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
381 fLblCustomCuts->SetTextJustify(kTextLeft);
382 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
383 // combo text field for additional cuts
384 fComboCustomCuts = new TGComboBox(fContCustomCuts);
385 // fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
386 fComboCustomCuts->Resize(0, 22);
387 fComboCustomCuts->EnableTextInput(kTRUE);
388 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
389 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
390 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
392 SetWindowName("AliTPCCalibViewer GUI - Time");
394 Resize(GetDefaultSize());
397 //______________________________________________________________________________
398 void AliTPCCalibViewerGUItime::SetInitialValues(){
400 // Set inital selections of the gui
402 fRadioXrun->SetState(kButtonDown);
403 fRadioXtime->SetState(kButtonUp);
406 //______________________________________________________________________________
407 void AliTPCCalibViewerGUItime::UseFile(const char* fileName, const char* treeName) {
409 // retrieve tree from file
411 TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
412 // TString s(fileName);
413 TObjArray *arr=s.Tokenize("\n");
416 if (fTree) delete fTree;
417 fTree=new TChain(treeName);
418 while ( (o=next()) ){
419 fTree->AddFile(o->GetName());
422 if (!CheckChain()) return;
423 UseConfigFile(fConfigFile.Data());
427 //______________________________________________________________________________
428 void AliTPCCalibViewerGUItime::UseChain(TChain* chain = 0)
434 if (!CheckChain()) return;
435 //set configuration file
436 UseConfigFile(fConfigFile.Data());
439 //______________________________________________________________________________
440 Bool_t AliTPCCalibViewerGUItime::CheckChain()
443 // check whether cahin has entries
444 // decide whether to draw graphs in 2D
446 if (!fTree) return kFALSE;
448 Long64_t entries=fTree->GetEntries();
450 AliError("No entries found in chain");
453 //check whether to draw graphs
457 //______________________________________________________________________________
458 void AliTPCCalibViewerGUItime::UseConfigFile(const char* file)
461 // Use 'file' as configuration file
464 fConfigParser->ParseConfigFileTxt(fConfigFile.Data());
467 //______________________________________________________________________________
468 void AliTPCCalibViewerGUItime::FillRunTypes()
471 //Loop over the tree entries and fill the run types
475 fComboRunType->RemoveAll();
476 fComboRunType->AddEntry("ALL",id++);
477 fComboRunType->Select(0,kFALSE);
478 if (!fTree->GetBranch("runType.")) return;
479 TObjString *runType=0x0;
480 Int_t nevets=fTree->GetEntries();
481 fTree->SetBranchStatus("*",0);
482 fTree->SetBranchStatus("runType.*",1);
483 fTree->SetBranchAddress("runType.",&runType);
484 for (Int_t iev=0;iev<nevets;++iev){
485 fTree->GetEntry(iev);
486 TString type=runType->String();
487 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
489 fTree->ResetBranchAddresses();
490 fTree->SetBranchStatus("*",1);
492 //______________________________________________________________________________
493 void AliTPCCalibViewerGUItime::FillCalibTypes()
496 // loop over configuration and fill calibration types
499 fListCalibType->RemoveAll();
501 fConfigParser->ResetIter();
503 while ( (o=fConfigParser->NextKey()) ){
504 type=fConfigParser->GetData(o,kCalibType);
505 //remove whitespcaces
506 type.Remove(TString::kBoth,' ');
507 type.Remove(TString::kBoth,'\t');
508 if (type.IsNull()) type="UNSPECIFIED";
509 // printf("CalibType: '%s'\n",type.Data());
510 if (!fListCalibType->FindEntry(type.Data())) {
511 fListCalibType->AddEntry(type,id);
512 fListCalibType->Select(id++);
515 //add type for unspecified calibration type
517 if (!fListCalibType->FindEntry(type.Data())) {
518 fListCalibType->AddEntry(SubstituteUnderscores(type.Data()),id);
519 fListCalibType->Select(id++);
522 //______________________________________________________________________________
523 void AliTPCCalibViewerGUItime::CheckDrawGraph()
526 // Check whether to draw graphs in 2D mode based on the number of entries in the chain
527 // GetEstimate() returns the maximum size of the arrays stored in GetV1()...
531 if (fTree->GetEntries()<fTree->GetEstimate()) fNoGraph=kFALSE;
533 //______________________________________________________________________________
534 void AliTPCCalibViewerGUItime::Reload(Int_t first)
537 // reload the gui contents, this is needed after the input tree has changed
540 if ( !fTree ) return;
541 //in case of the first call create run type and calibration type entries
546 //activate all branches
547 fTree->SetBranchStatus("*",1);
548 //reset variables list
549 fListVariables->RemoveAll();
550 //get selected calibration types
552 fListCalibType->GetSelectedEntries(&calibTypes);
554 TObjArray *branchList = fTree->GetListOfBranches();
555 if ( !branchList ) return;
556 TIter nextBranch(branchList);
557 Int_t idCount=0,id=0;
558 TObject *objBranch=0;
559 while ( (objBranch=nextBranch()) ){
560 TString branchName(objBranch->GetName());
561 TString branchTitle(objBranch->GetName());
562 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
564 TString calibType="UNSPECIFIED";
566 const TObject *key=(*fConfigParser)(branchName.Data());
568 //test if branch is active
569 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
570 id=(*fConfigParser)()->IndexOf(key);
571 // branchTitle=fConfigParser->GetData(key,kBranchTitle);
572 calibType=fConfigParser->GetData(key,kCalibType);
580 if (calibType.IsNull()) calibType="UNSPECIFIED";
581 //check if branch is in selected calibration types
582 //if not, don't show it in the list and deactivate the branch.
583 Bool_t calibActive=kFALSE;
584 TIter nextCalib(&calibTypes);
586 while ( (objCalib=nextCalib()) )
587 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
590 TString s=branchName;
591 if (branchName.EndsWith(".")) s+="*";
592 fTree->SetBranchStatus(s.Data(),0);
595 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
598 //trick to display modifications
600 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
601 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
604 //______________________________________________________________________________
605 const char* AliTPCCalibViewerGUItime::GetDrawString(){
607 // create draw string for ttree by combining the user requestsa
610 TString selectedVariable="";
612 if (!fListVariables->GetSelectedEntry()) return "";
613 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
614 id=fListVariables->GetSelectedEntry()->EntryId();
615 // printf("id: %d\n",id);
616 TString branchName=selectedVariable;
617 const TObject *key=(*fConfigParser)(id);
618 if (key) branchName=(*fConfigParser)(id)->GetName();
619 //treat case of TVector
620 if (branchName.EndsWith(".")){
621 Int_t par = (Int_t)(fNmbPar->GetNumber());
622 branchName.Append(Form("fElements[%d]",par));
624 // if (fRadioXrun->GetState()==kButtonDown)
625 // selectedVariable.Append(":run");
626 // if (fRadioXtime->GetState()==kButtonDown)
627 // selectedVariable.Append(":time");
629 return branchName.Data();
631 //______________________________________________________________________________
632 const char* AliTPCCalibViewerGUItime::GetDrawOption(){
634 // get user selected draw options
637 if (fComboAddDrawOpt->GetSelectedEntry()) drawOpt=fComboAddDrawOpt->GetSelectedEntry()->GetTitle();
638 if (fChkDrawOptSame->GetState()==kButtonDown && !drawOpt.Contains("same",TString::kIgnoreCase))
640 return drawOpt.Data();
642 //______________________________________________________________________________
643 void AliTPCCalibViewerGUItime::GetCutString(TString &cutStr){
647 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
649 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
650 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
651 cutStr=cuts.GetTitle();
653 //______________________________________________________________________________
654 void AliTPCCalibViewerGUItime::UpdateValueArrays(Bool_t withGraph)
660 fValuesX.ResizeTo(1);
661 fValuesY.ResizeTo(1);
662 fRunNumbers.ResizeTo(1);
663 fTimeStamps.ResizeTo(1);
665 fValuesX.ResizeTo(fTree->GetSelectedRows());
666 fValuesY.ResizeTo(fTree->GetSelectedRows());
667 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
668 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
669 fValuesY.SetElements(fTree->GetV3());
670 fRunNumbers.SetElements(fTree->GetV1());
671 fTimeStamps.SetElements(fTree->GetV2());
674 //______________________________________________________________________________
675 void AliTPCCalibViewerGUItime::GetHistogramTitle(TString &title)
678 // Create string for histogram title
682 Int_t pos=title.First(">>");
683 if (pos>0) title=title(0,pos);
685 if (fRadioXrun->GetState()==kButtonDown){
687 } else if (fRadioXtime->GetState()==kButtonDown){
693 TObjArray *arr=title.Tokenize(":");
698 TIter next(arr,kIterBackward);
699 while ( (o=next()) ){
700 TString varName=o->GetName();
702 //substitue variable names with names in configuration file if available
703 if ((*fConfigParser)()->GetEntries()){
704 TString branchName=varName;
706 if (branchName.Contains('.')) branchName=branchName(0,branchName.First('.')+1);
707 //chek if a configuration for that branch is available
708 const TObject *oBranch=(*fConfigParser)(branchName.Data());
710 TString branchTitle=fConfigParser->GetData(oBranch,kBranchTitle);
711 if (!branchTitle.IsNull()){
712 //check for TVectorT type branch
713 //add parameter name if available
714 if (varName.Contains("fElements")){
715 TString parStr=varName(varName.First('[')+1,varName.Length()-varName.First('[')-2);
718 TString yparname=fConfigParser->GetData(oBranch,par+kParamNames);
719 if (!yparname.IsNull()){
720 branchTitle+=yparname;
728 varName=SubstituteUnderscores(branchTitle.Data());
735 //______________________________________________________________________________
736 void AliTPCCalibViewerGUItime::DoDraw() {
737 TString drawString=fDrawString;
739 GetCutString(cutString);
740 TString optString = GetDrawOption();
741 Bool_t graphOutput=!fNoGraph; //ttree buffer for V1, V2... too small
742 graphOutput&=(drawString.First(">>")<0); //histogram output in custom draw
743 graphOutput&=fRadioXhist->GetState()!=kButtonDown; //histogram drawing selected
744 graphOutput&=!(fIsCustomDraw&&!fDrawString.Contains(":")); //custom draw 1D
745 Bool_t drawSame=optString.Contains("same",TString::kIgnoreCase);
746 // optString+="goff";
748 drawString.Prepend("run:time:");
752 if (fRadioXrun->GetState()==kButtonDown){
754 } else if (fRadioXtime->GetState()==kButtonDown){
759 TVirtualPad *padsave=gPad;
760 fCanvMain->GetCanvas()->cd();
761 //delete old histograms and graphs
767 // if (fCurrentGraph) {
768 // delete fCurrentGraph;
769 // fCurrentGraph=0x0;
770 // //fCurrentHist in case of graph is the interrnal histogram,
771 // // which is deleted by the graph itself.
774 // if (fCurrentHist) {
775 // delete fCurrentHist;
779 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
780 if (fTree->GetSelectedRows()==-1) return;
781 UpdateValueArrays(graphOutput);
783 GetHistogramTitle(title);
784 Bool_t drawGraph=kFALSE;
787 if (fDrawString.Contains(":")){
788 fValuesX.SetElements(fTree->GetV4());
795 if (fRadioXrun->GetState()==kButtonDown){
796 fValuesX.SetElements(fTree->GetV1());
797 } else if (fRadioXtime->GetState()==kButtonDown){
798 fValuesX.SetElements(fTree->GetV2());
803 }//create graph according to selection
805 TGraph *graph=new TGraph(fValuesX,fValuesY);
807 if (!drawSame) grDraw+="a";
808 if (!fIsCustomDraw) grDraw+="l";
809 graph->Draw(grDraw.Data());
810 graph->SetEditable(kFALSE);
811 TH1 *hist=graph->GetHistogram();
812 hist->SetTitle(title.Data());
813 fTrashBox->Add(graph);
814 graph->SetLineColor(fTrashBox->GetEntries());
815 graph->SetMarkerColor(fTrashBox->GetEntries());
821 TH1 *hist=fTree->GetHistogram();
822 hist->SetTitle(title.Data());
823 // hist->Draw(optString.Data());
824 fTrashBox->Add(hist);
825 hist->SetLineColor(fTrashBox->GetEntries());
826 hist->SetMarkerColor(fTrashBox->GetEntries());
827 if (!drawSame) fCurrentHist=hist;
830 //Set time axis if choosen as x-variables
831 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw){
832 TAxis *xaxis=fCurrentHist->GetXaxis();
833 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
834 xaxis->SetTimeDisplay(1);
835 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
836 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
839 if (!drawSame) fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
845 //______________________________________________________________________________
846 void AliTPCCalibViewerGUItime::DoDumpRuns()
849 // Dump the current run numbers to stdout
851 Int_t npoints=fRunNumbers.GetNrows();
852 Int_t *sortIndex = new Int_t[npoints];
853 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
854 Int_t run=0, prevRun=-1;
856 for (Int_t irun=0;irun<npoints;++irun){
857 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
858 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
863 //______________________________________________________________________________
864 void AliTPCCalibViewerGUItime::DoParLimitChange()
872 //______________________________________________________________________________
873 void AliTPCCalibViewerGUItime::DoNewSelection() {
875 // decides whether to redraw if user makes another selection
878 fDrawString=GetDrawString();
879 fIsCustomDraw=kFALSE;
882 //______________________________________________________________________________
883 void AliTPCCalibViewerGUItime::DoCustomDraw()
888 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
889 // if (fDrawString.Contains(">>")){
890 // Warning("DoCustomDraw","Currently no user defined histograms allowed!");
893 fNmbPar->SetState(kFALSE);
897 //______________________________________________________________________________
898 void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
903 if (fIsCustomDraw) DoCustomDraw();
905 fDrawString=GetDrawString();
906 fIsCustomDraw=kFALSE;
910 //______________________________________________________________________________
911 void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
914 // Draw selection button handling (x-variable)
918 TGButton *btn = (TGButton *) gTQSender;
919 id = btn->WidgetId();
922 Bool_t doDraw=kFALSE;
925 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
927 fRadioXrun->SetState(kButtonUp);
928 fRadioXtime->SetState(kButtonUp);
932 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
934 fRadioXhist->SetState(kButtonUp);
935 fRadioXtime->SetState(kButtonUp);
939 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
941 fRadioXrun->SetState(kButtonUp);
942 fRadioXhist->SetState(kButtonUp);
946 if (doDraw) DoCustomCutsDraw();
948 //______________________________________________________________________________
949 void AliTPCCalibViewerGUItime::UpdateParName()
952 // change parameter name
955 Int_t par = (Int_t)(fNmbPar->GetNumber());
957 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
958 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
959 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
960 fDrawString=GetDrawString();
961 fIsCustomDraw=kFALSE;
964 //______________________________________________________________________________
965 void AliTPCCalibViewerGUItime::UpdateParLimits()
968 // Adjust limits for TVectorT based variables
971 TString selectedVariableTitle="";
973 if (!fListVariables->GetSelectedEntry()) return;
974 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
975 id=fListVariables->GetSelectedEntry()->EntryId();
976 // printf("id: %d\n",id);
977 TString selectedVariable=selectedVariableTitle;
978 const TObject *key=(*fConfigParser)(id);
979 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
981 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
982 fNmbPar->SetState(kFALSE);
983 fLblPar->SetText("Parameter: none");
990 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
991 TString branchClass=branch->GetClassName();
993 if (branchClass=="TVectorT<double>"){
994 // branch->SetAddress(&vD);
995 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
996 while (maxPar<2&&event<fTree->GetEntries()){
997 fTree->GetEntry(event++);
998 maxPar=vD->GetNrows();
1000 } else if (branchClass=="TVectorT<float>"){
1001 // branch->SetAddress(&vF);
1002 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
1003 while (maxPar<2&&event<fTree->GetEntries()){
1004 fTree->GetEntry(event++);
1005 maxPar=vF->GetNrows();
1009 fNmbPar->SetState(kFALSE);
1012 // branch->ResetAddress();
1013 fTree->SetBranchAddress(selectedVariable.Data(),0x0);
1014 fNmbPar->SetNumber(0);
1015 fNmbPar->SetLimitValues(0,maxPar-1);
1016 fNmbPar->SetState(kTRUE);
1019 //______________________________________________________________________________
1020 void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
1023 // handle mouse events in the draw canvas
1025 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
1026 Double_t valx=0.,valy=0.;
1027 if (!fCurrentGraph) {
1028 fLblRunNumberVal->SetText(Form("%05u",run));
1029 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
1030 fLblValueXVal->SetText(Form("%.3e", valx));
1031 fLblValueYVal->SetText(Form("%.3e", valy));
1034 TVirtualPad *padsave=gPad;
1035 fCanvMain->GetCanvas()->cd();
1036 Int_t n=fValuesY.GetNrows();
1038 arr=fValuesX.GetMatrixArray();
1040 Int_t minDist=1000000;
1042 for (Int_t i=0;i<n;++i){
1043 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
1044 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
1045 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
1052 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
1053 t.GetDate(kTRUE,0,&yy,&mm,&dd);
1054 t.GetTime(kTRUE,0,&HH,&MM,&SS);
1055 run=(UInt_t)fRunNumbers[minPoint];
1056 valx=fValuesX[minPoint];
1057 valy=fValuesY[minPoint];
1059 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
1063 fLblRunNumberVal->SetText(Form("%05u",run));
1064 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
1066 fLblValueXVal->SetText(Form("%.3e", valx));
1068 if (fRadioXrun->GetState()==kButtonDown){
1069 fLblValueXVal->SetText("Run");
1070 } else if (fRadioXtime->GetState()==kButtonDown){
1071 fLblValueXVal->SetText("Time");
1074 fLblValueYVal->SetText(Form("%.3e", valy));
1077 if (event == kButton1Double ){
1080 //find closes point of current selection
1082 //______________________________________________________________________________
1083 void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
1086 // create the AliTPCCalibViewerGUI tree for run
1087 // cache tree in directory fOutputCacheDir
1088 // retrieve file from this directory if it already exists
1091 //try to find file for run in fOutputCacheDir
1092 TString fileName=fOutputCacheDir;
1093 if (!fileName.EndsWith("/")) fileName+="/";
1094 fileName+=Form("guiTreeRun_%d.root",run);
1095 TFile f(fileName.Data());
1098 fCalibViewerGUI->Initialize(fileName.Data());
1099 fCalibViewerGUI->Reload();
1100 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
1104 Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
1106 fCalibViewerGUI->Initialize(fileName.Data());
1107 fCalibViewerGUI->Reload();
1108 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
1110 fCalibViewerGUI->Reset();
1111 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
1114 //______________________________________________________________________________
1115 const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
1121 s.ReplaceAll("_{","|{");
1122 s.ReplaceAll("_"," ");
1123 s.ReplaceAll("|{","_{");
1126 //______________________________________________________________________________
1127 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName, const char* treeName) {
1129 // Initialize and show GUI for presentation for demonstration purposes
1130 // or for fast standalone use
1132 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1133 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1134 frmMain->SetCleanup(kDeepCleanup);
1136 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1137 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1139 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1140 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
1142 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1143 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1144 calibViewerTime->SetConfigFileName("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt");
1145 calibViewerTime->UseFile(fileName, treeName);
1147 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
1148 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1149 calibViewerTime->SetCalibViewerGUI(calibViewer);
1150 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
1153 TObjArray *guiArray = new TObjArray();
1154 guiArray->Add(calibViewerTime);
1155 guiArray->Add(calibViewer);
1157 frmMain->MapSubwindows();
1159 frmMain->MapWindow();
1164 //______________________________________________________________________________
1165 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(TChain *chain) {
1167 // Initialize and show GUI for presentation for demonstration purposes
1168 // or for fast standalone use
1170 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1171 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1172 frmMain->SetCleanup(kDeepCleanup);
1174 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1175 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1177 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1179 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1180 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1181 calibViewerTime->UseChain(chain);
1183 TObjArray *guiArray = new TObjArray();
1184 guiArray->Add(calibViewerTime);
1186 frmMain->MapSubwindows();
1188 frmMain->MapWindow();