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 ///////////////////////////////////////////////////////////////////////////////
19 // GUI for displaying calibration entries over time //
21 // Authors: Marian Ivanov (Marian.Ivanov@cern.ch) //
22 // Jens Wiechula (Jens.Wiechula@cern.ch) //
23 // Ionut Arsene (iarsene@cern.ch) //
25 // Usage: AliCalibViewerGUItime::ShowGUI(TChain* chain) //
26 // AliCalibViewerGUItime::ShowGUI() //
27 ///////////////////////////////////////////////////////////////////////////////
33 #include <TDirectory.h>
37 #include <TVirtualPad.h>
39 #include <TObjArray.h>
40 #include <TObjString.h>
49 #include <TIterator.h>
52 #include <TTimeStamp.h>
56 #include <TGFileDialog.h>
57 #include <TGInputDialog.h>
60 #include <TGListBox.h>
61 #include <TGComboBox.h>
62 #include <TGNumberEntry.h>
64 #include <TRootEmbeddedCanvas.h>
65 #include <TGSplitter.h>
66 #include <TGButtonGroup.h>
73 #include "AliBaseCalibViewer.h"
74 #include "AliBaseCalibViewerGUI.h"
75 #include "AliCalibViewerGUItime.h"
78 ClassImp(AliCalibViewerGUItime)
80 //_______________________________________________________________________________________________________________
81 AliCalibViewerGUItime::AliCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h, const Char_t* det) :
82 TGCompositeFrame(p,w,h),
87 fCalibViewerGUItab(0x0),
90 fCurrentRunDetails(-1),
91 fOutputCacheDir("/tmp"),
93 fIsCustomDraw(kFALSE),
99 fGraphLimitEntries(10000),
100 fMapRefTrees(new TMap),
102 //main canvas Top part, bottom part
104 //top left, centre, right
109 fChkDrawOptSame(0x0),
110 fComboAddDrawOpt(0x0),
112 fContDrawSelSubRunTime(0x0),
133 fLblRunNumberVal(0x0),
142 fContConfigFile(0x0),
149 // extract information from OCDB
152 fContCustomCuts(0x0),
155 fComboCustomDraw(0x0),
156 fComboCustomCuts(0x0),
157 fTrashBox(new TObjArray)
163 fMapRefTrees->SetOwnerKeyValue();
164 fTrashBox->SetOwner();
166 gStyle->SetMarkerStyle(20);
167 gStyle->SetMarkerSize(0.5);
171 //______________________________________________________________________________
172 AliCalibViewerGUItime::~AliCalibViewerGUItime(){
176 // delete fConfigParser;
181 //______________________________________________________________________________
182 void AliCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
186 // ======================================================================
187 // ************************* Display everything *************************
188 // ======================================================================
190 SetCleanup(kDeepCleanup);
192 // *****************************************************************************
193 // ************************* content of this MainFrame *************************
194 // *****************************************************************************
195 // top level container with horizontal layout
196 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
197 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
199 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
200 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
202 // ***********************************************************************
203 // ************************* content of fContLCR *************************
204 // ***********************************************************************
206 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
207 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
209 // left vertical splitter
210 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
211 splitLeft->SetFrame(fContLeft, kTRUE);
212 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
215 fContRight = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
216 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
219 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
220 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
222 // right vertical splitter
223 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
224 splitRight->SetFrame(fContRight, kFALSE);
225 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
228 // ========================================================================
229 // ************************* content of fContLeft *************************
230 // ========================================================================
231 // --- draw button and tabLeft ---
233 fContDrawOpt = new TGGroupFrame(fContLeft, "Draw options", kVerticalFrame | kFitWidth | kFitHeight);
234 fContLeft->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
235 fChkDrawOptSame = new TGCheckButton(fContDrawOpt, "Same");
236 fContDrawOpt->AddFrame(fChkDrawOptSame, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
237 fChkDrawOptSame->SetToolTipText("Add draw option 'same'");
238 // additional draw options combo box
239 fComboAddDrawOpt = new TGComboBox(fContDrawOpt);
240 fComboAddDrawOpt->Resize(0, 22);
241 fComboAddDrawOpt->EnableTextInput(kTRUE);
242 fContDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
244 // draw selection group
245 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
246 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
247 //x-axis variables selection, Run of Time
248 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
249 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
251 // ------------------------- content of fContDrawOpt -------------------------
255 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
256 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
257 fRadioXhist->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleButtonsDrawSel()");
258 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
260 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
261 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
262 fRadioXrun->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleButtonsDrawSel()");
263 fRadioXrun->SetToolTipText("Use run number as x-value");
266 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
267 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
268 fRadioXtime->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleButtonsDrawSel()");
269 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
273 fListVariables = new TGListBox(fContDrawSel);
274 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
275 fListVariables->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoNewSelection()");
278 //-------------------- run type selection ------------------------
280 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
281 fLblRunType->SetTextJustify(kTextLeft);
282 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
284 fComboRunType = new TGComboBox(fContDrawSel);
285 fComboRunType->EnableTextInput(kFALSE);
286 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
287 fComboRunType->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoDraw()");
288 fComboRunType->Resize(0, 22);
290 //-------------------- parameter selection ------------------------
292 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
293 fLblPar->SetTextJustify(kTextLeft);
294 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
296 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
297 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
298 fNmbPar->Connect("ValueSet(Long_t)", "AliCalibViewerGUItime", this, "DoParLimitChange()");
299 fNmbPar->SetState(kFALSE);
301 //-------------------- calibration type selection ------------------------
303 // draw selection group
304 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
305 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
308 fListCalibType = new TGListBox(fContCalibType);
309 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
310 fListCalibType->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoChangeSelectionList()");
311 fListCalibType->Resize(0,88);
312 fListCalibType->SetMultipleSelections();
315 // ==========================================================================
316 // ************************* content of fContCenter *************************
317 // ========================================================================
318 // main drawing canvas
319 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
320 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
321 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
322 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
323 fCanvMain->GetCanvas()->SetRightMargin(0.062);
324 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
326 // =========================================================================
327 // ************************* content of fContRight *************************
328 // ========================================================================
329 //group frame for value information
330 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
331 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
333 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 4));
334 //value information labels
337 fLblRunNumber = new TGLabel(fContValues, "Run:");
338 fLblRunNumber->SetTextJustify(kTextLeft);
339 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
341 fLblRunNumberVal = new TGLabel(fContValues, "0000000");
342 fLblRunNumberVal->SetTextJustify(kTextLeft);
343 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
345 fLblRunTime = new TGLabel(fContValues, "Time:");
346 fLblRunTime->SetTextJustify(kTextLeft);
347 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
349 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
350 fLblRunTimeVal->SetTextJustify(kTextLeft);
351 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
353 fLblValueX = new TGLabel(fContValues, "x-Value:");
354 fLblValueX->SetTextJustify(kTextLeft);
355 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
357 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
358 fLblValueXVal->SetTextJustify(kTextRight);
359 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
361 fLblValueY = new TGLabel(fContValues, "y-Value:");
362 fLblValueY->SetTextJustify(kTextLeft);
363 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
365 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
366 fLblValueYVal->SetTextJustify(kTextRight);
367 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
369 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
370 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
371 fBtnDumpRuns->Connect("Clicked()", "AliCalibViewerGUItime", this, "DoDumpRuns()");
372 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
374 fBtnSave = new TGTextButton(fContRight, "&Save picture");
375 fContRight->AddFrame(fBtnSave, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
376 fBtnSave->SetToolTipText("Press to save the current picture in the canvas");
377 fBtnSave->Connect("Clicked()", "AliCalibViewerGUItime", this, "SavePicture()");
379 //group frame for loading a file
380 fContLoad = new TGGroupFrame(fContRight, "Load file", kVerticalFrame | kFitWidth | kFitHeight);
381 fContRight->AddFrame(fContLoad, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
383 fContFilename = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
384 fContLoad->AddFrame(fContFilename, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
386 fTxtFilename = new TGTextEntry(fContFilename, "Input file", 100);
387 fContFilename->AddFrame(fTxtFilename, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
388 fTxtFilename->Connect("DoubleClicked()", "AliCalibViewerGUItime", this, "HandleLoadRunTextEntry()");
390 fContTreeName = new TGCompositeFrame(fContLoad, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
391 fContLoad->AddFrame(fContTreeName, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
393 fLblTreeName = new TGLabel(fContTreeName, "Tree Name:");
394 fLblTreeName->SetTextJustify(kTextLeft);
395 fContTreeName->AddFrame(fLblTreeName, new TGLayoutHints(kLHintsNormal | kLHintsCenterY, 0, 1, 0, 0));
397 fTxtTreeName = new TGTextEntry(fContTreeName, "trdTree");
398 if(fDetector.Contains("TPC")) fTxtTreeName->SetText("dcs");
399 fContTreeName->AddFrame(fTxtTreeName, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
401 fBtnLoadFile = new TGTextButton(fContLoad, "Load file", 100);
402 fContLoad->AddFrame(fBtnLoadFile, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
403 fBtnLoadFile->SetToolTipText("Load a file into viewer");
404 fBtnLoadFile->Connect("Clicked()", "AliCalibViewerGUItime", this, "HandleLoadRunButtons()");
406 // =========================================================================
407 // ****************** bottom content of fContTopBottom *********************
408 // =========================================================================
410 // custom options container
411 // --- fComboCustom --- the custom draw line on the very low
412 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
413 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
415 // ------------------------- content of fContCustom -------------------------
416 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
417 fLblCustomDraw->SetTextJustify(kTextLeft);
418 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
419 // text field for custom draw command
420 fComboCustomDraw = new TGComboBox(fContCustom);
421 fComboCustomDraw->Resize(0, 22);
422 fComboCustomDraw->EnableTextInput(kTRUE);
423 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
424 fComboCustomDraw->Connect("ReturnPressed()", "AliCalibViewerGUItime", this, "DoCustomDraw()");
425 fComboCustomDraw->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoCustomDraw()");
428 // additional cuts container
429 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
430 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
432 // ------------------------- content of fContCustomCuts -------------------------
433 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
434 fLblCustomCuts->SetTextJustify(kTextLeft);
435 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
436 // combo text field for additional cuts
437 fComboCustomCuts = new TGComboBox(fContCustomCuts);
438 // fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
439 fComboCustomCuts->Resize(0, 22);
440 fComboCustomCuts->EnableTextInput(kTRUE);
441 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
442 fComboCustomCuts->Connect("ReturnPressed()", "AliCalibViewerGUItime", this, "DoCustomCutsDraw()");
443 fComboCustomCuts->Connect("Selected(Int_t)", "AliCalibViewerGUItime", this, "DoCustomCutsDraw()");
445 if(fDetector.Contains("TPC")) SetWindowName("AliTPCCalibViewer GUI - Time");
446 else if (fDetector.Contains("TRD")) SetWindowName("AliTRDCalibViewer GUI - Time");
447 else SetWindowName("Unknown detector");
449 Resize(GetDefaultSize());
453 //______________________________________________________________________________
454 void AliCalibViewerGUItime::SetInitialValues(){
456 // Set inital selections of the gui
458 fRadioXrun->SetState(kButtonDown);
459 fRadioXtime->SetState(kButtonUp);
462 //______________________________________________________________________________
463 void AliCalibViewerGUItime::UseFile(const char* fileName, const char* treeName) {
465 // retrieve tree from file
468 TObjArray *arr=s.Tokenize(" ");
471 if (fTree) delete fTree;
472 fTree=new TChain(treeName);
473 while ( (o=next()) ){
474 TString tmpString(o->GetName());
475 std::cout << "Adding " << tmpString.Data() << " to the chain" << std::endl;
476 if(tmpString.Contains(".root"))
477 fTree->AddFile(tmpString.Data());
479 tmpString += "/*.root";
480 fTree->Add(tmpString.Data());
486 // UseConfigFile(fConfigFile.Data());
491 //______________________________________________________________________________
492 void AliCalibViewerGUItime::UseChain(TChain* chain)
499 std::cout << "AliCalibViewerGUItime::UseChain !checkchain OUT" << std::endl;
502 //set configuration file
503 // UseConfigFile(fConfigFile.Data());
508 //______________________________________________________________________________
509 Bool_t AliCalibViewerGUItime::CheckChain()
512 // check whether cahin has entries
513 // decide whether to draw graphs in 2D
519 Long64_t entries=fTree->GetEntries();
521 AliError("No entries found in chain");
524 //check whether to draw graphs
529 //______________________________________________________________________________
530 void AliCalibViewerGUItime::FillRunTypes()
533 //Loop over the tree entries and fill the run types
539 fComboRunType->RemoveAll();
540 fComboRunType->AddEntry("ALL",id++);
541 fComboRunType->Select(0,kFALSE);
542 if (!fTree->GetBranch("runType.")) {
545 TObjString *runType=0x0;
546 Int_t nevets=fTree->GetEntries();
547 fTree->SetBranchStatus("*",0);
548 fTree->SetBranchStatus("runType.*",1);
549 fTree->SetBranchAddress("runType.",&runType);
550 for (Int_t iev=0;iev<nevets;++iev){
551 fTree->GetEntry(iev);
552 TString type=runType->String();
553 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
555 fTree->ResetBranchAddresses();
556 fTree->SetBranchStatus("*",1);
559 //______________________________________________________________________________
560 void AliCalibViewerGUItime::FillCalibTypes()
563 // loop over configuration and fill calibration types
566 fListCalibType->RemoveAll();
568 // fConfigParser->ResetIter();
569 TString type="UNSPECIFIED";
570 fListCalibType->AddEntry(type.Data(),id);
571 fListCalibType->Select(id++);
574 //______________________________________________________________________________
575 void AliCalibViewerGUItime::CheckDrawGraph()
578 // Check whether to draw graphs in 2D mode based on the number of entries in the chain
579 // GetEstimate() returns the maximum size of the arrays stored in GetV1()...
585 if (fTree->GetEntries()<fTree->GetEstimate()) fNoGraph=kFALSE;
588 //______________________________________________________________________________
589 void AliCalibViewerGUItime::Reload(Int_t /*first*/)
592 // reload the gui contents, this is needed after the input tree has changed
600 //activate all branches
601 fTree->SetBranchStatus("*",1);
602 //reset variables list
603 fListVariables->RemoveAll();
604 //get selected calibration types
606 fListCalibType->GetSelectedEntries(&calibTypes);
608 TObjArray *branchList = fTree->GetListOfBranches();
609 if ( !branchList ) return;
610 TIter nextBranch(branchList);
611 Int_t idCount=0,id=0;
612 TObject *objBranch=0;
613 while ( (objBranch=nextBranch()) ){
614 TString branchName(objBranch->GetName());
615 TString branchTitle(objBranch->GetName());
616 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
618 TString calibType="UNSPECIFIED";
620 //check if branch is in selected calibration types
621 //if not, don't show it in the list and deactivate the branch.
622 Bool_t calibActive=kFALSE;
623 TIter nextCalib(&calibTypes);
625 while ( (objCalib=nextCalib()) ) {
626 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
630 TString s=branchName;
631 if (branchName.EndsWith(".")) s+="*";
632 fTree->SetBranchStatus(s.Data(),0);
635 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
636 //fListVariables->Select(id);
639 //trick to display modifications
640 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
641 fListCalibType->Resize(fListCalibType->GetWidth()+1, fListCalibType->GetHeight());
644 //______________________________________________________________________________
645 void AliCalibViewerGUItime::AddReferenceTree(const char* treeFileName, const char* refName)
648 // map of reference trees that should always be attached to the CalibViewerGUI
650 fMapRefTrees->Add(new TObjString(refName), new TObjString(treeFileName));
653 //______________________________________________________________________________
654 const char* AliCalibViewerGUItime::GetDrawString(){
656 // create draw string for ttree by combining the user requestsa
659 TString selectedVariable="";
661 if (!fListVariables->GetSelectedEntry()) {
664 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
665 id=fListVariables->GetSelectedEntry()->EntryId();
666 TString branchName=selectedVariable;
667 // const TObject *key=(*fConfigParser)(id);
668 // if (key) branchName=(*fConfigParser)(id)->GetName();
669 //treat case of TVector
670 if (branchName.EndsWith(".")){
671 Int_t par = (Int_t)(fNmbPar->GetNumber());
672 branchName.Append(Form("fElements[%d]",par));
675 return branchName.Data();
677 //______________________________________________________________________________
678 const char* AliCalibViewerGUItime::GetDrawOption() const {
680 // get user selected draw options
683 if (fComboAddDrawOpt->GetSelectedEntry()) drawOpt=fComboAddDrawOpt->GetSelectedEntry()->GetTitle();
684 if (fChkDrawOptSame->GetState()==kButtonDown && !drawOpt.Contains("same",TString::kIgnoreCase))
686 return drawOpt.Data();
688 //______________________________________________________________________________
689 void AliCalibViewerGUItime::GetCutString(TString &cutStr){
693 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
695 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
696 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
697 cutStr=cuts.GetTitle();
699 //______________________________________________________________________________
700 void AliCalibViewerGUItime::UpdateValueArrays(Bool_t withGraph)
703 // Update arrays of runs
706 fValuesX.ResizeTo(1);
707 fValuesY.ResizeTo(1);
708 fRunNumbers.ResizeTo(1);
709 fTimeStamps.ResizeTo(1);
711 fValuesX.ResizeTo(fTree->GetSelectedRows());
712 fValuesY.ResizeTo(fTree->GetSelectedRows());
713 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
714 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
715 fValuesY.SetElements(fTree->GetV3());
716 fRunNumbers.SetElements(fTree->GetV1());
717 fTimeStamps.SetElements(fTree->GetV2());
721 //______________________________________________________________________________
722 void AliCalibViewerGUItime::GetHistogramTitle(TString &title)
725 // Create string for histogram title
729 Int_t pos=title.First(">>");
730 if (pos>0) title=title(0,pos);
732 if (fRadioXrun->GetState()==kButtonDown){
734 } else if (fRadioXtime->GetState()==kButtonDown){
740 TObjArray *arr=title.Tokenize(":");
745 TIter next(arr,kIterBackward);
746 while ( (o=next()) ){
747 TString varName=o->GetName();
754 //______________________________________________________________________________
755 void AliCalibViewerGUItime::AdjustYRange()
758 // adjust the range of the Y axis
760 TIter nextGraphicObject(fTrashBox);
763 while ( (o=nextGraphicObject()) ){
764 if (o->IsA()==TGraph::Class()){
765 TGraph *gr=(TGraph*)o;
767 min=TMath::MinElement(gr->GetN(),gr->GetY());
768 max=TMath::MaxElement(gr->GetN(),gr->GetY());
770 Float_t currmin=TMath::MinElement(gr->GetN(),gr->GetY());
771 Float_t currmax=TMath::MaxElement(gr->GetN(),gr->GetY());
772 if (currmax>max) max=currmax;
773 if (currmin<min) min=currmin;
778 if (min!=0) min=min-(max-min)/10;
779 if (max!=0) max=max+(max-min)/10;
780 fCurrentHist->SetMinimum(min);
781 fCurrentHist->SetMaximum(max);
784 //______________________________________________________________________________
785 void AliCalibViewerGUItime::DoDraw() {
789 TString drawString=fDrawString;
791 GetCutString(cutString);
792 TString optString = GetDrawOption();
793 Bool_t graphOutput=!fNoGraph; //ttree buffer for V1, V2... too small
794 graphOutput&=(drawString.First(">>")<0); //histogram output in custom draw
795 graphOutput&=fRadioXhist->GetState()!=kButtonDown; //histogram drawing selected
796 graphOutput&=!(fIsCustomDraw&&!fDrawString.Contains(":")); //custom draw 1D
797 Bool_t drawSame=optString.Contains("same",TString::kIgnoreCase);
798 // optString+="goff";
800 drawString.Prepend("run:time:");
804 if (fRadioXrun->GetState()==kButtonDown){
806 } else if (fRadioXtime->GetState()==kButtonDown){
811 TVirtualPad *padsave=gPad;
812 fCanvMain->GetCanvas()->cd();
813 //delete old histograms and graphs
821 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
822 if (fTree->GetSelectedRows()==-1) {
825 UpdateValueArrays(graphOutput);
827 GetHistogramTitle(title);
828 Bool_t drawGraph=kFALSE;
831 if (fDrawString.Contains(":")){
832 fValuesX.SetElements(fTree->GetV4());
839 if (fRadioXrun->GetState()==kButtonDown){
840 fValuesX.SetElements(fTree->GetV1());
841 } else if (fRadioXtime->GetState()==kButtonDown){
842 fValuesX.SetElements(fTree->GetV2());
847 }//create graph according to selection
849 TGraph *graph=new TGraph(fValuesX,fValuesY);
851 if (!drawSame) grDraw+="a";
852 if (!fIsCustomDraw) grDraw+="l";
853 graph->Draw(grDraw.Data());
854 graph->SetEditable(kFALSE);
855 TH1 *hist=graph->GetHistogram();
856 hist->SetTitle(title.Data());
857 fTrashBox->Add(graph);
858 graph->SetLineColor(fTrashBox->GetEntries());
859 graph->SetMarkerColor(fTrashBox->GetEntries());
865 TH1 *hist=fTree->GetHistogram();
866 hist->SetTitle(title.Data());
867 fTrashBox->Add(hist);
868 hist->SetLineColor(fTrashBox->GetEntries());
869 hist->SetMarkerColor(fTrashBox->GetEntries());
870 if (!drawSame) fCurrentHist=hist;
873 //Set time axis if choosen as x-variables
874 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw&&!drawSame){
875 TAxis *xaxis=fCurrentHist->GetXaxis();
876 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
877 xaxis->SetTimeDisplay(1);
878 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
879 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
883 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
893 //______________________________________________________________________________
894 void AliCalibViewerGUItime::DoDumpRuns()
897 // Dump the current run numbers to stdout
899 Int_t npoints=fRunNumbers.GetNrows();
900 Int_t *sortIndex = new Int_t[npoints];
901 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
902 Int_t run=0, prevRun=-1;
904 for (Int_t irun=0;irun<npoints;++irun){
905 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
906 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
912 //______________________________________________________________________________
913 void AliCalibViewerGUItime::DoParLimitChange()
916 // DoParLimitChange()
922 //______________________________________________________________________________
923 void AliCalibViewerGUItime::DoNewSelection() {
925 // decides whether to redraw if user makes another selection
928 fDrawString=GetDrawString();
929 fIsCustomDraw=kFALSE;
933 //______________________________________________________________________________
934 void AliCalibViewerGUItime::DoCustomDraw()
937 // Custom draw (TTree::Draw syntax)
939 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
940 fNmbPar->SetState(kFALSE);
945 //______________________________________________________________________________
946 void AliCalibViewerGUItime::DoCustomCutsDraw()
949 // Custom cuts (TTree::Draw syntax)
951 if (fIsCustomDraw) DoCustomDraw();
953 fDrawString=GetDrawString();
954 fIsCustomDraw=kFALSE;
959 //______________________________________________________________________________
960 void AliCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
963 // Draw selection button handling (x-variable)
967 TGButton *btn = (TGButton *) gTQSender;
968 id = btn->WidgetId();
971 Bool_t doDraw=kFALSE;
974 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
976 fRadioXrun->SetState(kButtonUp);
977 fRadioXtime->SetState(kButtonUp);
981 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
983 fRadioXhist->SetState(kButtonUp);
984 fRadioXtime->SetState(kButtonUp);
988 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
990 fRadioXrun->SetState(kButtonUp);
991 fRadioXhist->SetState(kButtonUp);
995 if (doDraw) DoCustomCutsDraw();
997 //______________________________________________________________________________
998 void AliCalibViewerGUItime::UpdateParName()
1001 // change parameter name
1004 Int_t par = (Int_t)(fNmbPar->GetNumber());
1006 parName.Form("%d",par);
1007 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
1008 fDrawString=GetDrawString();
1009 fIsCustomDraw=kFALSE;
1012 //______________________________________________________________________________
1013 void AliCalibViewerGUItime::UpdateParLimits()
1016 // Adjust limits for TVectorT based variables
1019 TString selectedVariableTitle="";
1021 if (!fListVariables->GetSelectedEntry()) return;
1022 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
1023 id=fListVariables->GetSelectedEntry()->EntryId();
1024 TString selectedVariable=selectedVariableTitle;
1025 // const TObject *key=(*fConfigParser)(id);
1026 // if (key) selectedVariable=(*fConfigParser)(id)->GetName();
1028 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
1029 fNmbPar->SetState(kFALSE);
1030 fLblPar->SetText("Parameter: none");
1037 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
1038 TString branchClass=branch->GetClassName();
1040 if (branchClass=="TVectorT<double>"){
1041 // branch->SetAddress(&vD);
1042 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
1043 while (maxPar<2&&event<fTree->GetEntries()){
1044 fTree->GetEntry(event++);
1045 maxPar=vD->GetNrows();
1047 } else if (branchClass=="TVectorT<float>"){
1048 // branch->SetAddress(&vF);
1049 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
1050 while (maxPar<2&&event<fTree->GetEntries()){
1051 fTree->GetEntry(event++);
1052 maxPar=vF->GetNrows();
1056 fNmbPar->SetState(kFALSE);
1059 fTree->SetBranchAddress(selectedVariable.Data(),0x0);
1060 if (fNmbPar->GetNumMax()!=maxPar-1) fNmbPar->SetNumber(0);
1061 fNmbPar->SetLimitValues(0,maxPar-1);
1062 fNmbPar->SetState(kTRUE);
1065 //______________________________________________________________________________
1066 void AliCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
1069 // handle mouse events in the draw canvas
1071 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
1072 Double_t valx=0.,valy=0.;
1073 if (!fCurrentGraph) {
1074 fLblRunNumberVal->SetText(Form("%07u",run));
1075 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
1076 fLblValueXVal->SetText(Form("%.3e", valx));
1077 fLblValueYVal->SetText(Form("%.3e", valy));
1080 TVirtualPad *padsave=gPad;
1081 fCanvMain->GetCanvas()->cd();
1082 Int_t n=fValuesY.GetNrows();
1084 arr=fValuesX.GetMatrixArray();
1086 Int_t minDist=1000000;
1088 for (Int_t i=0;i<n;++i){
1089 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
1090 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
1091 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
1098 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
1099 t.GetDate(kTRUE,0,&yy,&mm,&dd);
1100 t.GetTime(kTRUE,0,&HH,&MM,&SS);
1101 run=(UInt_t)fRunNumbers[minPoint];
1102 valx=fValuesX[minPoint];
1103 valy=fValuesY[minPoint];
1105 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
1109 fLblRunNumberVal->SetText(Form("%07u",run));
1110 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
1112 fLblValueXVal->SetText(Form("%.3e", valx));
1114 if (fRadioXrun->GetState()==kButtonDown){
1115 fLblValueXVal->SetText("Run");
1116 } else if (fRadioXtime->GetState()==kButtonDown){
1117 fLblValueXVal->SetText("Time");
1120 fLblValueYVal->SetText(Form("%.3e", valy));
1125 if (event == kButton1Double ){
1128 //find closes point of current selection
1131 //______________________________________________________________________________
1132 void AliCalibViewerGUItime::SetGuiTree(Int_t run)
1135 // create the AliCalibViewerGUI tree for run
1136 // cache tree in directory fOutputCacheDir
1137 // retrieve file from this directory if it already exists
1140 //try to find file for run in fOutputCacheDir
1141 TString fileName=fOutputCacheDir;
1142 if (!fileName.EndsWith("/")) fileName+="/";
1143 if(fDetector.Contains("TPC")) fileName+=Form("guiTreeRun_%d.root",run);
1144 else if(fDetector.Contains("TRD")) fileName+=Form("trdOCDBDetails_run%d.root", run);
1147 TFile f(fileName.Data());
1149 if(fDetector.Contains("TRD"))
1150 load = fCalibViewerGUI->CreateDetailsTree(run, fileName.Data(), "nothing");
1151 if(fDetector.Contains("TPC"))
1152 load = fCalibViewerGUI->CreateDetailsTree(run, fileName.Data(), "nothing");
1155 fCalibViewerGUI->Reset();
1156 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
1161 if(fDetector.Contains("TPC")) fCalibViewerGUI->Initialize(fileName.Data(), "calPads");
1162 else fCalibViewerGUI->Initialize(fileName.Data(), "TRDcalibDetails");
1163 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %07d",run)));
1164 TIter nextRefTree(fMapRefTrees);
1166 while ( (o=nextRefTree()) ){
1167 if(fDetector.Contains("TPC"))
1168 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"calPads",o->GetName());
1170 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"TRDcalibDetails",o->GetName());
1172 //if(fDetector.Contains("TPC")) ((AliTPCCalibViewerGUI_new*)fCalibViewerGUI)->Reload();
1173 //else ((AliTRDCalibViewerGUI*)fCalibViewerGUI)->Reload();
1174 fCalibViewerGUI->Reload();
1177 //______________________________________________________________________________
1178 const char* AliCalibViewerGUItime::SubstituteUnderscores(const char* in)
1181 // Substitute underscores from the branch names
1184 s.ReplaceAll("_{","|{");
1185 s.ReplaceAll("_"," ");
1186 s.ReplaceAll("|{","_{");
1190 //______________________________________________________________________________
1191 void AliCalibViewerGUItime::SavePicture() {
1193 // saves the current picture
1196 const char *kSaveAsTypes[] = {
1197 "Postscript", "*.ps",
1198 "Encapsulated Postscript", "*.eps",
1207 "C++ macro", "*.cxx",
1208 "Macro file", "*.C",
1209 "ROOT file", "*.root",
1215 fi.fFileTypes = kSaveAsTypes;
1216 // fi.fIniDir = StrDup(dir);
1217 fi.fOverwrite = kFALSE;
1218 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
1219 if (fi.fFilename && strlen(fi.fFilename)) {
1220 fCanvMain->GetCanvas()->Print(fi.fFilename);
1224 //______________________________________________________________________________
1225 void AliCalibViewerGUItime::HandleLoadRunButtons() {
1227 // Handle the buttons
1229 Int_t id = ((TGTextButton*)gTQSender)->WidgetId();
1231 UseFile(fTxtFilename->GetText(), fTxtTreeName->GetText());
1238 //______________________________________________________________________________
1239 void AliCalibViewerGUItime::HandleLoadRunTextEntry() {
1241 // Handle the text entries
1244 // 100 - fTxtFilename
1245 // 101 - fTxtConfigFile
1247 Int_t id = ((TGTextEntry*)gTQSender)->WidgetId();
1248 if(id>=100 && id<=103) {
1249 const char *kTypes[] = {
1255 fi.fFileTypes = kTypes;
1256 fi.fOverwrite = kFALSE;
1257 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
1258 if(fi.fFilename && strlen(fi.fFilename)) {
1260 fTxtFilename->SetText(fi.fFilename);
1263 // fTxtConfigFile->SetText(fi.fFilename);
1264 // fConfigFile=fi.fFilename;
1267 //fTxtRunList->SetText(fi.fFilename);
1270 //fTxtOutputOCDB->SetText(fi.fFilename);
1280 //__________________________________________________________________
1281 TObjArray* AliCalibViewerGUItime::ShowGUI(TChain* chain) {
1283 // Launch the time trending GUI. Load the TChain chain into the viewer
1285 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 650);
1286 frmMain->SetWindowName("Calib Viewer - time trend");
1287 frmMain->SetCleanup(kDeepCleanup);
1289 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1290 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1292 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1294 AliCalibViewerGUItime* calibViewerTime = new AliCalibViewerGUItime(tabCont1, 1000, 650);
1295 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1296 calibViewerTime->UseChain(chain);
1298 TObjArray *guiArray = new TObjArray();
1299 guiArray->Add(calibViewerTime);
1301 frmMain->MapSubwindows();
1303 frmMain->MapWindow();
1307 //__________________________________________________________________
1308 TObjArray* AliCalibViewerGUItime::ShowGUI() {
1310 // Launch the time trending GUI. The GUI will be empty but trees can be loaded by using the GUI interface
1312 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 650);
1313 frmMain->SetWindowName("Calib Viewer - time trend");
1314 frmMain->SetCleanup(kDeepCleanup);
1316 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1317 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1319 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1321 AliCalibViewerGUItime* calibViewerTime = new AliCalibViewerGUItime(tabCont1, 1000, 650);
1322 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1324 TObjArray *guiArray = new TObjArray();
1325 guiArray->Add(calibViewerTime);
1327 frmMain->MapSubwindows();
1329 frmMain->MapWindow();