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>
49 #include <TGFileDialog.h>
50 #include <TGInputDialog.h>
53 #include <TGListBox.h>
54 #include <TGComboBox.h>
55 #include <TGNumberEntry.h>
57 #include <TRootEmbeddedCanvas.h>
58 #include <TGSplitter.h>
59 #include <TGButtonGroup.h>
66 #include "AliTPCCalibViewerGUI.h"
67 #include "AliTPCCalibViewer.h"
68 #include "AliTPCcalibDB.h"
69 #include "AliTPCConfigParser.h"
71 #include "AliTPCCalibViewerGUItime.h"
73 ClassImp(AliTPCCalibViewerGUItime)
75 AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
76 TGCompositeFrame(p,w,h),
80 fCalibViewerGUItab(0x0),
83 fCurrentRunDetails(-1),
84 fOutputCacheDir("/tmp"),
87 fConfigParser(new AliTPCConfigParser),
88 fIsCustomDraw(kFALSE),
94 fGraphLimitEntries(10000),
95 fMapRefTrees(new TMap),
97 //main canvas Top part, bottom part
99 //top left, centre, right
104 fChkDrawOptSame(0x0),
105 fComboAddDrawOpt(0x0),
107 fContDrawSelSubRunTime(0x0),
128 fLblRunNumberVal(0x0),
135 fContCustomCuts(0x0),
138 fComboCustomDraw(0x0),
139 fComboCustomCuts(0x0),
140 fTrashBox(new TObjArray)
145 fMapRefTrees->SetOwnerKeyValue();
146 fTrashBox->SetOwner();
148 gStyle->SetMarkerStyle(20);
149 gStyle->SetMarkerSize(0.5);
152 //______________________________________________________________________________
153 AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
157 delete fConfigParser;
161 //______________________________________________________________________________
162 void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
166 // ======================================================================
167 // ************************* Display everything *************************
168 // ======================================================================
170 SetCleanup(kDeepCleanup);
172 // *****************************************************************************
173 // ************************* content of this MainFrame *************************
174 // *****************************************************************************
175 // top level container with horizontal layout
176 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
177 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
179 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
180 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
182 // ***********************************************************************
183 // ************************* content of fContLCR *************************
184 // ***********************************************************************
186 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
187 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
189 // left vertical splitter
190 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
191 splitLeft->SetFrame(fContLeft, kTRUE);
192 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
195 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
196 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
199 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
200 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
202 // right vertical splitter
203 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
204 splitRight->SetFrame(fContRight, kFALSE);
205 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
208 // ========================================================================
209 // ************************* content of fContLeft *************************
210 // ========================================================================
211 // --- draw button and tabLeft ---
213 fContDrawOpt = new TGGroupFrame(fContLeft, "Draw options", kVerticalFrame | kFitWidth | kFitHeight);
214 fContLeft->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
215 fChkDrawOptSame = new TGCheckButton(fContDrawOpt, "Same");
216 fContDrawOpt->AddFrame(fChkDrawOptSame, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
217 fChkDrawOptSame->SetToolTipText("Add draw option 'same'");
218 // additional draw options combo box
219 fComboAddDrawOpt = new TGComboBox(fContDrawOpt);
220 fComboAddDrawOpt->Resize(0, 22);
221 fComboAddDrawOpt->EnableTextInput(kTRUE);
222 fContDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
223 // fComboAddDrawOpt->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral(=14)");
224 // fComboAddDrawOpt->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
226 // draw selection group
227 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
228 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
229 //x-axis variables selection, Run of Time
230 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
231 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
233 // ------------------------- content of fContDrawOpt -------------------------
237 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
238 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
239 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
240 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
242 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
243 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
244 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
245 fRadioXrun->SetToolTipText("Use run number as x-value");
248 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
249 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
250 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
251 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
255 fListVariables = new TGListBox(fContDrawSel);
256 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
257 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
260 //-------------------- run type selection ------------------------
262 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
263 fLblRunType->SetTextJustify(kTextLeft);
264 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
266 fComboRunType = new TGComboBox(fContDrawSel);
267 fComboRunType->EnableTextInput(kFALSE);
268 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
269 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
270 // fComboRunType->SetEnabled(kFALSE);
271 fComboRunType->Resize(0, 22);
273 //-------------------- parameter selection ------------------------
275 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
276 fLblPar->SetTextJustify(kTextLeft);
277 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
279 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
280 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
281 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
282 fNmbPar->SetState(kFALSE);
284 //-------------------- calibration type selection ------------------------
286 // draw selection group
287 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
288 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
291 fListCalibType = new TGListBox(fContCalibType);
292 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
293 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
294 fListCalibType->Resize(0,88);
295 fListCalibType->SetMultipleSelections();
298 // ==========================================================================
299 // ************************* content of fContCenter *************************
300 // ========================================================================
301 // main drawing canvas
302 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
303 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
304 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
305 // fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
306 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
307 fCanvMain->GetCanvas()->SetRightMargin(0.062);
308 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
310 // =========================================================================
311 // ************************* content of fContRight *************************
312 // ========================================================================
313 //group frame for value information
314 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
315 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
317 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
318 //value information labels
321 fLblRunNumber = new TGLabel(fContValues, "Run:");
322 fLblRunNumber->SetTextJustify(kTextLeft);
323 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
325 fLblRunNumberVal = new TGLabel(fContValues, "00000");
326 fLblRunNumberVal->SetTextJustify(kTextLeft);
327 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
329 fLblRunTime = new TGLabel(fContValues, "Time:");
330 fLblRunTime->SetTextJustify(kTextLeft);
331 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
333 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
334 fLblRunTimeVal->SetTextJustify(kTextLeft);
335 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
337 fLblValueX = new TGLabel(fContValues, "x-Value:");
338 fLblValueX->SetTextJustify(kTextLeft);
339 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
341 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
342 fLblValueXVal->SetTextJustify(kTextRight);
343 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
345 fLblValueY = new TGLabel(fContValues, "y-Value:");
346 fLblValueY->SetTextJustify(kTextLeft);
347 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
349 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
350 fLblValueYVal->SetTextJustify(kTextRight);
351 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
353 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
354 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
355 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
356 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
358 // =========================================================================
359 // ****************** bottom content of fContTopBottom *********************
360 // =========================================================================
362 // custom options container
363 // --- fComboCustom --- the custom draw line on the very low
364 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
365 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
367 // ------------------------- content of fContCustom -------------------------
368 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
369 fLblCustomDraw->SetTextJustify(kTextLeft);
370 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
371 // text field for custom draw command
372 fComboCustomDraw = new TGComboBox(fContCustom);
373 // fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
374 fComboCustomDraw->Resize(0, 22);
375 fComboCustomDraw->EnableTextInput(kTRUE);
376 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
377 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
378 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
381 // additional cuts container
382 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
383 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
385 // ------------------------- content of fContCustomCuts -------------------------
386 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
387 fLblCustomCuts->SetTextJustify(kTextLeft);
388 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
389 // combo text field for additional cuts
390 fComboCustomCuts = new TGComboBox(fContCustomCuts);
391 // fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
392 fComboCustomCuts->Resize(0, 22);
393 fComboCustomCuts->EnableTextInput(kTRUE);
394 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
395 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
396 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
398 SetWindowName("AliTPCCalibViewer GUI - Time");
400 Resize(GetDefaultSize());
403 //______________________________________________________________________________
404 void AliTPCCalibViewerGUItime::SetInitialValues(){
406 // Set inital selections of the gui
408 fRadioXrun->SetState(kButtonDown);
409 fRadioXtime->SetState(kButtonUp);
412 //______________________________________________________________________________
413 void AliTPCCalibViewerGUItime::UseFile(const char* fileName, const char* treeName) {
415 // retrieve tree from file
417 TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
418 // TString s(fileName);
419 TObjArray *arr=s.Tokenize("\n");
422 if (fTree) delete fTree;
423 fTree=new TChain(treeName);
424 while ( (o=next()) ){
425 fTree->AddFile(o->GetName());
428 if (!CheckChain()) return;
429 UseConfigFile(fConfigFile.Data());
433 //______________________________________________________________________________
434 void AliTPCCalibViewerGUItime::UseChain(TChain* chain = 0)
440 if (!CheckChain()) return;
441 //set configuration file
442 UseConfigFile(fConfigFile.Data());
445 //______________________________________________________________________________
446 Bool_t AliTPCCalibViewerGUItime::CheckChain()
449 // check whether cahin has entries
450 // decide whether to draw graphs in 2D
452 if (!fTree) return kFALSE;
454 Long64_t entries=fTree->GetEntries();
456 AliError("No entries found in chain");
459 //check whether to draw graphs
463 //______________________________________________________________________________
464 void AliTPCCalibViewerGUItime::UseConfigFile(const char* file)
467 // Use 'file' as configuration file
470 fConfigParser->ParseConfigFileTxt(fConfigFile.Data());
473 //______________________________________________________________________________
474 void AliTPCCalibViewerGUItime::FillRunTypes()
477 //Loop over the tree entries and fill the run types
481 fComboRunType->RemoveAll();
482 fComboRunType->AddEntry("ALL",id++);
483 fComboRunType->Select(0,kFALSE);
484 if (!fTree->GetBranch("runType.")) return;
485 TObjString *runType=0x0;
486 Int_t nevets=fTree->GetEntries();
487 fTree->SetBranchStatus("*",0);
488 fTree->SetBranchStatus("runType.*",1);
489 fTree->SetBranchAddress("runType.",&runType);
490 for (Int_t iev=0;iev<nevets;++iev){
491 fTree->GetEntry(iev);
492 TString type=runType->String();
493 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
495 fTree->ResetBranchAddresses();
496 fTree->SetBranchStatus("*",1);
498 //______________________________________________________________________________
499 void AliTPCCalibViewerGUItime::FillCalibTypes()
502 // loop over configuration and fill calibration types
505 fListCalibType->RemoveAll();
507 fConfigParser->ResetIter();
509 while ( (o=fConfigParser->NextKey()) ){
510 type=fConfigParser->GetData(o,kCalibType);
511 //remove whitespcaces
512 type.Remove(TString::kBoth,' ');
513 type.Remove(TString::kBoth,'\t');
514 if (type.IsNull()) type="UNSPECIFIED";
515 // printf("CalibType: '%s'\n",type.Data());
516 if (!fListCalibType->FindEntry(type.Data())) {
517 fListCalibType->AddEntry(type,id);
518 fListCalibType->Select(id++);
521 //add type for unspecified calibration type
523 if (!fListCalibType->FindEntry(type.Data())) {
524 fListCalibType->AddEntry(SubstituteUnderscores(type.Data()),id);
525 fListCalibType->Select(id++);
528 //______________________________________________________________________________
529 void AliTPCCalibViewerGUItime::CheckDrawGraph()
532 // Check whether to draw graphs in 2D mode based on the number of entries in the chain
533 // GetEstimate() returns the maximum size of the arrays stored in GetV1()...
537 if (fTree->GetEntries()<fTree->GetEstimate()) fNoGraph=kFALSE;
539 //______________________________________________________________________________
540 void AliTPCCalibViewerGUItime::Reload(Int_t first)
543 // reload the gui contents, this is needed after the input tree has changed
546 if ( !fTree ) return;
547 //in case of the first call create run type and calibration type entries
552 //activate all branches
553 fTree->SetBranchStatus("*",1);
554 //reset variables list
555 fListVariables->RemoveAll();
556 //get selected calibration types
558 fListCalibType->GetSelectedEntries(&calibTypes);
560 TObjArray *branchList = fTree->GetListOfBranches();
561 if ( !branchList ) return;
562 TIter nextBranch(branchList);
563 Int_t idCount=0,id=0;
564 TObject *objBranch=0;
565 while ( (objBranch=nextBranch()) ){
566 TString branchName(objBranch->GetName());
567 TString branchTitle(objBranch->GetName());
568 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
570 TString calibType="UNSPECIFIED";
572 const TObject *key=(*fConfigParser)(branchName.Data());
574 //test if branch is active
575 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
576 id=(*fConfigParser)()->IndexOf(key);
577 // branchTitle=fConfigParser->GetData(key,kBranchTitle);
578 calibType=fConfigParser->GetData(key,kCalibType);
586 if (calibType.IsNull()) calibType="UNSPECIFIED";
587 //check if branch is in selected calibration types
588 //if not, don't show it in the list and deactivate the branch.
589 Bool_t calibActive=kFALSE;
590 TIter nextCalib(&calibTypes);
592 while ( (objCalib=nextCalib()) )
593 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
596 TString s=branchName;
597 if (branchName.EndsWith(".")) s+="*";
598 fTree->SetBranchStatus(s.Data(),0);
601 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
604 //trick to display modifications
606 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
607 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
610 //______________________________________________________________________________
611 void AliTPCCalibViewerGUItime::AddReferenceTree(const char* treeFileName, const char* refName)
614 // map of reference trees that should always be attached to the CalibViewerGUI
616 fMapRefTrees->Add(new TObjString(refName), new TObjString(treeFileName));
619 //______________________________________________________________________________
620 const char* AliTPCCalibViewerGUItime::GetDrawString(){
622 // create draw string for ttree by combining the user requestsa
625 TString selectedVariable="";
627 if (!fListVariables->GetSelectedEntry()) return "";
628 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
629 id=fListVariables->GetSelectedEntry()->EntryId();
630 // printf("id: %d\n",id);
631 TString branchName=selectedVariable;
632 const TObject *key=(*fConfigParser)(id);
633 if (key) branchName=(*fConfigParser)(id)->GetName();
634 //treat case of TVector
635 if (branchName.EndsWith(".")){
636 Int_t par = (Int_t)(fNmbPar->GetNumber());
637 branchName.Append(Form("fElements[%d]",par));
639 // if (fRadioXrun->GetState()==kButtonDown)
640 // selectedVariable.Append(":run");
641 // if (fRadioXtime->GetState()==kButtonDown)
642 // selectedVariable.Append(":time");
644 return branchName.Data();
646 //______________________________________________________________________________
647 const char* AliTPCCalibViewerGUItime::GetDrawOption(){
649 // get user selected draw options
652 if (fComboAddDrawOpt->GetSelectedEntry()) drawOpt=fComboAddDrawOpt->GetSelectedEntry()->GetTitle();
653 if (fChkDrawOptSame->GetState()==kButtonDown && !drawOpt.Contains("same",TString::kIgnoreCase))
655 return drawOpt.Data();
657 //______________________________________________________________________________
658 void AliTPCCalibViewerGUItime::GetCutString(TString &cutStr){
662 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
664 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
665 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
666 cutStr=cuts.GetTitle();
668 //______________________________________________________________________________
669 void AliTPCCalibViewerGUItime::UpdateValueArrays(Bool_t withGraph)
675 fValuesX.ResizeTo(1);
676 fValuesY.ResizeTo(1);
677 fRunNumbers.ResizeTo(1);
678 fTimeStamps.ResizeTo(1);
680 fValuesX.ResizeTo(fTree->GetSelectedRows());
681 fValuesY.ResizeTo(fTree->GetSelectedRows());
682 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
683 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
684 fValuesY.SetElements(fTree->GetV3());
685 fRunNumbers.SetElements(fTree->GetV1());
686 fTimeStamps.SetElements(fTree->GetV2());
689 //______________________________________________________________________________
690 void AliTPCCalibViewerGUItime::GetHistogramTitle(TString &title)
693 // Create string for histogram title
697 Int_t pos=title.First(">>");
698 if (pos>0) title=title(0,pos);
700 if (fRadioXrun->GetState()==kButtonDown){
702 } else if (fRadioXtime->GetState()==kButtonDown){
708 TObjArray *arr=title.Tokenize(":");
713 TIter next(arr,kIterBackward);
714 while ( (o=next()) ){
715 TString varName=o->GetName();
717 //substitue variable names with names in configuration file if available
718 if ((*fConfigParser)()->GetEntries()){
719 TString branchName=varName;
721 if (branchName.Contains('.')) branchName=branchName(0,branchName.First('.')+1);
722 //chek if a configuration for that branch is available
723 const TObject *oBranch=(*fConfigParser)(branchName.Data());
725 TString branchTitle=fConfigParser->GetData(oBranch,kBranchTitle);
726 if (!branchTitle.IsNull()){
727 //check for TVectorT type branch
728 //add parameter name if available
729 if (varName.Contains("fElements")){
730 TString parStr=varName(varName.First('[')+1,varName.Length()-varName.First('[')-2);
733 TString yparname=fConfigParser->GetData(oBranch,par+kParamNames);
734 if (!yparname.IsNull()){
735 branchTitle+=yparname;
743 varName=SubstituteUnderscores(branchTitle.Data());
750 //______________________________________________________________________________
751 void AliTPCCalibViewerGUItime::AdjustYRange()
756 TIter nextGraphicObject(fTrashBox);
759 while ( (o=nextGraphicObject()) ){
760 if (o->IsA()==TGraph::Class()){
761 TGraph *gr=(TGraph*)o;
763 min=TMath::MinElement(gr->GetN(),gr->GetY());
764 max=TMath::MaxElement(gr->GetN(),gr->GetY());
766 Float_t currmin=TMath::MinElement(gr->GetN(),gr->GetY());
767 Float_t currmax=TMath::MaxElement(gr->GetN(),gr->GetY());
768 if (currmax>max) max=currmax;
769 if (currmin<min) min=currmin;
774 if (min!=0) min=min-(max-min)/10;
775 if (max!=0) max=max+(max-min)/10;
776 fCurrentHist->SetMinimum(min);
777 fCurrentHist->SetMaximum(max);
780 //______________________________________________________________________________
781 void AliTPCCalibViewerGUItime::DoDraw() {
785 TString drawString=fDrawString;
787 GetCutString(cutString);
788 TString optString = GetDrawOption();
789 Bool_t graphOutput=!fNoGraph; //ttree buffer for V1, V2... too small
790 graphOutput&=(drawString.First(">>")<0); //histogram output in custom draw
791 graphOutput&=fRadioXhist->GetState()!=kButtonDown; //histogram drawing selected
792 graphOutput&=!(fIsCustomDraw&&!fDrawString.Contains(":")); //custom draw 1D
793 Bool_t drawSame=optString.Contains("same",TString::kIgnoreCase);
794 // optString+="goff";
796 drawString.Prepend("run:time:");
800 if (fRadioXrun->GetState()==kButtonDown){
802 } else if (fRadioXtime->GetState()==kButtonDown){
807 TVirtualPad *padsave=gPad;
808 fCanvMain->GetCanvas()->cd();
809 //delete old histograms and graphs
815 // if (fCurrentGraph) {
816 // delete fCurrentGraph;
817 // fCurrentGraph=0x0;
818 // //fCurrentHist in case of graph is the interrnal histogram,
819 // // which is deleted by the graph itself.
822 // if (fCurrentHist) {
823 // delete fCurrentHist;
827 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
828 if (fTree->GetSelectedRows()==-1) return;
829 UpdateValueArrays(graphOutput);
831 GetHistogramTitle(title);
832 Bool_t drawGraph=kFALSE;
835 if (fDrawString.Contains(":")){
836 fValuesX.SetElements(fTree->GetV4());
843 if (fRadioXrun->GetState()==kButtonDown){
844 fValuesX.SetElements(fTree->GetV1());
845 } else if (fRadioXtime->GetState()==kButtonDown){
846 fValuesX.SetElements(fTree->GetV2());
851 }//create graph according to selection
853 TGraph *graph=new TGraph(fValuesX,fValuesY);
855 if (!drawSame) grDraw+="a";
856 if (!fIsCustomDraw) grDraw+="l";
857 graph->Draw(grDraw.Data());
858 graph->SetEditable(kFALSE);
859 TH1 *hist=graph->GetHistogram();
860 hist->SetTitle(title.Data());
861 fTrashBox->Add(graph);
862 graph->SetLineColor(fTrashBox->GetEntries());
863 graph->SetMarkerColor(fTrashBox->GetEntries());
869 TH1 *hist=fTree->GetHistogram();
870 hist->SetTitle(title.Data());
871 // hist->Draw(optString.Data());
872 fTrashBox->Add(hist);
873 hist->SetLineColor(fTrashBox->GetEntries());
874 hist->SetMarkerColor(fTrashBox->GetEntries());
875 if (!drawSame) fCurrentHist=hist;
878 //Set time axis if choosen as x-variables
879 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw&&!drawSame){
880 TAxis *xaxis=fCurrentHist->GetXaxis();
881 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
882 xaxis->SetTimeDisplay(1);
883 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
884 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
888 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
898 //______________________________________________________________________________
899 void AliTPCCalibViewerGUItime::DoDumpRuns()
902 // Dump the current run numbers to stdout
904 Int_t npoints=fRunNumbers.GetNrows();
905 Int_t *sortIndex = new Int_t[npoints];
906 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
907 Int_t run=0, prevRun=-1;
909 for (Int_t irun=0;irun<npoints;++irun){
910 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
911 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
916 //______________________________________________________________________________
917 void AliTPCCalibViewerGUItime::DoParLimitChange()
925 //______________________________________________________________________________
926 void AliTPCCalibViewerGUItime::DoNewSelection() {
928 // decides whether to redraw if user makes another selection
931 fDrawString=GetDrawString();
932 fIsCustomDraw=kFALSE;
935 //______________________________________________________________________________
936 void AliTPCCalibViewerGUItime::DoCustomDraw()
941 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
942 // if (fDrawString.Contains(">>")){
943 // Warning("DoCustomDraw","Currently no user defined histograms allowed!");
946 fNmbPar->SetState(kFALSE);
950 //______________________________________________________________________________
951 void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
956 if (fIsCustomDraw) DoCustomDraw();
958 fDrawString=GetDrawString();
959 fIsCustomDraw=kFALSE;
963 //______________________________________________________________________________
964 void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
967 // Draw selection button handling (x-variable)
971 TGButton *btn = (TGButton *) gTQSender;
972 id = btn->WidgetId();
975 Bool_t doDraw=kFALSE;
978 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
980 fRadioXrun->SetState(kButtonUp);
981 fRadioXtime->SetState(kButtonUp);
985 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
987 fRadioXhist->SetState(kButtonUp);
988 fRadioXtime->SetState(kButtonUp);
992 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
994 fRadioXrun->SetState(kButtonUp);
995 fRadioXhist->SetState(kButtonUp);
999 if (doDraw) DoCustomCutsDraw();
1001 //______________________________________________________________________________
1002 void AliTPCCalibViewerGUItime::UpdateParName()
1005 // change parameter name
1008 Int_t par = (Int_t)(fNmbPar->GetNumber());
1010 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
1011 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
1012 if (parName=="") parName.Form("%d",par);
1013 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
1014 fDrawString=GetDrawString();
1015 fIsCustomDraw=kFALSE;
1018 //______________________________________________________________________________
1019 void AliTPCCalibViewerGUItime::UpdateParLimits()
1022 // Adjust limits for TVectorT based variables
1025 TString selectedVariableTitle="";
1027 if (!fListVariables->GetSelectedEntry()) return;
1028 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
1029 id=fListVariables->GetSelectedEntry()->EntryId();
1030 // printf("id: %d\n",id);
1031 TString selectedVariable=selectedVariableTitle;
1032 const TObject *key=(*fConfigParser)(id);
1033 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
1035 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
1036 fNmbPar->SetState(kFALSE);
1037 fLblPar->SetText("Parameter: none");
1044 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
1045 TString branchClass=branch->GetClassName();
1047 if (branchClass=="TVectorT<double>"){
1048 // branch->SetAddress(&vD);
1049 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
1050 while (maxPar<2&&event<fTree->GetEntries()){
1051 fTree->GetEntry(event++);
1052 maxPar=vD->GetNrows();
1054 } else if (branchClass=="TVectorT<float>"){
1055 // branch->SetAddress(&vF);
1056 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
1057 while (maxPar<2&&event<fTree->GetEntries()){
1058 fTree->GetEntry(event++);
1059 maxPar=vF->GetNrows();
1063 fNmbPar->SetState(kFALSE);
1066 // branch->ResetAddress();
1067 fTree->SetBranchAddress(selectedVariable.Data(),0x0);
1068 if (fNmbPar->GetNumMax()!=maxPar-1) fNmbPar->SetNumber(0);
1069 fNmbPar->SetLimitValues(0,maxPar-1);
1070 fNmbPar->SetState(kTRUE);
1073 //______________________________________________________________________________
1074 void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
1077 // handle mouse events in the draw canvas
1079 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
1080 Double_t valx=0.,valy=0.;
1081 if (!fCurrentGraph) {
1082 fLblRunNumberVal->SetText(Form("%05u",run));
1083 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
1084 fLblValueXVal->SetText(Form("%.3e", valx));
1085 fLblValueYVal->SetText(Form("%.3e", valy));
1088 TVirtualPad *padsave=gPad;
1089 fCanvMain->GetCanvas()->cd();
1090 Int_t n=fValuesY.GetNrows();
1092 arr=fValuesX.GetMatrixArray();
1094 Int_t minDist=1000000;
1096 for (Int_t i=0;i<n;++i){
1097 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
1098 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
1099 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
1106 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
1107 t.GetDate(kTRUE,0,&yy,&mm,&dd);
1108 t.GetTime(kTRUE,0,&HH,&MM,&SS);
1109 run=(UInt_t)fRunNumbers[minPoint];
1110 valx=fValuesX[minPoint];
1111 valy=fValuesY[minPoint];
1113 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
1117 fLblRunNumberVal->SetText(Form("%05u",run));
1118 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
1120 fLblValueXVal->SetText(Form("%.3e", valx));
1122 if (fRadioXrun->GetState()==kButtonDown){
1123 fLblValueXVal->SetText("Run");
1124 } else if (fRadioXtime->GetState()==kButtonDown){
1125 fLblValueXVal->SetText("Time");
1128 fLblValueYVal->SetText(Form("%.3e", valy));
1131 if (event == kButton1Double ){
1134 //find closes point of current selection
1136 //______________________________________________________________________________
1137 void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
1140 // create the AliTPCCalibViewerGUI tree for run
1141 // cache tree in directory fOutputCacheDir
1142 // retrieve file from this directory if it already exists
1145 //try to find file for run in fOutputCacheDir
1146 TString fileName=fOutputCacheDir;
1147 if (!fileName.EndsWith("/")) fileName+="/";
1148 fileName+=Form("guiTreeRun_%d.root",run);
1150 TFile f(fileName.Data());
1152 load=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
1154 fCalibViewerGUI->Reset();
1155 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
1160 fCalibViewerGUI->Initialize(fileName.Data());
1161 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
1162 TIter nextRefTree(fMapRefTrees);
1164 while ( (o=nextRefTree()) ){
1165 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"calPads",o->GetName());
1167 fCalibViewerGUI->Reload();
1169 //______________________________________________________________________________
1170 const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
1176 s.ReplaceAll("_{","|{");
1177 s.ReplaceAll("_"," ");
1178 s.ReplaceAll("|{","_{");
1181 //______________________________________________________________________________
1182 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName, const char* treeName) {
1184 // Initialize and show GUI for presentation for demonstration purposes
1185 // or for fast standalone use
1187 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1188 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1189 frmMain->SetCleanup(kDeepCleanup);
1191 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1192 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1194 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1195 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
1197 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1198 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1199 calibViewerTime->SetConfigFileName("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt");
1200 calibViewerTime->UseFile(fileName, treeName);
1202 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
1203 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1204 calibViewerTime->SetCalibViewerGUI(calibViewer);
1205 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
1208 TObjArray *guiArray = new TObjArray();
1209 guiArray->Add(calibViewerTime);
1210 guiArray->Add(calibViewer);
1212 frmMain->MapSubwindows();
1214 frmMain->MapWindow();
1219 //______________________________________________________________________________
1220 TObjArray* AliTPCCalibViewerGUItime::ShowGUI(TChain *chain) {
1222 // Initialize and show GUI for presentation for demonstration purposes
1223 // or for fast standalone use
1225 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1226 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1227 frmMain->SetCleanup(kDeepCleanup);
1229 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1230 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1232 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1234 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1235 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1236 calibViewerTime->UseChain(chain);
1238 TObjArray *guiArray = new TObjArray();
1239 guiArray->Add(calibViewerTime);
1241 frmMain->MapSubwindows();
1243 frmMain->MapWindow();