177 #include "RConfigure.h"
232 static const char* gOptgen[16] =
234 "",
"AXIS",
"HIST",
"SAME",
"CYL",
"POL",
"SPH",
"PSR",
"LEGO",
"LEGO1",
"LEGO2",
235 "SURF",
"SURF1",
"SURF2",
"SURF3",
"SURF4"
237 static const char* gOpt1D[12] =
239 "",
"AH",
"B",
"C",
"E",
"E1",
"E2",
"E3",
"E4",
"L",
"P",
"*H"
241 static const char* gOpt2D[14] =
243 "",
"ARR",
"BOX",
"COL",
"COL2",
"CONT",
"CONT0",
"CONT1",
"CONT2",
"CONT3",
244 "FB",
"BB",
"SCAT",
"PROF"
247 static const char* gOpenTypes[] = {
"Root files",
"*.root",
250 static const char* gMacroTypes[] = {
"C++ macros",
"*.C",
254 enum ERootTreeViewerCommands {
257 kFileLoadLibrary = 3,
273 kOptionsGeneral = 20,
297 enum EButtonIdentifiers {
310 ClassImp(TTreeViewer);
315 TTreeViewer::TTreeViewer(
const char* treeName) :
316 TGMainFrame(0,10,10,kVerticalFrame),
317 fDimension(0), fVarDraw(0), fScanMode(0),
318 fTreeIndex(0), fDefaultCursor(0), fWatchCursor(0),
319 fCounting(0), fStopMapping(0), fEnableCut(0),fNexpressions(0)
322 if (!gClient)
return;
324 gROOT->ProcessLine(
"#ifndef GTV_DEFINED\n\
325 TTreeViewer *gTV = 0;\n\
326 TTree *tv__tree = 0;\n\
327 TList *tv__tree_list = 0;\n\
328 TFile *tv__tree_file = 0;\n\
329 #define GTV_DEFINED\n\
331 snprintf(command,128,
"gTV = (TTreeViewer*)0x%lx", (ULong_t)
this);
332 gROOT->ProcessLine(command);
333 fTreeList =
new TList;
334 gROOT->ProcessLine(
"tv__tree_list = new TList;");
336 gInterpreter->SaveContext();
338 SetTreeName(treeName);
343 TTreeViewer::TTreeViewer(
const TTree *tree) :
344 TGMainFrame(0, 10, 10, kVerticalFrame),
345 fDimension(0), fVarDraw(0), fScanMode(0),
346 fTreeIndex(0), fDefaultCursor(0), fWatchCursor(0),
347 fCounting(0), fStopMapping(0), fEnableCut(0),fNexpressions(0)
354 gROOT->ProcessLine(
"#ifndef GTV_DEFINED\n\
355 TTreeViewer *gTV = 0;\n\
356 TTree *tv__tree = 0;\n\
357 TList *tv__tree_list = 0;\n\
358 TFile *tv__tree_file = 0;\n\
359 #define GTV_DEFINED\n\
361 snprintf(command,128,
"gTV = (TTreeViewer*)0x%lx", (ULong_t)
this);
362 gROOT->ProcessLine(command);
364 fTreeList =
new TList;
365 gROOT->ProcessLine(
"tv__tree_list = new TList;");
367 gInterpreter->SaveContext();
369 TDirectory *dirsav = gDirectory;
370 TDirectory *cdir = tree->GetDirectory();
371 if (cdir) cdir->cd();
373 SetTree((TTree *)tree);
376 cdir = tree->GetDirectory();
378 if (cdir->GetFile()) fFilename = cdir->GetFile()->GetName();
380 if (dirsav) dirsav->cd();
385 void TTreeViewer::AppendTree(TTree *tree)
390 if (fTreeList->FindObject(tree)) {
391 printf(
"Tree found\n");
392 TIter next(fTreeList);
394 while ((ftree = (TTree*)next())) {
395 if (ftree==tree) {printf(
"found at index %i\n", index);
break;}
399 if (fTree != fMappedTree) {
401 fLVContainer->RemoveNonStatic();
405 TGListTreeItem *base = 0;
406 TGListTreeItem *parent = fLt->FindChildByName(base,
"TreeList");
407 TGListTreeItem *item = fLt->FindChildByName(parent, fTree->GetName());
408 fLt->ClearHighlighted();
409 fLt->HighlightItem(item);
410 fClient->NeedRedraw(fLt);
421 snprintf(command,100,
"tv__tree = (TTree *)0x%lx;", (ULong_t)tree);
422 ExecuteCommand(command);
425 if (fTreeList) fTreeList->Add(fTree);
426 ExecuteCommand(
"tv__tree_list->Add(tv__tree);");
428 TGListTreeItem *base = 0;
429 TGListTreeItem *parent = fLt->FindChildByName(base,
"TreeList");
430 if (!parent) parent = fLt->AddItem(base,
"TreeList",
new ULong_t(kLTNoType));
431 ULong_t *itemType =
new ULong_t((fTreeIndex << 8) | kLTTreeType);
433 TGListTreeItem *lTreeItem = fLt->AddItem(parent, tree->GetName(), itemType,
434 gClient->GetPicture(
"tree_t.xpm"), gClient->GetPicture(
"tree_t.xpm"));
435 MapTree(fTree, lTreeItem, kFALSE);
436 fLt->OpenItem(parent);
437 fLt->HighlightItem(lTreeItem);
438 fClient->NeedRedraw(fLt);
441 SwitchTree(fTreeIndex-1);
442 fLVContainer->RemoveNonStatic();
450 void TTreeViewer::SetNexpressions(Int_t expr)
452 Int_t diff = expr - fNexpressions;
453 if (diff <= 0)
return;
454 if (!fLVContainer)
return;
455 for (Int_t i=0; i<TMath::Abs(diff); i++) NewExpression();
460 void TTreeViewer::SetScanFileName(
const char *name)
462 if (fTree) ((TTreePlayer *)fTree->GetPlayer())->SetScanFileName(name);
467 void TTreeViewer::SetScanRedirect(Bool_t mode)
470 fBarScan->SetState(kButtonDown);
472 fBarScan->SetState(kButtonUp);
478 void TTreeViewer::SetTree(TTree *tree)
485 TString command = TString::Format(
"tv__tree = (TTree *)0x%lx;", (ULong_t)tree);
486 ExecuteCommand(command.Data());
489 if (fTreeList) fTreeList->Add(fTree);
490 ExecuteCommand(
"tv__tree_list->Add(tv__tree);");
492 TGListTreeItem *base = 0;
493 TGListTreeItem *parent = fLt->FindChildByName(base,
"TreeList");
494 if (!parent) parent = fLt->AddItem(base,
"TreeList",
new ULong_t(kLTNoType));
495 ULong_t *itemType =
new ULong_t((fTreeIndex << 8) | kLTTreeType);
497 TGListTreeItem *lTreeItem = fLt->AddItem(parent, tree->GetName(), itemType,
498 gClient->GetPicture(
"tree_t.xpm"), gClient->GetPicture(
"tree_t.xpm"));
499 MapTree(fTree, lTreeItem, kFALSE);
500 fLt->OpenItem(parent);
501 fLt->HighlightItem(lTreeItem);
502 fClient->NeedRedraw(fLt);
505 SwitchTree(fTreeIndex-1);
506 fLVContainer->RemoveNonStatic();
514 void TTreeViewer::SetTreeName(
const char* treeName)
516 if (!treeName)
return;
517 TTree *tree = (TTree *) gROOT->FindObject(treeName);
519 if (fTreeList->FindObject(treeName)) {
520 printf(
"Tree found\n");
521 TIter next(fTreeList);
523 while ((tree = (TTree*)next())) {
524 if (!strcmp(treeName, tree->GetName())) {printf(
"found at index %i\n", index);
break;}
528 if (fTree != fMappedTree) {
530 fLVContainer->RemoveNonStatic();
534 TGListTreeItem *base = 0;
535 TGListTreeItem *parent = fLt->FindChildByName(base,
"TreeList");
536 TGListTreeItem *item = fLt->FindChildByName(parent, fTree->GetName());
537 fLt->ClearHighlighted();
538 fLt->HighlightItem(item);
539 fClient->NeedRedraw(fLt);
550 TString command = TString::Format(
"tv__tree = (TTree *) gROOT->FindObject(\"%s\");", treeName);
551 ExecuteCommand(command.Data());
554 if (fTreeList) fTreeList->Add(fTree);
555 ExecuteCommand(
"tv__tree_list->Add(tv__tree);");
557 TGListTreeItem *base = 0;
558 TGListTreeItem *parent = fLt->FindChildByName(base,
"TreeList");
559 if (!parent) parent = fLt->AddItem(base,
"TreeList",
new ULong_t(kLTNoType));
560 ULong_t *itemType =
new ULong_t((fTreeIndex << 8) | kLTTreeType);
562 TGListTreeItem *lTreeItem = fLt->AddItem(parent, treeName, itemType,
563 gClient->GetPicture(
"tree_t.xpm"), gClient->GetPicture(
"tree_t.xpm"));
564 MapTree(fTree, lTreeItem, kFALSE);
565 fLt->OpenItem(parent);
566 fLt->HighlightItem(lTreeItem);
567 fClient->NeedRedraw(fLt);
570 SwitchTree(fTreeIndex-1);
571 fLVContainer->RemoveNonStatic();
579 void TTreeViewer::SetFile()
582 TSeqCollection *list = gROOT->GetListOfFiles();
587 while ((obj=next())) {
590 tree = (TTree*)file->Get(fTree->GetName());
592 fFilename = file->GetName();
593 std::cout <<
"File name : "<< fFilename << std::endl;
605 void TTreeViewer::BuildInterface()
611 fTimer =
new TTimer(
this, 20, kTRUE);
613 fSession =
new TTVSession(
this);
615 fDefaultCursor = gVirtualX->CreateCursor(kPointer);
616 fWatchCursor = gVirtualX->CreateCursor(kWatch);
619 gClient->GetColorByName(
"blue",color);
621 fPicX = gClient->GetPicture(
"x_pic.xpm");
622 fPicY = gClient->GetPicture(
"y_pic.xpm");
623 fPicZ = gClient->GetPicture(
"z_pic.xpm");
626 fContextMenu =
new TContextMenu(
"TreeViewer context menu",
"");
632 fStopMapping = kFALSE;
634 fSourceFile =
"treeviewer.C";
638 fWidgets =
new TList();
641 fFileMenu =
new TGPopupMenu(fClient->GetRoot());
642 fFileMenu->AddEntry(
"&New canvas", kFileCanvas);
643 fFileMenu->AddEntry(
"Open &tree file...", kFileBrowse);
644 fFileMenu->AddEntry(
"&Load Library...", kFileLoadLibrary);
645 fFileMenu->AddEntry(
"&Open session", kFileOpenSession);
646 fFileMenu->AddEntry(
"&Save source...", kFileSaveMacro);
647 fFileMenu->AddSeparator();
648 fFileMenu->AddEntry(
"&Print", kFilePrint);
649 fFileMenu->AddEntry(
"&Close", kFileClose);
650 fFileMenu->AddSeparator();
651 fFileMenu->AddEntry(
"&Quit ROOT", kFileQuit);
653 fFileMenu->DisableEntry(kFilePrint);
656 fEditMenu =
new TGPopupMenu(gClient->GetRoot());
657 fEditMenu->AddEntry(
"&Expression...", kEditExpression);
658 fEditMenu->AddEntry(
"&Cut...", kEditCut);
659 fEditMenu->AddEntry(
"&Macro...", kEditMacro);
660 fEditMenu->AddEntry(
"E&Vent...", kEditEvent);
662 fEditMenu->DisableEntry(kEditMacro);
663 fEditMenu->DisableEntry(kEditEvent);
665 fRunMenu =
new TGPopupMenu(gClient->GetRoot());
666 fRunMenu->AddEntry(
"&Macro...", kRunMacro);
667 fRunMenu->DisableEntry(kRunMacro);
670 fOptionsGen =
new TGPopupMenu(gClient->GetRoot());
671 fOptionsGen->AddEntry(
"Default", kOptionsGeneral);
672 fOptionsGen->AddSeparator();
673 fOptionsGen->AddEntry(
"Axis only", kOptionsGeneral+1);
674 fOptionsGen->AddEntry(
"Contour only", kOptionsGeneral+2);
675 fOptionsGen->AddEntry(
"Superimpose", kOptionsGeneral+3);
676 fOptionsGen->AddEntry(
"Cylindrical", kOptionsGeneral+4);
677 fOptionsGen->AddEntry(
"Polar", kOptionsGeneral+5);
678 fOptionsGen->AddEntry(
"Spherical", kOptionsGeneral+6);
679 fOptionsGen->AddEntry(
"PsRap/Phi", kOptionsGeneral+7);
680 fOptionsGen->AddEntry(
"Lego HLR", kOptionsGeneral+8);
681 fOptionsGen->AddEntry(
"Lego HSR", kOptionsGeneral+9);
682 fOptionsGen->AddEntry(
"Lego Color", kOptionsGeneral+10);
683 fOptionsGen->AddEntry(
"Surface HLR", kOptionsGeneral+11);
684 fOptionsGen->AddEntry(
"Surface HSR", kOptionsGeneral+12);
685 fOptionsGen->AddEntry(
"Surface Col", kOptionsGeneral+13);
686 fOptionsGen->AddEntry(
"Surf+Cont", kOptionsGeneral+14);
687 fOptionsGen->AddEntry(
"Gouraud", kOptionsGeneral+15);
688 fOptionsGen->Associate(
this);
690 fOptions1D =
new TGPopupMenu(gClient->GetRoot());
691 fOptions1D->AddEntry(
"Default", kOptions1D);
692 fOptions1D->AddSeparator();
693 fOptions1D->AddEntry(
"No labels/ticks", kOptions1D+1);
694 fOptions1D->AddEntry(
"Bar chart", kOptions1D+2);
695 fOptions1D->AddEntry(
"Smooth curve", kOptions1D+3);
696 fOptions1D->AddEntry(
"Errors", kOptions1D+4);
697 fOptions1D->AddEntry(
"Errors 1", kOptions1D+5);
698 fOptions1D->AddEntry(
"Errors 2", kOptions1D+6);
699 fOptions1D->AddEntry(
"Errors 3", kOptions1D+7);
700 fOptions1D->AddEntry(
"Errors 4", kOptions1D+8);
701 fOptions1D->AddEntry(
"Line", kOptions1D+9);
702 fOptions1D->AddEntry(
"Markers", kOptions1D+10);
703 fOptions1D->AddEntry(
"Stars", kOptions1D+11);
704 fOptions1D->Associate(
this);
706 fOptions2D =
new TGPopupMenu(gClient->GetRoot());
707 fOptions2D->AddEntry(
"Default", kOptions2D);
708 fOptions2D->AddSeparator();
709 fOptions2D->AddEntry(
"Arrows", kOptions2D+1);
710 fOptions2D->AddEntry(
"Box/Surf", kOptions2D+2);
711 fOptions2D->AddEntry(
"Box/Color", kOptions2D+3);
712 fOptions2D->AddEntry(
"Box/ColMap", kOptions2D+4);
713 fOptions2D->AddEntry(
"Contour", kOptions2D+5);
714 fOptions2D->AddEntry(
"Contour 0", kOptions2D+6);
715 fOptions2D->AddEntry(
"Contour 1", kOptions2D+7);
716 fOptions2D->AddEntry(
"Contour 2", kOptions2D+8);
717 fOptions2D->AddEntry(
"Contour 3", kOptions2D+9);
718 fOptions2D->AddEntry(
"No front-box", kOptions2D+10);
719 fOptions2D->AddEntry(
"No back-box", kOptions2D+11);
720 fOptions2D->AddEntry(
"Scatter", kOptions2D+12);
721 fOptions2D->AddEntry(
"Profile", kOptions2D+13);
722 fOptions2D->Associate(
this);
724 fOptionsMenu =
new TGPopupMenu(gClient->GetRoot());
725 fOptionsMenu->AddPopup(
"&General Options...", fOptionsGen);
726 fOptionsMenu->AddPopup(
"&1D Options", fOptions1D);
727 fOptionsMenu->AddPopup(
"&2D Options", fOptions2D);
728 fOptionsMenu->AddSeparator();
729 fOptionsMenu->AddEntry(
"&Reset options", kOptionsReset);
731 fHelpMenu =
new TGPopupMenu(gClient->GetRoot());
732 fHelpMenu->AddEntry(
"&About ROOT...", kHelpAbout);
733 fHelpMenu->AddEntry(
"&About TreeViewer...", kHelpAboutTV);
734 fHelpMenu->AddSeparator();
735 fHelpMenu->AddEntry(
"&Starting...", kHelpStart);
736 fHelpMenu->AddEntry(
"&Layout...", kHelpLayout);
737 fHelpMenu->AddEntry(
"&Open/Save", kHelpOpenSave);
738 fHelpMenu->AddEntry(
"&Dragging...", kHelpDragging);
739 fHelpMenu->AddEntry(
"&Editing expressions...",kHelpEditing);
740 fHelpMenu->AddEntry(
"&Session...", kHelpSession);
741 fHelpMenu->AddEntry(
"&User commands...", kHelpCommands);
742 fHelpMenu->AddEntry(
"&Context menus...", kHelpContext);
743 fHelpMenu->AddEntry(
"D&rawing...", kHelpDrawing);
744 fHelpMenu->AddEntry(
"&Macros...", kHelpMacros);
746 fFileMenu->Associate(
this);
747 fEditMenu->Associate(
this);
748 fRunMenu->Associate(
this);
749 fOptionsMenu->Associate(
this);
750 fHelpMenu->Associate(
this);
753 fMenuBarLayout =
new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0,0,1,1);
754 fMenuBarItemLayout =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
755 fMenuBarHelpLayout =
new TGLayoutHints(kLHintsTop | kLHintsRight);
757 fMenuBar =
new TGMenuBar(
this, 1, 1, kHorizontalFrame);
759 fMenuBar->AddPopup(
"&File", fFileMenu, fMenuBarItemLayout);
760 fMenuBar->AddPopup(
"&Edit", fEditMenu, fMenuBarItemLayout);
761 fMenuBar->AddPopup(
"&Run", fRunMenu, fMenuBarItemLayout);
762 fMenuBar->AddPopup(
"&Options", fOptionsMenu, fMenuBarItemLayout);
763 fMenuBar->AddPopup(
"&Help", fHelpMenu, fMenuBarHelpLayout);
765 AddFrame(fMenuBar, fMenuBarLayout);
767 fToolBar =
new TGToolBar(
this, 10, 10, kHorizontalFrame);
768 fBarLayout =
new TGLayoutHints(kLHintsTop | kLHintsExpandX);
771 lo =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
774 fBarLbl1 =
new TGLabel(fToolBar,
"Command");
775 fToolBar->AddFrame(fBarLbl1,lo);
777 fBarCommand =
new TGTextEntry(fToolBar,
new TGTextBuffer(250),kBarCommand);
778 fBarCommand->SetWidth(120);
779 fBarCommand->Associate(
this);
780 fBarCommand->SetToolTipText(
"User commands executed via interpreter. Type <ENTER> to execute");
781 fToolBar->AddFrame(fBarCommand, lo);
783 TGVertical3DLine *vSeparator =
new TGVertical3DLine(fToolBar);
784 lo =
new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 4,4,0,0);
786 fWidgets->Add(vSeparator);
787 fToolBar->AddFrame(vSeparator, lo);
789 lo =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
792 fBarLbl2 =
new TGLabel(fToolBar,
"Option");
793 fToolBar->AddFrame(fBarLbl2, lo);
795 fBarOption =
new TGTextEntry(fToolBar,
new TGTextBuffer(200),kBarOption);
796 fBarOption->SetWidth(100);
797 fBarOption->Associate(
this);
798 fBarOption->SetToolTipText(
"Histogram graphics option. Type option here and click <Draw> (or <ENTER> to update current histogram).");
799 fToolBar->AddFrame(fBarOption, lo);
801 vSeparator =
new TGVertical3DLine(fToolBar);
802 lo =
new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 4,4,0,0);
804 fWidgets->Add(vSeparator);
805 fToolBar->AddFrame(vSeparator, lo);
807 lo =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
810 fBarLbl3 =
new TGLabel(fToolBar,
"Histogram");
811 fToolBar->AddFrame(fBarLbl3, lo);
814 lo =
new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 4,4,0,0);
816 fBarHist =
new TGTextEntry(fToolBar,
new TGTextBuffer(100));
817 fBarHist->Resize(50, fBarHist->GetDefaultHeight());
818 fBarHist->SetDefaultSize(50, fBarHist->GetDefaultHeight());
819 fBarHist->SetText(
"htemp");
820 fToolBar->AddFrame(fBarHist, lo);
823 lo =
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
825 fBarH =
new TGCheckButton(fToolBar,
"Hist");
826 fBarH->SetToolTipText(
"Checked : redraw only current histogram");
827 fBarH->SetState(kButtonUp);
828 fToolBar->AddFrame(fBarH, lo);
830 fBarScan =
new TGCheckButton(fToolBar,
"Scan");
831 fBarScan->SetState(kButtonUp);
832 fBarScan->SetToolTipText(
"Check to redirect TTree::Scan command in a file");
833 fToolBar->AddFrame(fBarScan, lo);
835 fBarRec =
new TGCheckButton(fToolBar,
"Rec");
836 fBarRec->SetState(kButtonDown);
837 fBarRec->SetToolTipText(
"Check to record commands in history file and be verbose");
838 fToolBar->AddFrame(fBarRec, lo);
840 TGHorizontal3DLine *toolBarSep =
new TGHorizontal3DLine(
this);
841 fWidgets->Add(toolBarSep);
842 AddFrame(toolBarSep, fBarLayout);
843 AddFrame(fToolBar, fBarLayout);
845 toolBarSep =
new TGHorizontal3DLine(
this);
846 fWidgets->Add(toolBarSep);
847 AddFrame(toolBarSep, fBarLayout);
850 fHf =
new TGHorizontalFrame(
this, 10, 10);
852 fSlider =
new TGDoubleVSlider(fHf, 10, kDoubleScaleBoth, kSLIDER);
854 fSlider->Associate(
this);
857 fV1 =
new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
858 fTreeHdr =
new TGCompositeFrame(fV1, 10, 10, kSunkenFrame | kVerticalFrame);
860 fLbl1 =
new TGLabel(fTreeHdr,
"Current Folder");
861 lo =
new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY, 3, 0, 0, 0);
863 fTreeHdr->AddFrame(fLbl1, lo);
865 lo =
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 1, 0);
867 fV1->AddFrame(fTreeHdr, lo);
870 fTreeView =
new TGCanvas(fV1, fV1->GetWidth(), 10, kSunkenFrame | kDoubleBorder);
872 fLt =
new TGListTree(fTreeView->GetViewPort(), 10, 10, kHorizontalFrame,
874 fLt->Associate(
this);
875 fTreeView->SetContainer(fLt);
877 lo =
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2,0,0,0);
879 fV1->AddFrame(fTreeView, lo);
882 fHpb =
new TGHorizontalFrame(fV1, fTreeHdr->GetWidth(), 10, kSunkenFrame);
885 fPicDraw = gClient->GetPicture(
"draw_t.xpm");
886 fDRAW =
new TGPictureButton(fHpb,fPicDraw,kDRAW);
887 fDRAW->SetToolTipText(
"Draw current selection");
888 fDRAW->Associate(
this);
890 lo =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
892 fHpb->AddFrame(fDRAW, lo);
895 fSPIDER =
new TGTextButton(fHpb,
"SPIDER");
896 fSPIDER->SetToolTipText(
"Scan current selection using a spider plot");
897 fSPIDER->Associate(
this);
899 lo =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
901 fHpb->AddFrame(fSPIDER,lo);
903 fSPIDER->Connect(
"Clicked()",
"TTreeViewer",
this,
"ExecuteSpider()");
907 fPicStop = gClient->GetPicture(
"stop_t.xpm");
908 fSTOP =
new TGPictureButton(fHpb,fPicStop,kSTOP);
909 fSTOP->SetToolTipText(
"Abort current operation");
910 fSTOP->Associate(
this);
912 lo =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
914 fHpb->AddFrame(fSTOP, lo);
917 fPicRefr = gClient->GetPicture(
"refresh2.xpm");
918 fREFR =
new TGPictureButton(fHpb,fPicRefr,kDRAW);
919 fREFR->SetToolTipText(
"Update the tree viewer");
920 lo =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
922 fHpb->AddFrame(fREFR, lo);
924 fREFR->Connect(
"Clicked()",
"TTreeViewer",
this,
"DoRefresh()");
926 lo =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,2,2);
928 fV1->AddFrame(fHpb, lo);
931 fV2 =
new TGVerticalFrame(fHf, 10, 10);
932 fListHdr =
new TGCompositeFrame(fV2, 10, 10, kSunkenFrame | kFitHeight);
933 fLbl2 =
new TGLabel(fListHdr,
"Current Tree: ");
934 lo =
new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 0, 0, 0);
936 fListHdr->AddFrame(fLbl2, lo);
939 fProgressBar =
new TGHProgressBar(fListHdr);
940 fProgressBar->SetBarColor(
"red");
941 fProgressBar->SetFillType(TGProgressBar::kBlockFill);
942 lo =
new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 2,2,4,2);
944 fListHdr->AddFrame(fProgressBar, lo);
945 lo =
new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 2,0,1,2);
947 fV2->AddFrame(fListHdr, lo);
949 fV1->Resize(fTreeHdr->GetDefaultWidth()+100, fV1->GetDefaultHeight());
950 lo =
new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
952 fHf->AddFrame(fSlider, lo);
953 lo =
new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
955 fHf->AddFrame(fV1, lo);
958 TGVSplitter *splitter =
new TGVSplitter(fHf);
959 splitter->SetFrame(fV1,kTRUE);
960 lo =
new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
961 fWidgets->Add(splitter);
963 fHf->AddFrame(splitter,lo);
968 fListView =
new TGListView(fListHdr,400,300);
970 fLVContainer =
new TTVLVContainer(fListView->GetViewPort(),400,300);
971 fLVContainer->Associate(
this);
972 fLVContainer->SetListView(fListView);
973 fLVContainer->SetViewer(
this);
974 fLVContainer->SetBackgroundColor(GetWhitePixel());
975 fListView->GetViewPort()->SetBackgroundColor(GetWhitePixel());
976 fListView->SetContainer(fLVContainer);
977 fListView->SetViewMode(kLVList);
978 lo =
new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX | kLHintsExpandY);
981 fListHdr->AddFrame(fListView,lo);
983 lo =
new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY);
985 fHf->AddFrame(fV2,lo);
989 toolBarSep =
new TGHorizontal3DLine(
this);
990 fWidgets->Add(toolBarSep);
991 AddFrame(toolBarSep, fBarLayout);
994 fBFrame =
new TGHorizontalFrame(
this,10,10);
995 fBLbl4 =
new TGLabel(fBFrame,
"IList");
996 lo =
new TGLayoutHints(kLHintsLeft | kLHintsBottom, 2,2,2,2);
998 fBFrame->AddFrame(fBLbl4, lo);
1000 fBarListIn =
new TGTextEntry(fBFrame,
new TGTextBuffer(100));
1001 fBarListIn->SetWidth(60);
1002 fBarListIn->SetToolTipText(
"Name of a previously created event list");
1003 fBFrame->AddFrame(fBarListIn, lo);
1005 fBLbl5 =
new TGLabel(fBFrame,
"OList");
1006 fBFrame->AddFrame(fBLbl5, lo);
1008 fBarListOut =
new TGTextEntry(fBFrame,
new TGTextBuffer(100));
1009 fBarListOut->SetWidth(60);
1010 fBarListOut->SetToolTipText(
"Output event list. Use <Draw> to generate it.");
1011 fBFrame->AddFrame(fBarListOut, lo);
1013 fStatusBar =
new TGStatusBar(fBFrame, 10, 10);
1014 fStatusBar->SetWidth(200);
1015 fStatusBar->Draw3DCorner(kFALSE);
1016 lo =
new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsLeft | kLHintsExpandX, 2,2,2,2);
1018 fBFrame->AddFrame(fStatusBar, lo);
1020 fReset =
new TGTextButton(fBFrame,
"RESET",kRESET);
1021 fReset->SetToolTipText(
"Reset variable's fields and drawing options");
1022 fReset->Associate(
this);
1023 lo =
new TGLayoutHints(kLHintsTop | kLHintsRight, 2,2,2,2);
1025 fBFrame->AddFrame(fReset,lo);
1027 fBGFirst =
new TGPictureButton(fBFrame,
1028 gClient->GetPicture(
"first_t.xpm"), kBGFirst);
1029 fBGFirst->SetToolTipText(
"First record");
1030 fBGFirst->Associate(
this);
1031 fBGPrevious =
new TGPictureButton(fBFrame,
1032 gClient->GetPicture(
"previous_t.xpm"), kBGPrevious);
1033 fBGPrevious->SetToolTipText(
"Previous record");
1034 fBGPrevious->Associate(
this);
1035 fBGRecord =
new TGPictureButton(fBFrame,
1036 gClient->GetPicture(
"record_t.xpm"), kBGRecord);
1037 fBGRecord->SetToolTipText(
"Record");
1038 fBGRecord->Associate(
this);
1039 fBGNext =
new TGPictureButton(fBFrame,
1040 gClient->GetPicture(
"next_t.xpm"), kBGNext);
1041 fBGNext->SetToolTipText(
"Next record");
1042 fBGNext->Associate(
this);
1043 fBGLast =
new TGPictureButton(fBFrame,
1044 gClient->GetPicture(
"last_t.xpm"), kBGLast);
1045 fBGLast->SetToolTipText(
"Last record");
1046 fBGLast->Associate(
this);
1048 fCombo =
new TGComboBox(fBFrame, 0);
1049 fCombo->SetHeight(fReset->GetDefaultHeight());
1050 fCombo->SetWidth(100);
1051 fCombo->Associate(
this);
1053 lo =
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 0,0,2,0);
1055 fBFrame->AddFrame(fCombo, lo);
1056 fBFrame->AddFrame(fBGLast, lo);
1057 fBFrame->AddFrame(fBGNext, lo);
1058 fBFrame->AddFrame(fBGRecord, lo);
1059 fBFrame->AddFrame(fBGPrevious, lo);
1060 fBFrame->AddFrame(fBGFirst, lo);
1061 lo =
new TGLayoutHints(kLHintsExpandX,2,2,2,0);
1063 AddFrame(fBFrame,lo);
1066 SetWindowName(
"TreeViewer");
1068 Resize(GetDefaultSize());
1072 const TGPicture *pic, *spic;
1074 fLVContainer->RemoveAll();
1077 entry =
new TTVLVEntry(fLVContainer,fPicX,fPicX,
new TGString(),0,kLVSmallIcons);
1079 entry->SetUserData(
new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
1080 entry->SetToolTipText(
"X expression. Drag and drop expressions here");
1082 fLVContainer->AddThisItem(entry);
1086 entry =
new TTVLVEntry(fLVContainer,fPicY,fPicY,
new TGString(),0,kLVSmallIcons);
1088 entry->SetUserData(
new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
1089 entry->SetToolTipText(
"Y expression. Drag and drop expressions here");
1091 fLVContainer->AddThisItem(entry);
1095 entry =
new TTVLVEntry(fLVContainer,fPicZ,fPicZ,
new TGString(),0,kLVSmallIcons);
1097 entry->SetUserData(
new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
1098 entry->SetToolTipText(
"Z expression. Drag and drop expressions here");
1100 fLVContainer->AddThisItem(entry);
1104 pic = gClient->GetPicture(
"cut_t.xpm");
1105 spic = gClient->GetPicture(
"cut_t.xpm");
1106 entry =
new TTVLVEntry(fLVContainer,pic,spic,
new TGString(),0,kLVSmallIcons);
1107 entry->SetUserData(
new ULong_t(kLTExpressionType | kLTCutType));
1108 entry->SetToolTipText(
"Active cut. Double-click to enable/disable");
1110 fLVContainer->AddThisItem(entry);
1114 pic = gClient->GetPicture(
"pack_t.xpm");
1115 spic = gClient->GetPicture(
"pack-empty_t.xpm");
1116 entry =
new TTVLVEntry(fLVContainer,pic,spic,
new TGString(
"Scan box"),0,kLVSmallIcons);
1117 entry->SetUserData(
new ULong_t(kLTExpressionType | kLTPackType));
1118 entry->SetToolTipText(
"Drag and drop expressions/leaves here. Double-click to scan. Check <Scan> to redirect on file.");
1120 fLVContainer->AddThisItem(entry);
1122 entry->SetTrueName(
"");
1126 for (Int_t i=0; i<fNexpressions; i++) {
1127 pic = gClient->GetPicture(
"expression_t.xpm");
1128 spic = gClient->GetPicture(
"expression_t.xpm");
1129 entry =
new TTVLVEntry(fLVContainer,pic,spic,
new TGString(),0,kLVSmallIcons);
1130 entry->SetUserData(
new ULong_t(kLTExpressionType | kLTDragType));
1131 entry->SetToolTipText(
"User defined expression/cut. Double-click to edit");
1132 fLVContainer->AddThisItem(entry);
1137 fListView->Layout();
1138 fListView->Resize();
1143 fSlider->SetRange(0,1000000);
1144 fSlider->SetPosition(0,1000000);
1146 fSlider->SetRange(0,fTree->GetEntries()-1);
1147 fSlider->SetPosition(0,fTree->GetEntries()-1);
1150 fProgressBar->SetPosition(0);
1151 fProgressBar->ShowPosition();
1152 ActivateButtons(kFALSE, kFALSE, kFALSE, kFALSE);
1157 Resize(GetDefaultSize());
1164 TTreeViewer::~TTreeViewer()
1166 if (!gClient)
return;
1167 gClient->FreePicture(fPicX);
1168 gClient->FreePicture(fPicY);
1169 gClient->FreePicture(fPicZ);
1170 gClient->FreePicture(fPicDraw);
1171 gClient->FreePicture(fPicStop);
1172 gClient->FreePicture(fPicRefr);
1174 fDialogBox = TGSelectBox::GetInstance();
1175 if (fDialogBox)
delete fDialogBox;
1177 delete fContextMenu;
1206 delete fLVContainer;
1209 delete fProgressBar;
1231 delete fOptionsMenu;
1233 delete fMenuBarLayout;
1234 delete fMenuBarItemLayout;
1235 delete fMenuBarHelpLayout;
1250 void TTreeViewer::ActivateButtons(Bool_t first, Bool_t previous,
1251 Bool_t next, Bool_t last)
1253 if (first) fBGFirst->SetState(kButtonUp);
1254 else fBGFirst->SetState(kButtonDisabled);
1255 if (previous) fBGPrevious->SetState(kButtonUp);
1256 else fBGPrevious->SetState(kButtonDisabled);
1257 if (next) fBGNext->SetState(kButtonUp);
1258 else fBGNext->SetState(kButtonDisabled);
1259 if (last) fBGLast->SetState(kButtonUp);
1260 else fBGLast->SetState(kButtonDisabled);
1266 const char* TTreeViewer::Cut()
1268 return fLVContainer->Cut();
1274 const char* TTreeViewer::ScanList()
1276 return fLVContainer->ScanList();
1282 void TTreeViewer::SetSession(TTVSession *session)
1293 const char* TTreeViewer::EmptyBrackets(
const char* name)
1295 TString stripped(name);
1296 if (!stripped.Contains(
"["))
return name;
1297 TString retstr(name);
1300 while (stripped.Index(
"[", index) != kNPOS) {
1301 Int_t start = stripped.Index(
"[", index);
1302 Int_t end = stripped.Index(
"]", index);
1304 objstr =
new TObjString(retstr.Data());
1305 fWidgets->Add(objstr);
1306 return (objstr->String()).Data();
1309 retstr = stripped.Remove(start+1, end-start-1);
1312 objstr =
new TObjString(retstr.Data());
1313 fWidgets->Add(objstr);
1314 return (objstr->String()).Data();
1320 void TTreeViewer::EmptyAll()
1322 fLVContainer->EmptyAll();
1328 void TTreeViewer::Empty()
1331 TTVLVEntry *item = 0;
1332 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
1333 Warning(
"Empty",
"No item selected.");
1336 ULong_t *itemType = (ULong_t *) item->GetUserData();
1337 if (!(*itemType & kLTExpressionType)) {
1338 Warning(
"Empty",
"Not expression type.");
1341 if (*itemType & kLTPackType) {
1342 item->SetSmallPic(fClient->GetPicture(
"pack-empty_t.xpm"));
1343 item->SetTrueName(
"");
1352 TTVLVEntry * TTreeViewer::ExpressionItem(Int_t index)
1354 return fLVContainer->ExpressionItem(index);
1360 TList* TTreeViewer::ExpressionList()
1362 return fLVContainer->ExpressionList();
1368 Int_t TTreeViewer::Dimension()
1371 if (Ex() && strlen(Ex())) fDimension++;
1372 if (Ey() && strlen(Ey())) fDimension++;
1373 if (Ez() && strlen(Ez())) fDimension++;
1380 void TTreeViewer::ExecuteDraw()
1384 Int_t dimension = 0;
1392 if (!(item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)))
return;
1393 alias[0] = item->GetAlias();
1394 if (alias[0].BeginsWith(
"~")) alias[0].Remove(0, 1);
1395 varexp = item->ConvertAliases();
1397 if (Ez() && strlen(Ez())) {
1400 item = ExpressionItem(2);
1401 alias[2] = item->GetAlias();
1402 if (alias[2].BeginsWith(
"~")) alias[2].Remove(0, 1);
1404 if ((Ez() && strlen(Ez())) && ((Ex() &&strlen(Ex())) || (Ey() && strlen(Ey())))) varexp +=
":";
1405 if (Ey() && strlen(Ey())) {
1408 item = ExpressionItem(1);
1409 alias[1] = item->GetAlias();
1410 if (alias[1].BeginsWith(
"~")) alias[1].Remove(0, 1);
1412 if (Ey() && strlen(Ey()) && Ex() && strlen(Ex())) varexp +=
":";
1413 if (Ex () && strlen(Ex())) {
1416 item = ExpressionItem(0);
1417 alias[0] = item->GetAlias();
1418 if (alias[0].BeginsWith(
"~")) alias[0].Remove(0, 1);
1421 if (!dimension && !fScanMode) {
1422 Warning(
"ExecuteDraw",
"Nothing to draw on X,Y,Z.");
1426 fTree->SetEventList(0);
1427 TEventList *elist = 0;
1428 if (strlen(fBarListIn->GetText())) {
1429 elist = (TEventList *) gROOT->FindObject(fBarListIn->GetText());
1430 if (elist) fTree->SetEventList(elist);
1433 if (strlen(fBarListOut->GetText())) varexp = TString::Format(
">>%s", fBarListOut->GetText());
1435 if (strcmp(
"htemp", fBarHist->GetText())) {
1437 varexp += fBarHist->GetText();
1440 TPad *pad = (TPad*)gROOT->GetSelectedPad();
1443 const char* gopt = fBarOption->GetText();
1445 gROOT->SetInterrupt(kFALSE);
1447 const char *cut =
"";
1448 if (fEnableCut) cut = Cut();
1451 Long64_t nentries = (Long64_t)(fSlider->GetMaxPosition() -
1452 fSlider->GetMinPosition() + 1);
1453 Long64_t firstentry =(Long64_t) fSlider->GetMinPosition();
1459 if (ScanList() && strlen(ScanList())) varexp = ScanList();
1460 command = TString::Format(
"tv__tree->Scan(\"%s\",\"%s\",\"%s\", %lld, %lld);",
1461 varexp.Data(), cut, gopt, nentries, firstentry);
1462 if (fBarScan->GetState() == kButtonDown) {
1463 ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kTRUE);
1465 ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kFALSE);
1467 ExecuteCommand(command.Data(), kTRUE);
1471 if (fBarH->GetState() == kButtonDown) {
1473 fBarH->SetState(kButtonUp);
1474 TH1 *hist = fTree->GetHistogram();
1479 TString last(fLastOption);
1480 TString current(gopt);
1483 if (current == last) {
1487 if (dimension == 3 && strlen(gopt)) {
1488 std::cout <<
"Graphics option " << gopt <<
" not valid for 3D histograms" << std::endl;
1491 std::cout <<
" Graphics option for current histogram changed to " << gopt << std::endl;
1493 fLastOption = fBarOption->GetText();
1500 fLastOption = fBarOption->GetText();
1505 if (dimension == 3 && strlen(gopt)) {
1506 std::cout <<
"Graphics option " << gopt <<
" not valid for 3D histograms" << std::endl;
1510 command = TString::Format(
"tv__tree->Draw(\"%s\",\"%s\",\"%s\", %lld, %lld);",
1511 varexp.Data(), cut, gopt, nentries, firstentry);
1512 if (fCounting)
return;
1514 fTree->SetTimerInterval(200);
1516 ExecuteCommand(command.Data());
1517 HandleTimer(fTimer);
1519 fTree->SetTimerInterval(0);
1521 fProgressBar->SetPosition(0);
1522 fProgressBar->ShowPosition();
1523 TH1 *hist = fTree->GetHistogram();
1527 for (i=0; i<3; i++) {
1528 if (alias[i].Length()) {
1530 alias[current] = alias[i];
1538 axis[0] = hist->GetXaxis();
1539 axis[1] = hist->GetYaxis();
1540 axis[2] = hist->GetZaxis();
1541 for (Int_t ind=0; ind<3; ind++) axis[ind]->SetTitle(alias[ind].Data());
1543 if (gPad) gPad->Update();
1549 void TTreeViewer::ExecuteSpider()
1552 Int_t dimension = 0;
1555 Bool_t previousexp = kFALSE;
1557 if (Ez() && strlen(Ez())) {
1558 previousexp = kTRUE;
1561 item = ExpressionItem(2);
1562 alias[2] = item->GetAlias();
1563 if (alias[2].BeginsWith(
"~")) alias[2].Remove(0, 1);
1565 if ((Ez() && strlen(Ez())) && ((Ex() && strlen(Ex())) || (Ey() && strlen(Ey())))) varexp +=
":";
1566 if (Ey() && strlen(Ey())) {
1567 previousexp = kTRUE;
1570 item = ExpressionItem(1);
1571 alias[1] = item->GetAlias();
1572 if (alias[1].BeginsWith(
"~")) alias[1].Remove(0, 1);
1574 if (Ey() && strlen(Ey()) && Ex() && strlen(Ex())) varexp +=
":";
1575 if (Ex() && strlen(Ex())) {
1576 previousexp = kTRUE;
1579 item = ExpressionItem(0);
1580 alias[0] = item->GetAlias();
1581 if (alias[0].BeginsWith(
"~")) alias[0].Remove(0, 1);
1583 for(Int_t i=0;i<10;++i){
1584 if(En(i+5) && strlen(En(i+5))){
1589 }
else varexp = En(i+5);
1590 previousexp = kTRUE;
1594 Warning(
"ExecuteSpider",
"Need at least 3 variables");
1598 fTree->SetEventList(0);
1599 TEventList *elist = 0;
1600 if (strlen(fBarListIn->GetText())) {
1601 elist = (TEventList *) gROOT->FindObject(fBarListIn->GetText());
1602 if (elist) fTree->SetEventList(elist);
1605 if (strlen(fBarListOut->GetText())) varexp = TString::Format(
">>%s", fBarListOut->GetText());
1607 TPad *pad = (TPad*)gROOT->GetSelectedPad();
1610 const char* gopt = fBarOption->GetText();
1612 gROOT->SetInterrupt(kFALSE);
1614 const char *cut =
"";
1615 if (fEnableCut) cut = Cut();
1618 Long64_t nentries = (Long64_t)(fSlider->GetMaxPosition() -
1619 fSlider->GetMinPosition() + 1);
1620 Long64_t firstentry =(Long64_t) fSlider->GetMinPosition();
1624 TSpider* spider =
new TSpider(fTree,varexp.Data(),cut,Form(
"%s spider average",gopt),nentries,firstentry);
1627 if (gPad) gPad->Update();
1633 const char* TTreeViewer::Ex()
1635 return fLVContainer->Ex();
1641 const char* TTreeViewer::Ey()
1643 return fLVContainer->Ey();
1649 const char* TTreeViewer::Ez()
1651 return fLVContainer->Ez();
1657 const char* TTreeViewer::En(Int_t n)
1659 TTVLVEntry *e = fLVContainer->ExpressionItem(n);
1660 if(e)
return e->ConvertAliases();
1667 void TTreeViewer::EditExpression()
1671 TTVLVEntry *item = 0;
1672 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
1673 Warning(
"EditExpression",
"No item selected.");
1677 ULong_t *itemType = (ULong_t *) item->GetUserData();
1678 if (!(*itemType & kLTExpressionType)) {
1679 Warning(
"EditExpression",
"Not expression type.");
1683 fDialogBox = TGSelectBox::GetInstance();
1685 fDialogBox =
new TGSelectBox(fClient->GetRoot(),
this, fV1->GetWidth() - 10);
1688 fDialogBox->SetEntry(item);
1689 fDialogBox->SetWindowName(
"Expression editor");
1691 if (*itemType & kLTCutType || item->IsCut()) {
1692 fDialogBox->SetLabel(
"Selection");
1694 fDialogBox->SetLabel(
"Expression");
1701 Int_t TTreeViewer::MakeSelector(
const char* selector)
1703 if (!fTree)
return 0;
1704 return fTree->MakeSelector(selector);
1710 Long64_t TTreeViewer::Process(
const char* filename, Option_t *option, Long64_t nentries, Long64_t firstentry)
1712 if (!fTree)
return 0;
1713 return fTree->Process(filename, option, nentries, firstentry);
1719 const char *TTreeViewer::GetGrOpt()
1721 return fBarOption->GetText();
1727 void TTreeViewer::SetGrOpt(
const char *option)
1729 fBarOption->SetText(option);
1735 Bool_t TTreeViewer::IsScanRedirected()
1737 return (fBarScan->GetState()==kButtonDown);
1743 void TTreeViewer::RemoveItem()
1746 TTVLVEntry *item = 0;
1748 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
1749 Warning(
"RemoveItem",
"No item selected.");
1753 ULong_t *itemType = (ULong_t *) item->GetUserData();
1754 if (!(*itemType & kLTDragType)) {
1755 Warning(
"RemoveItem",
"Not removable type.");
1758 fLVContainer->RemoveItem(item);
1759 fListView->Layout();
1765 void TTreeViewer::RemoveLastRecord()
1767 fSession->RemoveLastRecord();
1773 Bool_t TTreeViewer::HandleTimer(TTimer *timer)
1776 Float_t first = fSlider->GetMinPosition();
1777 Float_t last = fSlider->GetMaxPosition();
1778 Float_t current = (Float_t)fTree->GetReadEntry();
1779 Float_t percent = (current-first+1)/(last-first+1);
1780 fProgressBar->SetPosition(100.*percent);
1781 fProgressBar->ShowPosition();
1790 Bool_t TTreeViewer::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
1792 TRootHelpDialog *hd;
1795 switch (GET_MSG(msg)) {
1801 switch (GET_SUBMSG(msg)) {
1804 if ((ERootTreeViewerCommands)parm1 == kBarCommand) {
1805 ExecuteCommand(fBarCommand->GetText());
1806 fBarCommand->Clear();
1808 if ((ERootTreeViewerCommands)parm1 == kBarOption) {
1810 fBarH->SetState(kButtonDown);
1812 fBarH->SetState(kButtonUp);
1820 switch (GET_SUBMSG(msg)) {
1822 case kCT_ITEMCLICK :
1827 if (((EMouseButton)parm1==kButton1) ||
1828 ((EMouseButton)parm1==kButton3)) {
1829 TGListTreeItem *ltItem = 0;
1831 if ((ltItem = fLt->GetSelected()) != 0) {
1833 ULong_t *itemType = (ULong_t *)ltItem->GetUserData();
1836 if (*itemType & kLTTreeType) {
1838 Int_t index = (Int_t)(*itemType >> 8);
1840 if (fTree != fMappedTree) {
1842 fLVContainer->RemoveNonStatic();
1845 fListView->Layout();
1848 if (parm1 == kButton3) {
1849 Int_t x = (Int_t)(parm2 &0xffff);
1850 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
1851 fContextMenu->Popup(x, y, fTree);
1855 if (*itemType & kLTBranchType) {
1857 SetParentTree(ltItem);
1859 TBranch *branch = fTree->GetBranch(ltItem->GetText());
1862 if (branch != fMappedBranch) {
1863 fLVContainer->RemoveNonStatic();
1865 fStopMapping = kFALSE;
1866 fListView->Layout();
1869 if (parm1 == kButton3) {
1870 Int_t x = (Int_t)(parm2 &0xffff);
1871 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
1872 fContextMenu->Popup(x, y, branch);
1876 if (*itemType & kLTLeafType) {
1878 SetParentTree(ltItem);
1881 TBranch *branch = fTree->GetBranch(ltItem->GetParent()->GetText());
1883 if (fTree != fMappedTree) {
1884 fLVContainer->RemoveNonStatic();
1886 fListView->Layout();
1890 if (branch!=fMappedBranch) {
1891 fLVContainer->RemoveNonStatic();
1893 fStopMapping = kFALSE;
1894 fListView->Layout();
1898 fLVContainer->SelectItem(ltItem->GetText());
1899 if (parm1 == kButton3) {
1901 ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMCLICK), kButton3, parm2);
1907 case kCT_ITEMDBLCLICK :
1908 fClient->NeedRedraw(fLt);
1909 if (parm1 == kButton1) {
1911 ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMDBLCLICK), kButton1, parm2);
1919 switch (GET_SUBMSG(msg)) {
1921 if ((record = fSession->GetRecord((Int_t)parm2)))
1922 fSession->Show(record);
1936 gROOT->SetInterrupt(kTRUE);
1942 if ((record = fSession->First()))
1943 fSession->Show(record);
1946 if ((record = fSession->Previous()))
1947 fSession->Show(record);
1950 fSession->AddRecord();
1953 if ((record = fSession->Next()))
1954 fSession->Show(record);
1957 if ((record = fSession->Last()))
1958 fSession->Show(record);
1967 if ((parm1>=kOptionsReset) && (parm1<kHelpAbout)) {
1969 if ((fDimension==0) && (parm1>=kOptions1D)) {
1970 Warning(
"ProcessMessage",
"Edit expressions first.");
1973 if ((fDimension==1) && (parm1>=kOptions2D)) {
1974 Warning(
"ProcessMessage",
"You have only one expression active.");
1977 if ((fDimension==2) && (parm1>=kOptions1D) &&(parm1<kOptions2D)) {
1978 Warning(
"ProcessMessage",
"1D drawing options not apply to 2D histograms.");
1987 gROOT->MakeDefCanvas();
1991 static TString dir(
".");
1993 info.fFileTypes = gOpenTypes;
1994 info.fIniDir = StrDup(dir);
1995 new TGFileDialog(fClient->GetRoot(),
this, kFDOpen, &info);
1996 if (!info.fFilename)
return kTRUE;
1998 TString command = TString::Format(
"tv__tree_file = new TFile(\"%s\");",
1999 gSystem->UnixPathName(info.fFilename));
2000 ExecuteCommand(command.Data());
2001 ExecuteCommand(
"tv__tree_file->ls();");
2002 std::cout <<
"Use SetTreeName() from context menu and supply a tree name" << std::endl;
2003 std::cout <<
"The context menu is activated by right-clicking the panel from right" << std::endl;
2006 case kFileLoadLibrary:
2007 fBarCommand->SetText(
"gSystem->Load(\"\");");
2010 event.fType = kButtonPress;
2011 event.fCode = kButton1;
2012 event.fX =
event.fY = 1;
2013 fBarCommand->HandleButton(&event);
2015 fBarCommand->SetCursorPosition(15);
2017 case kFileOpenSession:
2019 static TString dir(
".");
2021 info.fFileTypes = gMacroTypes;
2022 info.fIniDir = StrDup(dir);
2023 new TGFileDialog(fClient->GetRoot(),
this, kFDOpen, &info);
2024 if (!info.fFilename)
return kTRUE;
2026 gInterpreter->Reset();
2027 if (!gInterpreter->IsLoaded(info.fFilename)) gInterpreter->LoadMacro(info.fFilename);
2030 snprintf(command,1024,
"open_session((void*)0x%lx);", (Long_t)
this);
2031 ExecuteCommand(command);
2034 case kFileSaveMacro:
2035 fContextMenu->Action(
this,(TMethod*)IsA()->GetListOfMethods()->FindObject(
"SaveSource"));
2043 gApplication->Terminate(0);
2045 case kEditExpression:
2060 TString rootx = TROOT::GetBinDir() +
"/root -a &";
2061 gSystem->Exec(rootx);
2064 new TWin32SplashThread(kTRUE);
2067 snprintf(str,32,
"About ROOT %s...", gROOT->GetVersion());
2068 hd =
new TRootHelpDialog(
this, str, 600, 400);
2069 hd->SetText(gHelpAbout);
2076 hd =
new TRootHelpDialog(
this,
"About TreeViewer...", 600, 400);
2077 hd->SetText(gTVHelpAbout);
2078 hd->Resize(hd->GetDefaultSize());
2082 hd =
new TRootHelpDialog(
this,
"Quick start...", 600, 400);
2083 hd->SetText(gTVHelpStart);
2087 hd =
new TRootHelpDialog(
this,
"Layout...", 600, 400);
2088 hd->SetText(gTVHelpLayout);
2092 hd =
new TRootHelpDialog(
this,
"Open/Save...", 600, 400);
2093 hd->SetText(gTVHelpOpenSave);
2097 hd =
new TRootHelpDialog(
this,
"Dragging items...", 600, 400);
2098 hd->SetText(gTVHelpDraggingItems);
2102 hd =
new TRootHelpDialog(
this,
"Editing expressions...", 600, 400);
2103 hd->SetText(gTVHelpEditExpressions);
2107 hd =
new TRootHelpDialog(
this,
"Session...", 600, 400);
2108 hd->SetText(gTVHelpSession);
2112 hd =
new TRootHelpDialog(
this,
"Executing user commands...", 600, 400);
2113 hd->SetText(gTVHelpUserCommands);
2117 hd =
new TRootHelpDialog(
this,
"Context menus...", 600, 400);
2118 hd->SetText(gTVHelpContext);
2122 hd =
new TRootHelpDialog(
this,
"Drawing histograms...", 600, 400);
2123 hd->SetText(gTVHelpDrawing);
2127 hd =
new TRootHelpDialog(
this,
"Using macros...", 600, 400);
2128 hd->SetText(gTVHelpMacros);
2140 switch (GET_SUBMSG(msg)) {
2142 case kCT_SELCHANGED:
2148 if (fLVContainer->NumSelected()) {
2152 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
2153 const char* vname = item->GetTrueName();
2154 TString trueName(vname);
2155 if (trueName.Contains(
"[]")) {
2156 TIter next(fTree->GetListOfLeaves());
2158 while((leaf=(TLeaf*)next())) {
2159 if (!strcmp(vname, EmptyBrackets(leaf->GetName())))
2160 vname = leaf->GetName();
2163 char* msg2 =
new char[2000];
2165 ULong_t *itemType = (ULong_t *) item->GetUserData();
2166 if (*itemType & kLTTreeType) {
2168 char symbol = (char)((*itemType) >> 8);
2169 snprintf(msg2,2000,
"%c expression : %s", symbol, vname);
2171 if (*itemType & kLTCutType) {
2173 snprintf(msg2,2000,
"Cut : %s", vname);
2175 if (*itemType & kLTPackType) {
2176 snprintf(msg2,2000,
"Box : %s", vname);
2178 if (*itemType & kLTExpressionType) {
2180 snprintf(msg2,2000,
"Expression : %s", vname);
2182 if (*itemType & kLTBranchType) {
2183 snprintf(msg2,2000,
"Branch : %s", vname);
2185 snprintf(msg2,2000,
"Leaf : %s", vname);
2192 TString message = msg2;
2193 message = message(0,150);
2197 if ((*itemType & kLTBranchType) || (*itemType & kLTCutType))
break;
2198 fDialogBox = TGSelectBox::GetInstance();
2199 if (!fDialogBox || !vname[0])
break;
2200 if (item == fDialogBox->EditedEntry())
break;
2203 TString insert(item->GetAlias());
2208 fDialogBox->GrabPointer();
2209 fDialogBox->InsertText(insert.Data());
2218 if (fLVContainer->NumSelected()) {
2220 Int_t x = (Int_t)(parm2 &0xffff);
2221 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
2222 TTVLVEntry *item = 0;
2223 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
2224 fContextMenu->Popup(x, y, item->GetContext());
2227 Int_t x = (Int_t)(parm2 &0xffff);
2228 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
2229 fContextMenu->Popup(x, y,
this);
2236 case kCT_ITEMDBLCLICK:
2239 if (fLVContainer->NumSelected()) {
2243 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
2245 ULong_t *itemType = (ULong_t *) item->GetUserData();
2246 if (!(*itemType & kLTCutType) && !(*itemType & kLTBranchType)
2247 && !(*itemType & kLTPackType)) {
2248 if (strlen(item->GetTrueName())) {
2258 if (*itemType & kLTCutType) {
2259 fEnableCut = !fEnableCut;
2261 item->SetSmallPic(gClient->GetPicture(
"cut_t.xpm"));
2263 item->SetSmallPic(gClient->GetPicture(
"cut-disable_t.xpm"));
2266 if (*itemType & kLTPackType) {
2296 void TTreeViewer::CloseWindow()
2304 void TTreeViewer::ExecuteCommand(
const char* command, Bool_t fast)
2307 if (fBarRec->GetState() == kButtonDown) {
2312 if (strlen(command) > 1999) {
2313 Warning(
"ExecuteCommand",
"Command too long: aborting.");
2316 snprintf(comm,2000,
"%s", command);
2322 gROOT->ProcessLineFast(command);
2324 gROOT->ProcessLine(command);
2333 void TTreeViewer::MapOptions(Long_t parm1)
2336 if (parm1 == kOptionsReset) {
2337 for (ind=kOptionsGeneral; ind<kOptionsGeneral+16; ind++)
2338 fOptionsGen->UnCheckEntry(ind);
2339 for (ind=kOptions1D; ind<kOptions1D+12; ind++)
2340 fOptions1D->UnCheckEntry(ind);
2341 for (ind=kOptions2D; ind<kOptions2D+14; ind++)
2342 fOptions2D->UnCheckEntry(ind);
2344 if ((parm1 < kOptions1D) && (parm1 != kOptionsReset)) {
2345 if (fOptionsGen->IsEntryChecked((Int_t)parm1)) {
2346 fOptionsGen->UnCheckEntry((Int_t)parm1);
2348 fOptionsGen->CheckEntry((Int_t)parm1);
2349 if ((Int_t)parm1 != kOptionsGeneral) fOptionsGen->UnCheckEntry((Int_t)kOptionsGeneral);
2351 if (fOptionsGen->IsEntryChecked((Int_t)kOptionsGeneral)) {
2353 for (ind=kOptionsGeneral+1; ind<kOptionsGeneral+16; ind++) {
2354 fOptionsGen->UnCheckEntry(ind);
2359 if ((parm1 < kOptions2D) && (parm1 >= kOptions1D)) {
2360 if (fOptions1D->IsEntryChecked((Int_t)parm1)) {
2361 fOptions1D->UnCheckEntry((Int_t)parm1);
2363 fOptions1D->CheckEntry((Int_t)parm1);
2364 if ((Int_t)parm1 != kOptions1D) fOptions1D->UnCheckEntry((Int_t)kOptions1D);
2366 if (fOptions1D->IsEntryChecked((Int_t)kOptions1D)) {
2368 for (ind=kOptions1D+1; ind<kOptions1D+12; ind++) {
2369 fOptions1D->UnCheckEntry(ind);
2374 if (parm1 >= kOptions2D) {
2375 if (fOptions2D->IsEntryChecked((Int_t)parm1)) {
2376 fOptions2D->UnCheckEntry((Int_t)parm1);
2378 fOptions2D->CheckEntry((Int_t)parm1);
2379 if ((Int_t)parm1 != kOptions2D) fOptions2D->UnCheckEntry((Int_t)kOptions2D);
2381 if (fOptions2D->IsEntryChecked((Int_t)kOptions2D)) {
2383 for (ind=kOptions2D+1; ind<kOptions2D+14; ind++) {
2384 fOptions2D->UnCheckEntry(ind);
2389 fBarOption->SetText(
"");
2390 for (ind=kOptionsGeneral; ind<kOptionsGeneral+16; ind++) {
2391 if (fOptionsGen->IsEntryChecked(ind))
2392 fBarOption->AppendText(gOptgen[ind-kOptionsGeneral]);
2394 if (Dimension() == 1) {
2395 for (ind=kOptions1D; ind<kOptions1D+12; ind++) {
2396 if (fOptions1D->IsEntryChecked(ind))
2397 fBarOption->AppendText(gOpt1D[ind-kOptions1D]);
2400 if (Dimension() == 2) {
2401 for (ind=kOptions2D; ind<kOptions2D+14; ind++) {
2402 if (fOptions2D->IsEntryChecked(ind))
2403 fBarOption->AppendText(gOpt2D[ind-kOptions2D]);
2411 void TTreeViewer::MapTree(TTree *tree, TGListTreeItem *parent, Bool_t listIt)
2414 TObjArray *branches = tree->GetListOfBranches();
2415 if (!branches)
return;
2419 for (
id=0;
id<branches->GetEntries();
id++) {
2420 branch = (TBranch *)branches->At(
id);
2421 if (branch->TestBit(kDoNotProcess))
continue;
2422 TString name = branch->GetName();
2423 if (name.Contains(
"fBits") || name.Contains(
"fUniqueID"))
continue;
2425 MapBranch(branch,
"", parent, listIt);
2426 fStopMapping = kFALSE;
2431 TIter nextf( tree->GetTree()->GetListOfFriends() );
2433 while ((fr = (TFriendElement*)nextf())) {
2434 TTree * t = fr->GetTree();
2435 branches = t->GetListOfBranches();
2436 for (
id=0;
id<branches->GetEntries();
id++) {
2437 branch = (TBranch *)branches->At(
id);
2438 if (branch->TestBit(kDoNotProcess))
continue;
2439 TString name = branch->GetName();
2440 if (name.Contains(
"fBits") || name.Contains(
"fUniqueID"))
continue;
2442 MapBranch(branch, fr->GetName(), parent, listIt);
2443 fStopMapping = kFALSE;
2457 void TTreeViewer::MapBranch(TBranch *branch,
const char *prefix, TGListTreeItem *parent, Bool_t listIt)
2459 if (!branch)
return;
2461 if (prefix && strlen(prefix) > 0) {
2463 if (!name.EndsWith(
".")) name +=
".";
2464 name += branch->GetName();
2466 else name = branch->GetName();
2468 TGListTreeItem *branchItem = 0;
2471 if (name.Contains(
"fBits") || name.Contains(
"fUniqueID"))
return;
2474 const TGPicture *pic, *spic;
2475 if ((branch->GetListOfBranches()->GetEntries()) ||
2476 (branch->GetNleaves())) {
2477 if (branch->GetListOfBranches()->GetEntries()) {
2478 itemType =
new ULong_t(kLTBranchType);
2479 if (branch->InheritsFrom(
"TBranchObject")) {
2480 pic = gClient->GetPicture(
"branch-ob_t.xpm");
2481 spic = gClient->GetPicture(
"branch-ob_t.xpm");
2483 if (branch->InheritsFrom(
"TBranchClones")) {
2484 pic = gClient->GetPicture(
"branch-cl_t.xpm");
2485 spic = gClient->GetPicture(
"branch-cl_t.xpm");
2487 pic = gClient->GetPicture(
"branch_t.xpm");
2488 spic = gClient->GetPicture(
"branch_t.xpm");
2491 branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType, pic, spic);
2493 if (branch->GetNleaves() > 1) {
2494 itemType =
new ULong_t(kLTBranchType);
2495 pic = gClient->GetPicture(
"branch_t.xpm");
2496 spic = gClient->GetPicture(
"branch_t.xpm");
2497 branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType,pic, spic);
2498 TObjArray *leaves = branch->GetListOfLeaves();
2501 for (Int_t lf=0; lf<leaves->GetEntries(); lf++) {
2502 leaf = (TLeaf *)leaves->At(lf);
2504 if (!leafName.EndsWith(
".")) leafName.Append(
".");
2505 leafName.Append(EmptyBrackets(leaf->GetName()));
2506 itemType =
new ULong_t(kLTLeafType);
2507 pic = gClient->GetPicture(
"leaf_t.xpm");
2508 spic = gClient->GetPicture(
"leaf_t.xpm");
2509 fLt->AddItem(branchItem, leafName.Data(), itemType, pic, spic);
2512 itemType =
new ULong_t(kLTLeafType);
2513 pic = gClient->GetPicture(
"leaf_t.xpm");
2514 spic = gClient->GetPicture(
"leaf_t.xpm");
2515 branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType, pic, spic);
2522 TGString *textEntry = 0;
2523 const TGPicture *pic, *spic;
2526 if (!fStopMapping) {
2527 fMappedBranch = branch;
2529 fStopMapping = kTRUE;
2531 if ((branch->GetListOfBranches()->GetEntries()) ||
2532 (branch->GetNleaves())) {
2533 textEntry =
new TGString(EmptyBrackets(name.Data()));
2534 if (branch->GetListOfBranches()->GetEntries()) {
2535 if (branch->InheritsFrom(
"TBranchObject")) {
2536 pic = gClient->GetPicture(
"branch-ob_t.xpm");
2537 spic = gClient->GetPicture(
"branch-ob_t.xpm");
2539 if (branch->InheritsFrom(
"TBranchClones")) {
2540 pic = gClient->GetPicture(
"branch-cl_t.xpm");
2541 spic = gClient->GetPicture(
"branch-cl_t.xpm");
2543 pic = gClient->GetPicture(
"branch_t.xpm");
2544 spic = gClient->GetPicture(
"branch_t.xpm");
2547 entry =
new TTVLVEntry(fLVContainer,pic,spic,textEntry,0,kLVSmallIcons);
2548 entry->SetUserData(
new UInt_t(kLTBranchType));
2549 entry->SetToolTipText(
"Branch with sub-branches. Can not be dragged");
2550 fLVContainer->AddThisItem(entry);
2552 entry->SetAlias(textEntry->GetString());
2554 if (branch->GetNleaves() > 1) {
2555 if (textEntry)
delete textEntry;
2556 textEntry =
new TGString(EmptyBrackets(name.Data()));
2557 pic = gClient->GetPicture(
"branch_t.xpm");
2558 spic = gClient->GetPicture(
"branch_t.xpm");
2559 entry =
new TTVLVEntry(fLVContainer, pic, spic, textEntry,0,kLVSmallIcons);
2560 entry->SetUserData(
new UInt_t(kLTBranchType));
2561 entry->SetToolTipText(
"Branch with more than one leaf. Can not be dragged");
2562 fLVContainer->AddThisItem(entry);
2564 entry->SetAlias(textEntry->GetString());
2566 TObjArray *leaves = branch->GetListOfLeaves();
2569 for (Int_t lf=0; lf<leaves->GetEntries(); lf++) {
2570 leaf = (TLeaf *)leaves->At(lf);
2572 if (!leafName.EndsWith(
".")) leafName.Append(
".");
2573 leafName.Append(EmptyBrackets(leaf->GetName()));
2574 textEntry =
new TGString(leafName.Data());
2575 pic = gClient->GetPicture(
"leaf_t.xpm");
2576 spic = gClient->GetPicture(
"leaf_t.xpm");
2577 entry =
new TTVLVEntry(fLVContainer, pic, spic, textEntry,0,kLVSmallIcons);
2578 entry->SetUserData(
new UInt_t(kLTDragType | kLTLeafType));
2579 entry->SetToolTipText(
"Double-click to draw. Drag to X, Y, Z or scan box.");
2580 fLVContainer->AddThisItem(entry);
2582 entry->SetAlias(textEntry->GetString());
2585 pic = (gClient->GetMimeTypeList())->GetIcon(
"TLeaf",kFALSE);
2586 if (!pic) pic = gClient->GetPicture(
"leaf_t.xpm");
2587 spic = gClient->GetMimeTypeList()->GetIcon(
"TLeaf",kTRUE);
2588 if (!spic) spic = gClient->GetPicture(
"leaf_t.xpm");
2589 entry =
new TTVLVEntry(fLVContainer,pic,spic,textEntry,0,kLVSmallIcons);
2590 entry->SetUserData(
new UInt_t(kLTDragType | kLTLeafType));
2591 entry->SetToolTipText(
"Double-click to draw. Drag to X, Y, Z or scan box.");
2592 fLVContainer->AddThisItem(entry);
2594 entry->SetAlias(textEntry->GetString());
2600 TObjArray *branches = branch->GetListOfBranches();
2601 TBranch *branchDaughter = 0;
2604 for (ind=0; ind<branches->GetEntries(); ind++) {
2605 branchDaughter = (TBranch *)branches->UncheckedAt(ind);
2607 MapBranch(branchDaughter,
"", branchItem, listIt);
2614 void TTreeViewer::NewExpression()
2616 fLVContainer->RemoveNonStatic();
2617 const TGPicture *pic = gClient->GetPicture(
"expression_t.xpm");
2618 const TGPicture *spic = gClient->GetPicture(
"expression_t.xpm");
2620 TTVLVEntry *entry =
new TTVLVEntry(fLVContainer,pic,spic,
2621 new TGString(),0,kLVSmallIcons);
2622 entry->SetUserData(
new ULong_t(kLTExpressionType | kLTDragType));
2623 fLVContainer->AddThisItem(entry);
2626 if (fMappedTree) MapTree(fTree);
2627 if (fMappedBranch) MapBranch(fMappedBranch);
2628 fListView->Layout();
2635 void TTreeViewer::SetParentTree(TGListTreeItem *item)
2638 ULong_t *itemType = (ULong_t *)item->GetUserData();
2639 if (!itemType)
return;
2640 TGListTreeItem *parent = 0;
2642 if (!(*itemType & kLTTreeType)) {
2643 parent = item->GetParent();
2644 SetParentTree(parent);
2646 index = (Int_t)(*itemType >> 8);
2654 void TTreeViewer::Message(
const char* msg)
2656 fStatusBar->SetText(msg);
2662 void TTreeViewer::DoError(
int level,
const char *location,
const char *fmt, va_list va)
const
2664 TObject::DoError(level, location, fmt, va);
2668 static const int buf_size = 2048;
2669 char buf[buf_size], *bp;
2671 int n = vsnprintf(buf, buf_size, fmt, va);
2674 if (n == -1 || n >= buf_size) {
2675 TObject::Warning(
"DoError",
"Error message string truncated...");
2677 if (level >= kSysError && level < kFatal)
2678 bp = Form(
"%s (%s)", buf, gSystem->GetError());
2682 const char *title =
"";
2685 if (level == kWarning)
2687 if (level == kError)
2689 if (level == kSysError)
2690 title =
"System Error";
2692 new TGMsgBox(fClient->GetRoot(),
this, title, bp, kMBIconExclamation);
2698 void TTreeViewer::PrintEntries()
2701 char * msg =
new char[100];
2702 snprintf(msg,100,
"First entry : %lld Last entry : %lld",
2703 (Long64_t)fSlider->GetMinPosition(), (Long64_t)fSlider->GetMaxPosition());
2711 void TTreeViewer::SaveSource(
const char* filename, Option_t *)
2716 Int_t lenfile = strlen(filename);
2719 fname = (
char*)fSourceFile;
2720 lenfile = strlen(fname);
2722 fname = (
char*)filename;
2723 fSourceFile = filename;
2728 out.open(fname, std::ios::out);
2730 fname =
new char[13];
2731 strlcpy(fname,
"treeviewer.C",13);
2732 out.open(fname, std::ios::out);
2735 printf(
"SaveSource cannot open file : %s\n", fname);
2736 fSourceFile =
"treeviewer.C";
2737 if (!lenfile)
delete [] fname;
2742 TString sname(fname);
2743 sname = sname.ReplaceAll(
".C",
"");
2744 out <<
"void open_session(void *p = 0);"<<std::endl<<std::endl;
2745 out <<
"void "<<sname.Data()<<
"() {"<<std::endl;
2746 out <<
"//=========Macro generated by ROOT version"<<gROOT->GetVersion()<<std::endl;
2747 out <<
"//=========for tree "<<quote<<fTree->GetName()<<quote<<
" ("<<t.AsString()<<
")"<<std::endl;
2748 out <<
"//===This macro can be opened from a TreeViewer session after loading"<<std::endl;
2749 out <<
"//===the corresponding tree, or by running root with the macro name argument"<<std::endl<<std::endl;
2750 out <<
" open_session();"<<std::endl;
2751 out <<
"}"<<std::endl<<std::endl;
2752 out <<
"void open_session(void *p = 0) {"<<std::endl;
2753 out <<
" gSystem->Load("<<quote<<
"libTreeViewer"<<quote<<
");"<<std::endl;
2754 out <<
" TTreeViewer *treeview = (TTreeViewer *) p;"<<std::endl;
2755 out <<
" if (!treeview) treeview = new TTreeViewer();"<<std::endl;
2756 out <<
" TTree *tv_tree = (TTree*)gROOT->FindObject("<<quote<<fTree->GetName()<<quote<<
");"<<std::endl;
2757 out <<
" TFile *tv_file = (TFile*)gROOT->GetListOfFiles()->FindObject("<<quote<<fFilename<<quote<<
");"<<std::endl;
2758 out <<
" if (!tv_tree) {"<<std::endl;
2759 out <<
" if (!tv_file) tv_file = new TFile("<<quote<<fFilename<<quote<<
");"<<std::endl;
2760 out <<
" if (tv_file) tv_tree = (TTree*)tv_file->Get("<<quote<<fTree->GetName()<<quote<<
");"<<std::endl;
2761 out <<
" if(!tv_tree) {"<<std::endl;
2762 out <<
" printf(\"Tree %s not found\", "<<quote<<fTree->GetName()<<quote<<
");"<<std::endl;
2763 out <<
" return;"<<std::endl;
2764 out <<
" }"<<std::endl;
2765 out <<
" }"<<std::endl<<std::endl;
2766 out <<
" treeview->SetTreeName("<<quote<<fTree->GetName()<<quote<<
");"<<std::endl;
2767 out <<
" treeview->SetNexpressions("<<fNexpressions<<
");"<<std::endl;
2770 out <<
"// Set expressions on axis and cut"<<std::endl;
2771 out <<
" TTVLVEntry *item;"<<std::endl;
2772 for (Int_t i=0; i<4; i++) {
2775 out <<
"// X expression"<<std::endl;
2778 out <<
"// Y expression"<<std::endl;
2781 out <<
"// Z expression"<<std::endl;
2784 out <<
"// Cut expression"<<std::endl;
2789 item = ExpressionItem(i);
2790 out <<
" item = treeview->ExpressionItem("<<i<<
");"<<std::endl;
2791 out <<
" item->SetExpression("<<quote<<item->GetTrueName()<<quote
2792 <<
", "<<quote<<item->GetAlias()<<quote<<
");"<<std::endl;
2794 out <<
"// Scan list"<<std::endl;
2795 item = ExpressionItem(4);
2796 out <<
" item = treeview->ExpressionItem(4);"<<std::endl;
2797 out <<
" item->SetExpression("<<quote<<item->GetTrueName()<<quote
2798 <<
", "<<quote<<
"Scan box"<<quote<<
");"<<std::endl;
2799 out <<
"// User defined expressions"<<std::endl;
2801 for (Int_t crt=5; crt<fNexpressions+5; crt++) {
2802 item = ExpressionItem(crt);
2806 itemType =
"kFALSE";
2807 out <<
" item = treeview->ExpressionItem("<<crt<<
");"<<std::endl;
2808 out <<
" item->SetExpression("<<quote<<item->GetTrueName()<<quote
2809 <<
", "<<quote<<item->GetAlias()<<quote<<
", "<<itemType.Data()<<
");"<<std::endl;
2811 fSession->SaveSource(out);
2812 out <<
"}"<<std::endl;
2814 printf(
"C++ Macro file: %s has been generated\n", fname);
2815 if (!lenfile)
delete [] fname;
2821 Bool_t TTreeViewer::SwitchTree(Int_t index)
2823 TTree *tree = (TTree *) fTreeList->At(index);
2825 Warning(
"SwitchTree",
"No tree found.");
2828 if ((tree == fTree) && (tree == fMappedTree))
return kFALSE;
2829 std::string command;
2830 if (tree != fTree) {
2831 command =
"tv__tree = (TTree *) tv__tree_list->At";
2832 command += Form(
"(%i)",index);
2833 ExecuteCommand(command.c_str());
2837 fSlider->SetRange(0,fTree->GetEntries()-1);
2838 fSlider->SetPosition(0,fTree->GetEntries()-1);
2839 command =
"Current Tree : ";
2840 command += fTree->GetName();
2841 fLbl2->SetText(
new TGString(command.c_str()));
2844 Resize(GetDefaultSize());
2854 void TTreeViewer::SetRecordName(
const char *name)
2856 fSession->SetRecordName(name);
2862 void TTreeViewer::SetCurrentRecord(Long64_t entry)
2864 fCombo->Select(entry);
2870 void TTreeViewer::SetHistogramTitle(
const char *title)
2873 TH1 *hist = (TH1*)gPad->GetListOfPrimitives()->FindObject(fBarHist->GetText());
2875 hist->SetTitle(title);
2883 void TTreeViewer::SetUserCode(
const char *code, Bool_t autoexec)
2885 TTVRecord *rec = fSession->GetCurrent();
2886 if (rec) rec->SetUserCode(code, autoexec);
2892 void TTreeViewer::UpdateCombo()
2895 fCombo->RemoveEntries(0, 1000);
2896 for (Long64_t entry=0; entry<fSession->GetEntries(); entry++) {
2897 if ((record = fSession->GetRecord(entry)))
2898 fCombo->AddEntry(record->GetName(), entry);
2905 void TTreeViewer::UpdateRecord(
const char *name)
2907 fSession->UpdateRecord(name);
2913 void TTreeViewer::DoRefresh()
2916 Float_t min = fSlider->GetMinPosition();
2917 Float_t max = (Float_t)fTree->GetEntries()-1;
2918 fSlider->SetRange(min,max);
2919 fSlider->SetPosition(min,max);