00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 #include "RConfigure.h"
00164
00165 #include "Riostream.h"
00166 #include "TTreeViewer.h"
00167 #include "HelpText.h"
00168 #include "HelpTextTV.h"
00169 #include "TTVLVContainer.h"
00170 #include "TTVSession.h"
00171
00172 #include "TROOT.h"
00173 #include "TError.h"
00174 #include "TGMsgBox.h"
00175 #include "TTreePlayer.h"
00176 #include "TContextMenu.h"
00177 #include "TInterpreter.h"
00178 #include "TLeaf.h"
00179 #include "TRootHelpDialog.h"
00180 #include "TSystem.h"
00181 #include "TApplication.h"
00182 #include "TVirtualX.h"
00183 #include "TGClient.h"
00184 #include "TKey.h"
00185 #include "TFile.h"
00186 #include "TGMenu.h"
00187 #include "TGFrame.h"
00188 #include "TCanvas.h"
00189 #include "TH1.h"
00190 #include "TTree.h"
00191 #include "TFriendElement.h"
00192 #include "TObjArray.h"
00193 #include "TObjString.h"
00194 #include "TGButton.h"
00195 #include "TGButtonGroup.h"
00196 #include "TGTextEntry.h"
00197 #include "TGComboBox.h"
00198 #include "TGLabel.h"
00199 #include "TGListView.h"
00200 #include "TGListTree.h"
00201 #include "TGMimeTypes.h"
00202 #include "TGSplitter.h"
00203 #include "TGDoubleSlider.h"
00204 #include "TGToolBar.h"
00205 #include "TGStatusBar.h"
00206 #include "Getline.h"
00207 #include "TTimer.h"
00208 #include "TG3DLine.h"
00209 #include "TGFileDialog.h"
00210 #include "TGProgressBar.h"
00211 #include "TClonesArray.h"
00212 #include "TSpider.h"
00213
00214 #ifdef WIN32
00215 #include "TWin32SplashThread.h"
00216 #endif
00217
00218
00219 static const char* gOptgen[16] =
00220 {
00221 "","AXIS","HIST","SAME","CYL","POL","SPH","PSR","LEGO","LEGO1","LEGO2",
00222 "SURF","SURF1","SURF2","SURF3","SURF4"
00223 };
00224 static const char* gOpt1D[12] =
00225 {
00226 "","AH","B","C","E","E1","E2","E3","E4","L","P","*H"
00227 };
00228 static const char* gOpt2D[14] =
00229 {
00230 "","ARR","BOX","COL","COL2","CONT","CONT0","CONT1","CONT2","CONT3",
00231 "FB","BB","SCAT","PROF"
00232 };
00233
00234 static const char* gOpenTypes[] = {"Root files", "*.root",
00235 0, 0 };
00236
00237 static const char* gMacroTypes[] = {"C++ macros", "*.C",
00238 0, 0 };
00239
00240
00241 enum ERootTreeViewerCommands {
00242 kFileCanvas,
00243 kFileBrowse,
00244 kFileLoadLibrary = 3,
00245 kFileOpenSession,
00246 kFileSaveMacro,
00247 kFilePrint,
00248 kFileClose,
00249 kFileQuit,
00250
00251 kEditExpression,
00252 kEditCut,
00253 kEditMacro,
00254 kEditEvent,
00255
00256 kRunCommand,
00257 kRunMacro,
00258
00259 kOptionsReset,
00260 kOptionsGeneral = 20,
00261 kOptions1D = 50,
00262 kOptions2D = 70,
00263
00264 kHelpAbout = 100,
00265 kHelpAboutTV,
00266 kHelpStart,
00267 kHelpLayout,
00268 kHelpOpenSave,
00269 kHelpDragging,
00270 kHelpEditing,
00271 kHelpSession,
00272 kHelpCommands,
00273 kHelpContext,
00274 kHelpDrawing,
00275 kHelpMacros,
00276
00277 kBarCommand,
00278 kBarOption,
00279 kBarCut,
00280 kAxis
00281 };
00282
00283
00284 enum EButtonIdentifiers {
00285 kDRAW,
00286 kRESET,
00287 kSTOP,
00288 kCLOSE,
00289 kSLIDER,
00290 kBGFirst,
00291 kBGPrevious,
00292 kBGRecord,
00293 kBGNext,
00294 kBGLast
00295 };
00296
00297 ClassImp(TTreeViewer)
00298
00299
00300 TTreeViewer::TTreeViewer(const char* treeName) :
00301 TGMainFrame(0,10,10,kVerticalFrame),
00302 fDimension(0), fVarDraw(0), fScanMode(0),
00303 fTreeIndex(0), fDefaultCursor(0), fWatchCursor(0),
00304 fCounting(0), fStopMapping(0), fEnableCut(0),fNexpressions(0)
00305 {
00306
00307
00308 fTree = 0;
00309 if (!gClient) return;
00310 char command[128];
00311 snprintf(command,128, "TTreeViewer *gTV = (TTreeViewer*)0x%lx", (ULong_t)this);
00312 gROOT->ProcessLine(command);
00313 gROOT->ProcessLine("TTree *tv__tree = 0;");
00314 fTreeList = new TList;
00315 gROOT->ProcessLine("TList *tv__tree_list = new TList;");
00316 fFilename = "";
00317 gROOT->ProcessLine("TFile *tv__tree_file = 0;");
00318 gInterpreter->SaveContext();
00319 BuildInterface();
00320 SetTreeName(treeName);
00321 }
00322
00323
00324 TTreeViewer::TTreeViewer(const TTree *tree) :
00325 TGMainFrame(0, 10, 10, kVerticalFrame),
00326 fDimension(0), fVarDraw(0), fScanMode(0),
00327 fTreeIndex(0), fDefaultCursor(0), fWatchCursor(0),
00328 fCounting(0), fStopMapping(0), fEnableCut(0),fNexpressions(0)
00329
00330 {
00331
00332
00333 fTree = 0;
00334 char command[128];
00335 snprintf(command,128, "TTreeViewer *gTV = (TTreeViewer*)0x%lx", (ULong_t)this);
00336 gROOT->ProcessLine(command);
00337 if (!tree) return;
00338 gROOT->ProcessLine("TTree *tv__tree = 0;");
00339 fTreeList = new TList;
00340 gROOT->ProcessLine("TList *tv__tree_list = new TList;");
00341 fFilename = "";
00342 gROOT->ProcessLine("TFile *tv__tree_file = 0;");
00343 gInterpreter->SaveContext();
00344 BuildInterface();
00345 TDirectory *dirsav = gDirectory;
00346 TDirectory *cdir = tree->GetDirectory();
00347 if (cdir) cdir->cd();
00348
00349 SetTreeName(tree->GetName());
00350
00351
00352 cdir = tree->GetDirectory();
00353 if (cdir) {
00354 if (cdir->GetFile()) fFilename = cdir->GetFile()->GetName();
00355 }
00356 if (dirsav) dirsav->cd();
00357 }
00358
00359 void TTreeViewer::AppendTree(TTree *tree)
00360 {
00361
00362
00363 if (!tree) return;
00364 TTree *ftree;
00365 if (fTreeList) {
00366 if (fTreeList->FindObject(tree)) {
00367 printf("Tree found\n");
00368 TIter next(fTreeList);
00369 Int_t index = 0;
00370 while ((ftree = (TTree*)next())) {
00371 if (ftree==tree) {printf("found at index %i\n", index);break;}
00372 index++;
00373 }
00374 SwitchTree(index);
00375 if (fTree != fMappedTree) {
00376
00377 fLVContainer->RemoveNonStatic();
00378
00379 MapTree(fTree);
00380 fListView->Layout();
00381 TGListTreeItem *base = 0;
00382 TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00383 TGListTreeItem *item = fLt->FindChildByName(parent, fTree->GetName());
00384 fLt->ClearHighlighted();
00385 fLt->HighlightItem(item);
00386 fClient->NeedRedraw(fLt);
00387 }
00388 return;
00389 }
00390 }
00391 if (fTree != tree) {
00392 fTree = tree;
00393
00394 char command[100];
00395 command[0] = 0;
00396
00397 snprintf(command,100, "tv__tree = (TTree *)0x%lx;", (ULong_t)tree);
00398 ExecuteCommand(command);
00399 }
00400
00401 if (fTreeList) fTreeList->Add(fTree);
00402 ExecuteCommand("tv__tree_list->Add(tv__tree);");
00403
00404 TGListTreeItem *base = 0;
00405 TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00406 if (!parent) parent = fLt->AddItem(base, "TreeList", new ULong_t(kLTNoType));
00407 ULong_t *itemType = new ULong_t((fTreeIndex << 8) | kLTTreeType);
00408 fTreeIndex++;
00409 TGListTreeItem *lTreeItem = fLt->AddItem(parent, tree->GetName(), itemType,
00410 gClient->GetPicture("tree_t.xpm"), gClient->GetPicture("tree_t.xpm"));
00411 MapTree(fTree, lTreeItem, kFALSE);
00412 fLt->OpenItem(parent);
00413 fLt->HighlightItem(lTreeItem);
00414 fClient->NeedRedraw(fLt);
00415
00416
00417 SwitchTree(fTreeIndex-1);
00418 fLVContainer->RemoveNonStatic();
00419 MapTree(fTree);
00420 fListView->Layout();
00421 SetFile();
00422 }
00423
00424 void TTreeViewer::SetNexpressions(Int_t expr)
00425 {
00426
00427
00428 Int_t diff = expr - fNexpressions;
00429 if (diff <= 0) return;
00430 if (!fLVContainer) return;
00431 for (Int_t i=0; i<TMath::Abs(diff); i++) NewExpression();
00432 }
00433
00434 void TTreeViewer::SetScanFileName(const char *name)
00435 {
00436
00437
00438 if (fTree) ((TTreePlayer *)fTree->GetPlayer())->SetScanFileName(name);
00439 }
00440
00441 void TTreeViewer::SetScanRedirect(Bool_t mode)
00442 {
00443
00444
00445 if (mode)
00446 fBarScan->SetState(kButtonDown);
00447 else
00448 fBarScan->SetState(kButtonUp);
00449 }
00450
00451 void TTreeViewer::SetTreeName(const char* treeName)
00452 {
00453
00454
00455 if (!treeName) return;
00456 TTree *tree = (TTree *) gROOT->FindObject(treeName);
00457 if (fTreeList) {
00458 if (fTreeList->FindObject(treeName)) {
00459 printf("Tree found\n");
00460 TIter next(fTreeList);
00461 Int_t index = 0;
00462 while ((tree = (TTree*)next())) {
00463 if (!strcmp(treeName, tree->GetName())) {printf("found at index %i\n", index);break;}
00464 index++;
00465 }
00466 SwitchTree(index);
00467 if (fTree != fMappedTree) {
00468
00469 fLVContainer->RemoveNonStatic();
00470
00471 MapTree(fTree);
00472 fListView->Layout();
00473 TGListTreeItem *base = 0;
00474 TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00475 TGListTreeItem *item = fLt->FindChildByName(parent, fTree->GetName());
00476 fLt->ClearHighlighted();
00477 fLt->HighlightItem(item);
00478 fClient->NeedRedraw(fLt);
00479 }
00480 return;
00481 }
00482 }
00483 if (!tree) return;
00484
00485 if (fTree != tree) {
00486 fTree = tree;
00487
00488
00489 TString command = TString::Format("tv__tree = (TTree *) gROOT->FindObject(\"%s\");", treeName);
00490 ExecuteCommand(command.Data());
00491 }
00492
00493 if (fTreeList) fTreeList->Add(fTree);
00494 ExecuteCommand("tv__tree_list->Add(tv__tree);");
00495
00496 TGListTreeItem *base = 0;
00497 TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00498 if (!parent) parent = fLt->AddItem(base, "TreeList", new ULong_t(kLTNoType));
00499 ULong_t *itemType = new ULong_t((fTreeIndex << 8) | kLTTreeType);
00500 fTreeIndex++;
00501 TGListTreeItem *lTreeItem = fLt->AddItem(parent, treeName, itemType,
00502 gClient->GetPicture("tree_t.xpm"), gClient->GetPicture("tree_t.xpm"));
00503 MapTree(fTree, lTreeItem, kFALSE);
00504 fLt->OpenItem(parent);
00505 fLt->HighlightItem(lTreeItem);
00506 fClient->NeedRedraw(fLt);
00507
00508
00509 SwitchTree(fTreeIndex-1);
00510 fLVContainer->RemoveNonStatic();
00511 MapTree(fTree);
00512 fListView->Layout();
00513 SetFile();
00514 }
00515
00516 void TTreeViewer::SetFile()
00517 {
00518
00519
00520 if (!fTree) return;
00521 TSeqCollection *list = gROOT->GetListOfFiles();
00522 TTree *tree;
00523 TIter next(list);
00524 TObject *obj;
00525 TFile *file;
00526 while ((obj=next())) {
00527 file = (TFile*)obj;
00528 if (file) {
00529 tree = (TTree*)file->Get(fTree->GetName());
00530 if (tree) {
00531 fFilename = file->GetName();
00532 cout << "File name : "<< fFilename << endl;
00533 return;
00534 } else {
00535 fFilename = "";
00536 }
00537 }
00538 }
00539 fFilename = "";
00540 }
00541
00542 void TTreeViewer::BuildInterface()
00543 {
00544
00545
00546
00547 fCounting = kFALSE;
00548 fScanMode = kFALSE;
00549 fEnableCut = kTRUE;
00550 fTimer = new TTimer(this, 20, kTRUE);
00551 fLastOption = "";
00552 fSession = new TTVSession(this);
00553
00554 fDefaultCursor = gVirtualX->CreateCursor(kPointer);
00555 fWatchCursor = gVirtualX->CreateCursor(kWatch);
00556
00557 ULong_t color;
00558 gClient->GetColorByName("blue",color);
00559
00560 fPicX = gClient->GetPicture("x_pic.xpm");
00561 fPicY = gClient->GetPicture("y_pic.xpm");
00562 fPicZ = gClient->GetPicture("z_pic.xpm");
00563
00564
00565 fContextMenu = new TContextMenu("TreeViewer context menu","");
00566 fMappedTree = 0;
00567 fMappedBranch = 0;
00568 fDialogBox = 0;
00569 fDimension = 0;
00570 fVarDraw = kFALSE;
00571 fStopMapping = kFALSE;
00572
00573 fSourceFile = "treeviewer.C";
00574
00575
00576 fTreeIndex = 0;
00577 fWidgets = new TList();
00578
00579
00580 fFileMenu = new TGPopupMenu(fClient->GetRoot());
00581 fFileMenu->AddEntry("&New canvas", kFileCanvas);
00582 fFileMenu->AddEntry("Open &tree file...", kFileBrowse);
00583 fFileMenu->AddEntry("&Load Library...", kFileLoadLibrary);
00584 fFileMenu->AddEntry("&Open session", kFileOpenSession);
00585 fFileMenu->AddEntry("&Save source", kFileSaveMacro);
00586 fFileMenu->AddSeparator();
00587 fFileMenu->AddEntry("&Print", kFilePrint);
00588 fFileMenu->AddEntry("&Close", kFileClose);
00589 fFileMenu->AddSeparator();
00590 fFileMenu->AddEntry("&Quit ROOT", kFileQuit);
00591
00592 fFileMenu->DisableEntry(kFilePrint);
00593
00594
00595 fEditMenu = new TGPopupMenu(gClient->GetRoot());
00596 fEditMenu->AddEntry("&Expression...", kEditExpression);
00597 fEditMenu->AddEntry("&Cut...", kEditCut);
00598 fEditMenu->AddEntry("&Macro...", kEditMacro);
00599 fEditMenu->AddEntry("E&Vent...", kEditEvent);
00600
00601 fEditMenu->DisableEntry(kEditMacro);
00602 fEditMenu->DisableEntry(kEditEvent);
00603
00604 fRunMenu = new TGPopupMenu(gClient->GetRoot());
00605 fRunMenu->AddEntry("&Macro...", kRunMacro);
00606 fRunMenu->DisableEntry(kRunMacro);
00607
00608
00609 fOptionsGen = new TGPopupMenu(gClient->GetRoot());
00610 fOptionsGen->AddEntry("Default", kOptionsGeneral);
00611 fOptionsGen->AddSeparator();
00612 fOptionsGen->AddEntry("Axis only", kOptionsGeneral+1);
00613 fOptionsGen->AddEntry("Contour only", kOptionsGeneral+2);
00614 fOptionsGen->AddEntry("Superimpose", kOptionsGeneral+3);
00615 fOptionsGen->AddEntry("Cylindrical", kOptionsGeneral+4);
00616 fOptionsGen->AddEntry("Polar", kOptionsGeneral+5);
00617 fOptionsGen->AddEntry("Spherical", kOptionsGeneral+6);
00618 fOptionsGen->AddEntry("PsRap/Phi", kOptionsGeneral+7);
00619 fOptionsGen->AddEntry("Lego HLR", kOptionsGeneral+8);
00620 fOptionsGen->AddEntry("Lego HSR", kOptionsGeneral+9);
00621 fOptionsGen->AddEntry("Lego Color", kOptionsGeneral+10);
00622 fOptionsGen->AddEntry("Surface HLR", kOptionsGeneral+11);
00623 fOptionsGen->AddEntry("Surface HSR", kOptionsGeneral+12);
00624 fOptionsGen->AddEntry("Surface Col", kOptionsGeneral+13);
00625 fOptionsGen->AddEntry("Surf+Cont", kOptionsGeneral+14);
00626 fOptionsGen->AddEntry("Gouraud", kOptionsGeneral+15);
00627 fOptionsGen->Associate(this);
00628
00629 fOptions1D = new TGPopupMenu(gClient->GetRoot());
00630 fOptions1D->AddEntry("Default", kOptions1D);
00631 fOptions1D->AddSeparator();
00632 fOptions1D->AddEntry("No labels/ticks", kOptions1D+1);
00633 fOptions1D->AddEntry("Bar chart", kOptions1D+2);
00634 fOptions1D->AddEntry("Smooth curve", kOptions1D+3);
00635 fOptions1D->AddEntry("Errors", kOptions1D+4);
00636 fOptions1D->AddEntry("Errors 1", kOptions1D+5);
00637 fOptions1D->AddEntry("Errors 2", kOptions1D+6);
00638 fOptions1D->AddEntry("Errors 3", kOptions1D+7);
00639 fOptions1D->AddEntry("Errors 4", kOptions1D+8);
00640 fOptions1D->AddEntry("Line", kOptions1D+9);
00641 fOptions1D->AddEntry("Markers", kOptions1D+10);
00642 fOptions1D->AddEntry("Stars", kOptions1D+11);
00643 fOptions1D->Associate(this);
00644
00645 fOptions2D = new TGPopupMenu(gClient->GetRoot());
00646 fOptions2D->AddEntry("Default", kOptions2D);
00647 fOptions2D->AddSeparator();
00648 fOptions2D->AddEntry("Arrows", kOptions2D+1);
00649 fOptions2D->AddEntry("Box/Surf", kOptions2D+2);
00650 fOptions2D->AddEntry("Box/Color", kOptions2D+3);
00651 fOptions2D->AddEntry("Box/ColMap", kOptions2D+4);
00652 fOptions2D->AddEntry("Contour", kOptions2D+5);
00653 fOptions2D->AddEntry("Contour 0", kOptions2D+6);
00654 fOptions2D->AddEntry("Contour 1", kOptions2D+7);
00655 fOptions2D->AddEntry("Contour 2", kOptions2D+8);
00656 fOptions2D->AddEntry("Contour 3", kOptions2D+9);
00657 fOptions2D->AddEntry("No front-box", kOptions2D+10);
00658 fOptions2D->AddEntry("No back-box", kOptions2D+11);
00659 fOptions2D->AddEntry("Scatter", kOptions2D+12);
00660 fOptions2D->AddEntry("Profile", kOptions2D+13);
00661 fOptions2D->Associate(this);
00662
00663 fOptionsMenu = new TGPopupMenu(gClient->GetRoot());
00664 fOptionsMenu->AddPopup("&General Options...", fOptionsGen);
00665 fOptionsMenu->AddPopup("&1D Options", fOptions1D);
00666 fOptionsMenu->AddPopup("&2D Options", fOptions2D);
00667 fOptionsMenu->AddSeparator();
00668 fOptionsMenu->AddEntry("&Reset options", kOptionsReset);
00669
00670 fHelpMenu = new TGPopupMenu(gClient->GetRoot());
00671 fHelpMenu->AddEntry("&About ROOT...", kHelpAbout);
00672 fHelpMenu->AddEntry("&About TreeViewer...", kHelpAboutTV);
00673 fHelpMenu->AddSeparator();
00674 fHelpMenu->AddEntry("&Starting...", kHelpStart);
00675 fHelpMenu->AddEntry("&Layout...", kHelpLayout);
00676 fHelpMenu->AddEntry("&Open/Save", kHelpOpenSave);
00677 fHelpMenu->AddEntry("&Dragging...", kHelpDragging);
00678 fHelpMenu->AddEntry("&Editing expressions...",kHelpEditing);
00679 fHelpMenu->AddEntry("&Session...", kHelpSession);
00680 fHelpMenu->AddEntry("&User commands...", kHelpCommands);
00681 fHelpMenu->AddEntry("&Context menus...", kHelpContext);
00682 fHelpMenu->AddEntry("D&rawing...", kHelpDrawing);
00683 fHelpMenu->AddEntry("&Macros...", kHelpMacros);
00684
00685 fFileMenu->Associate(this);
00686 fEditMenu->Associate(this);
00687 fRunMenu->Associate(this);
00688 fOptionsMenu->Associate(this);
00689 fHelpMenu->Associate(this);
00690
00691
00692 fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0,0,1,1);
00693 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00694 fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00695
00696 fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
00697
00698 fMenuBar->AddPopup("&File", fFileMenu, fMenuBarItemLayout);
00699 fMenuBar->AddPopup("&Edit", fEditMenu, fMenuBarItemLayout);
00700 fMenuBar->AddPopup("&Run", fRunMenu, fMenuBarItemLayout);
00701 fMenuBar->AddPopup("&Options", fOptionsMenu, fMenuBarItemLayout);
00702 fMenuBar->AddPopup("&Help", fHelpMenu, fMenuBarHelpLayout);
00703
00704 AddFrame(fMenuBar, fMenuBarLayout);
00705
00706 fToolBar = new TGToolBar(this, 10, 10, kHorizontalFrame);
00707 fBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
00708
00709 TGLayoutHints *lo;
00710 lo = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
00711 fWidgets->Add(lo);
00712
00713 fBarLbl1 = new TGLabel(fToolBar,"Command");
00714 fToolBar->AddFrame(fBarLbl1,lo);
00715
00716 fBarCommand = new TGTextEntry(fToolBar, new TGTextBuffer(250),kBarCommand);
00717 fBarCommand->SetWidth(120);
00718 fBarCommand->Associate(this);
00719 fBarCommand->SetToolTipText("User commands executed via interpreter. Type <ENTER> to execute");
00720 fToolBar->AddFrame(fBarCommand, lo);
00721
00722 TGVertical3DLine *vSeparator = new TGVertical3DLine(fToolBar);
00723 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 4,4,0,0);
00724 fWidgets->Add(lo);
00725 fWidgets->Add(vSeparator);
00726 fToolBar->AddFrame(vSeparator, lo);
00727
00728 lo = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
00729 fWidgets->Add(lo);
00730
00731 fBarLbl2 = new TGLabel(fToolBar,"Option");
00732 fToolBar->AddFrame(fBarLbl2, lo);
00733
00734 fBarOption = new TGTextEntry(fToolBar, new TGTextBuffer(200),kBarOption);
00735 fBarOption->SetWidth(100);
00736 fBarOption->Associate(this);
00737 fBarOption->SetToolTipText("Histogram graphics option. Type option here and click <Draw> (or <ENTER> to update current histogram).");
00738 fToolBar->AddFrame(fBarOption, lo);
00739
00740 vSeparator = new TGVertical3DLine(fToolBar);
00741 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 4,4,0,0);
00742 fWidgets->Add(lo);
00743 fWidgets->Add(vSeparator);
00744 fToolBar->AddFrame(vSeparator, lo);
00745
00746 lo = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
00747 fWidgets->Add(lo);
00748
00749 fBarLbl3 = new TGLabel(fToolBar,"Histogram");
00750 fToolBar->AddFrame(fBarLbl3, lo);
00751
00752 fBarHist = new TGTextEntry(fToolBar, new TGTextBuffer(100));
00753 fBarHist->SetWidth(50);
00754 fBarHist->SetText("htemp");
00755 fBarHist->SetToolTipText("Name of the histogram created by <Draw> command.");
00756 fToolBar->AddFrame(fBarHist, lo);
00757
00758 fBarH = new TGCheckButton(fToolBar, "Hist");
00759 fBarH->SetToolTipText("Checked : redraw only current histogram");
00760 fBarH->SetState(kButtonUp);
00761 fToolBar->AddFrame(fBarH, lo);
00762
00763 fBarScan = new TGCheckButton(fToolBar, "Scan");
00764 fBarScan->SetState(kButtonUp);
00765 fBarScan->SetToolTipText("Check to redirect TTree::Scan command in a file");
00766 fToolBar->AddFrame(fBarScan, lo);
00767
00768 fBarRec = new TGCheckButton(fToolBar, "Rec");
00769 fBarRec->SetState(kButtonDown);
00770 fBarRec->SetToolTipText("Check to record commands in history file and be verbose");
00771 fToolBar->AddFrame(fBarRec, lo);
00772
00773 TGHorizontal3DLine *toolBarSep = new TGHorizontal3DLine(this);
00774 fWidgets->Add(toolBarSep);
00775 AddFrame(toolBarSep, fBarLayout);
00776 AddFrame(fToolBar, fBarLayout);
00777
00778 toolBarSep = new TGHorizontal3DLine(this);
00779 fWidgets->Add(toolBarSep);
00780 AddFrame(toolBarSep, fBarLayout);
00781
00782
00783 fHf = new TGHorizontalFrame(this, 10, 10);
00784
00785 fSlider = new TGDoubleVSlider(fHf, 10, kDoubleScaleBoth, kSLIDER);
00786
00787 fSlider->Associate(this);
00788
00789
00790 fV1 = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
00791 fTreeHdr = new TGCompositeFrame(fV1, 10, 10, kSunkenFrame | kVerticalFrame);
00792
00793 fLbl1 = new TGLabel(fTreeHdr, "Current Folder");
00794 lo = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY, 3, 0, 0, 0);
00795 fWidgets->Add(lo);
00796 fTreeHdr->AddFrame(fLbl1, lo);
00797
00798 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 1, 0);
00799 fWidgets->Add(lo);
00800 fV1->AddFrame(fTreeHdr, lo);
00801
00802
00803 fTreeView = new TGCanvas(fV1, fV1->GetWidth(), 10, kSunkenFrame | kDoubleBorder);
00804
00805 fLt = new TGListTree(fTreeView->GetViewPort(), 10, 10, kHorizontalFrame,
00806 GetWhitePixel());
00807 fLt->Associate(this);
00808 fTreeView->SetContainer(fLt);
00809
00810 lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2,0,0,0);
00811 fWidgets->Add(lo);
00812 fV1->AddFrame(fTreeView, lo);
00813
00814
00815 fHpb = new TGHorizontalFrame(fV1, fTreeHdr->GetWidth(), 10, kSunkenFrame);
00816
00817
00818 fPicDraw = gClient->GetPicture("draw_t.xpm");
00819 fDRAW = new TGPictureButton(fHpb,fPicDraw,kDRAW);
00820 fDRAW->SetToolTipText("Draw current selection");
00821 fDRAW->Associate(this);
00822
00823 lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00824 fWidgets->Add(lo);
00825 fHpb->AddFrame(fDRAW, lo);
00826
00827
00828 fSPIDER = new TGTextButton(fHpb,"SPIDER");
00829 fSPIDER->SetToolTipText("Scan current selection using a spider plot");
00830 fSPIDER->Associate(this);
00831
00832 lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00833 fWidgets->Add(lo);
00834 fHpb->AddFrame(fSPIDER,lo);
00835
00836 fSPIDER->Connect("Clicked()","TTreeViewer",this,"ExecuteSpider()");
00837
00838
00839
00840 fPicStop = gClient->GetPicture("stop_t.xpm");
00841 fSTOP = new TGPictureButton(fHpb,fPicStop,kSTOP);
00842 fSTOP->SetToolTipText("Abort current operation");
00843 fSTOP->Associate(this);
00844
00845 lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00846 fWidgets->Add(lo);
00847 fHpb->AddFrame(fSTOP, lo);
00848
00849
00850 fPicRefr = gClient->GetPicture("refresh2.xpm");
00851 fREFR = new TGPictureButton(fHpb,fPicRefr,kDRAW);
00852 fREFR->SetToolTipText("Update the tree viewer");
00853 lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00854 fWidgets->Add(lo);
00855 fHpb->AddFrame(fREFR, lo);
00856
00857 fREFR->Connect("Clicked()", "TTreeViewer", this, "DoRefresh()");
00858
00859 lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,2,2);
00860 fWidgets->Add(lo);
00861 fV1->AddFrame(fHpb, lo);
00862
00863
00864 fV2 = new TGVerticalFrame(fHf, 10, 10);
00865 fListHdr = new TGCompositeFrame(fV2, 10, 10, kSunkenFrame | kFitHeight);
00866 fLbl2 = new TGLabel(fListHdr, "Current Tree: ");
00867 lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 0, 0, 0);
00868 fWidgets->Add(lo);
00869 fListHdr->AddFrame(fLbl2, lo);
00870
00871
00872 fProgressBar = new TGHProgressBar(fListHdr);
00873 fProgressBar->SetBarColor("red");
00874 fProgressBar->SetFillType(TGProgressBar::kBlockFill);
00875 lo = new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 2,2,4,2);
00876 fWidgets->Add(lo);
00877 fListHdr->AddFrame(fProgressBar, lo);
00878 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 2,0,1,2);
00879 fWidgets->Add(lo);
00880 fV2->AddFrame(fListHdr, lo);
00881
00882 fV1->Resize(fTreeHdr->GetDefaultWidth()+100, fV1->GetDefaultHeight());
00883 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00884 fWidgets->Add(lo);
00885 fHf->AddFrame(fSlider, lo);
00886 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00887 fWidgets->Add(lo);
00888 fHf->AddFrame(fV1, lo);
00889
00890
00891 TGVSplitter *splitter = new TGVSplitter(fHf);
00892 splitter->SetFrame(fV1,kTRUE);
00893 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00894 fWidgets->Add(splitter);
00895 fWidgets->Add(lo);
00896 fHf->AddFrame(splitter,lo);
00897
00898
00899
00900
00901 fListView = new TGListView(fListHdr,400,300);
00902
00903 fLVContainer = new TTVLVContainer(fListView->GetViewPort(),400,300);
00904 fLVContainer->Associate(this);
00905 fLVContainer->SetListView(fListView);
00906 fLVContainer->SetViewer(this);
00907 fLVContainer->SetBackgroundColor(GetWhitePixel());
00908 fListView->GetViewPort()->SetBackgroundColor(GetWhitePixel());
00909 fListView->SetContainer(fLVContainer);
00910 fListView->SetViewMode(kLVList);
00911 lo = new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX | kLHintsExpandY);
00912 fWidgets->Add(lo);
00913
00914 fListHdr->AddFrame(fListView,lo);
00915
00916 lo = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY);
00917 fWidgets->Add(lo);
00918 fHf->AddFrame(fV2,lo);
00919
00920 AddFrame(fHf, lo);
00921
00922 toolBarSep = new TGHorizontal3DLine(this);
00923 fWidgets->Add(toolBarSep);
00924 AddFrame(toolBarSep, fBarLayout);
00925
00926
00927 fBFrame = new TGHorizontalFrame(this,10,10);
00928 fBLbl4 = new TGLabel(fBFrame,"IList");
00929 lo = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 2,2,2,2);
00930 fWidgets->Add(lo);
00931 fBFrame->AddFrame(fBLbl4, lo);
00932
00933 fBarListIn = new TGTextEntry(fBFrame, new TGTextBuffer(100));
00934 fBarListIn->SetWidth(60);
00935 fBarListIn->SetToolTipText("Name of a previously created event list");
00936 fBFrame->AddFrame(fBarListIn, lo);
00937
00938 fBLbl5 = new TGLabel(fBFrame,"OList");
00939 fBFrame->AddFrame(fBLbl5, lo);
00940
00941 fBarListOut = new TGTextEntry(fBFrame, new TGTextBuffer(100));
00942 fBarListOut->SetWidth(60);
00943 fBarListOut->SetToolTipText("Output event list. Use <Draw> to generate it.");
00944 fBFrame->AddFrame(fBarListOut, lo);
00945
00946 fStatusBar = new TGStatusBar(fBFrame, 10, 10);
00947 fStatusBar->SetWidth(200);
00948 fStatusBar->Draw3DCorner(kFALSE);
00949 lo = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsLeft | kLHintsExpandX, 2,2,2,2);
00950 fWidgets->Add(lo);
00951 fBFrame->AddFrame(fStatusBar, lo);
00952
00953 fReset = new TGTextButton(fBFrame,"RESET",kRESET);
00954 fReset->SetToolTipText("Reset variable's fields and drawing options");
00955 fReset->Associate(this);
00956 lo = new TGLayoutHints(kLHintsTop | kLHintsRight, 2,2,2,2);
00957 fWidgets->Add(lo);
00958 fBFrame->AddFrame(fReset,lo);
00959
00960 fBGFirst = new TGPictureButton(fBFrame,
00961 gClient->GetPicture("first_t.xpm"), kBGFirst);
00962 fBGFirst->SetToolTipText("First record");
00963 fBGFirst->Associate(this);
00964 fBGPrevious = new TGPictureButton(fBFrame,
00965 gClient->GetPicture("previous_t.xpm"), kBGPrevious);
00966 fBGPrevious->SetToolTipText("Previous record");
00967 fBGPrevious->Associate(this);
00968 fBGRecord = new TGPictureButton(fBFrame,
00969 gClient->GetPicture("record_t.xpm"), kBGRecord);
00970 fBGRecord->SetToolTipText("Record");
00971 fBGRecord->Associate(this);
00972 fBGNext = new TGPictureButton(fBFrame,
00973 gClient->GetPicture("next_t.xpm"), kBGNext);
00974 fBGNext->SetToolTipText("Next record");
00975 fBGNext->Associate(this);
00976 fBGLast = new TGPictureButton(fBFrame,
00977 gClient->GetPicture("last_t.xpm"), kBGLast);
00978 fBGLast->SetToolTipText("Last record");
00979 fBGLast->Associate(this);
00980
00981 fCombo = new TGComboBox(fBFrame, 0);
00982 fCombo->SetHeight(fReset->GetDefaultHeight());
00983 fCombo->SetWidth(100);
00984 fCombo->Associate(this);
00985
00986 lo = new TGLayoutHints(kLHintsCenterY | kLHintsRight, 0,0,2,0);
00987 fWidgets->Add(lo);
00988 fBFrame->AddFrame(fCombo, lo);
00989 fBFrame->AddFrame(fBGLast, lo);
00990 fBFrame->AddFrame(fBGNext, lo);
00991 fBFrame->AddFrame(fBGRecord, lo);
00992 fBFrame->AddFrame(fBGPrevious, lo);
00993 fBFrame->AddFrame(fBGFirst, lo);
00994 lo = new TGLayoutHints(kLHintsExpandX,2,2,2,0);
00995 fWidgets->Add(lo);
00996 AddFrame(fBFrame,lo);
00997
00998
00999 SetWindowName("TreeViewer");
01000 MapSubwindows();
01001 Resize(GetDefaultSize());
01002 MapWindow();
01003
01004
01005 const TGPicture *pic, *spic;
01006
01007 fLVContainer->RemoveAll();
01008 TTVLVEntry* entry;
01009 Char_t symbol;
01010 entry = new TTVLVEntry(fLVContainer,fPicX,fPicX,new TGString(),0,kLVSmallIcons);
01011 symbol = 'X';
01012 entry->SetUserData(new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
01013 entry->SetToolTipText("X expression. Drag and drop expressions here");
01014
01015 fLVContainer->AddThisItem(entry);
01016 entry->Empty();
01017 entry->MapWindow();
01018
01019 entry = new TTVLVEntry(fLVContainer,fPicY,fPicY,new TGString(),0,kLVSmallIcons);
01020 symbol = 'Y';
01021 entry->SetUserData(new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
01022 entry->SetToolTipText("Y expression. Drag and drop expressions here");
01023
01024 fLVContainer->AddThisItem(entry);
01025 entry->Empty();
01026 entry->MapWindow();
01027
01028 entry = new TTVLVEntry(fLVContainer,fPicZ,fPicZ,new TGString(),0,kLVSmallIcons);
01029 symbol = 'Z';
01030 entry->SetUserData(new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
01031 entry->SetToolTipText("Z expression. Drag and drop expressions here");
01032
01033 fLVContainer->AddThisItem(entry);
01034 entry->Empty();
01035 entry->MapWindow();
01036
01037 pic = gClient->GetPicture("cut_t.xpm");
01038 spic = gClient->GetPicture("cut_t.xpm");
01039 entry = new TTVLVEntry(fLVContainer,pic,spic,new TGString(),0,kLVSmallIcons);
01040 entry->SetUserData(new ULong_t(kLTExpressionType | kLTCutType));
01041 entry->SetToolTipText("Active cut. Double-click to enable/disable");
01042
01043 fLVContainer->AddThisItem(entry);
01044 entry->Empty();
01045 entry->MapWindow();
01046
01047 pic = gClient->GetPicture("pack_t.xpm");
01048 spic = gClient->GetPicture("pack-empty_t.xpm");
01049 entry = new TTVLVEntry(fLVContainer,pic,spic,new TGString("Scan box"),0,kLVSmallIcons);
01050 entry->SetUserData(new ULong_t(kLTExpressionType | kLTPackType));
01051 entry->SetToolTipText("Drag and drop expressions/leaves here. Double-click to scan. Check <Scan> to redirect on file.");
01052
01053 fLVContainer->AddThisItem(entry);
01054 entry->MapWindow();
01055 entry->SetTrueName("");
01056
01057
01058 fNexpressions = 10;
01059 for (Int_t i=0; i<fNexpressions; i++) {
01060 pic = gClient->GetPicture("expression_t.xpm");
01061 spic = gClient->GetPicture("expression_t.xpm");
01062 entry = new TTVLVEntry(fLVContainer,pic,spic,new TGString(),0,kLVSmallIcons);
01063 entry->SetUserData(new ULong_t(kLTExpressionType | kLTDragType));
01064 entry->SetToolTipText("User defined expression/cut. Double-click to edit");
01065 fLVContainer->AddThisItem(entry);
01066 entry->Empty();
01067 entry->MapWindow();
01068 }
01069
01070 fListView->Layout();
01071 fListView->Resize();
01072
01073
01074
01075 if (!fTree) {
01076 fSlider->SetRange(0,1000000);
01077 fSlider->SetPosition(0,1000000);
01078 } else {
01079 fSlider->SetRange(0,fTree->GetEntries()-1);
01080 fSlider->SetPosition(0,fTree->GetEntries()-1);
01081 }
01082 PrintEntries();
01083 fProgressBar->SetPosition(0);
01084 fProgressBar->ShowPosition();
01085 ActivateButtons(kFALSE, kFALSE, kFALSE, kFALSE);
01086
01087
01088
01089 MapSubwindows();
01090 Resize(GetDefaultSize());
01091 MapWindow();
01092 }
01093
01094
01095 TTreeViewer::~TTreeViewer()
01096 {
01097
01098
01099 if (!gClient) return;
01100 gClient->FreePicture(fPicX);
01101 gClient->FreePicture(fPicY);
01102 gClient->FreePicture(fPicZ);
01103 gClient->FreePicture(fPicDraw);
01104 gClient->FreePicture(fPicStop);
01105 gClient->FreePicture(fPicRefr);
01106
01107 fDialogBox = TGSelectBox::GetInstance();
01108 if (fDialogBox) delete fDialogBox;
01109
01110 delete fContextMenu;
01111
01112 delete fBarLbl1;
01113 delete fBarLbl2;
01114 delete fBarLbl3;
01115 delete fBLbl4;
01116 delete fBLbl5;
01117 delete fBarCommand;
01118 delete fBarOption;
01119 delete fBarHist;
01120 delete fBarListIn;
01121 delete fBarListOut;
01122
01123 delete fBarH;
01124 delete fBarScan;
01125 delete fBarRec;
01126
01127 delete fToolBar;
01128
01129 delete fSlider;
01130 delete fV1;
01131 delete fV2;
01132 delete fLbl1;
01133 delete fLbl2;
01134 delete fHf;
01135 delete fTreeHdr;
01136 delete fListHdr;
01137 delete fLt;
01138 delete fTreeView;
01139 delete fLVContainer;
01140 delete fListView;
01141
01142 delete fProgressBar;
01143 delete fHpb;
01144
01145 delete fDRAW;
01146 delete fSPIDER;
01147 delete fSTOP;
01148 delete fReset;
01149 delete fBGFirst;
01150 delete fBGPrevious;
01151 delete fBGRecord;
01152 delete fBGNext;
01153 delete fBGLast;
01154 delete fCombo;
01155 delete fBFrame;
01156
01157 delete fMenuBar;
01158 delete fFileMenu;
01159 delete fEditMenu;
01160
01161 delete fOptionsGen;
01162 delete fOptions1D;
01163 delete fOptions2D;
01164 delete fOptionsMenu;
01165 delete fHelpMenu;
01166 delete fMenuBarLayout;
01167 delete fMenuBarItemLayout;
01168 delete fMenuBarHelpLayout;
01169 delete fBarLayout;
01170
01171 fWidgets->Delete();
01172 delete fWidgets;
01173 if (fTreeList) {
01174 delete fTreeList;
01175 }
01176 delete fTimer;
01177 delete fSession;
01178 }
01179
01180 void TTreeViewer::ActivateButtons(Bool_t first, Bool_t previous,
01181 Bool_t next, Bool_t last)
01182 {
01183
01184
01185 if (first) fBGFirst->SetState(kButtonUp);
01186 else fBGFirst->SetState(kButtonDisabled);
01187 if (previous) fBGPrevious->SetState(kButtonUp);
01188 else fBGPrevious->SetState(kButtonDisabled);
01189 if (next) fBGNext->SetState(kButtonUp);
01190 else fBGNext->SetState(kButtonDisabled);
01191 if (last) fBGLast->SetState(kButtonUp);
01192 else fBGLast->SetState(kButtonDisabled);
01193 }
01194
01195
01196 const char* TTreeViewer::Cut()
01197 {
01198
01199
01200 return fLVContainer->Cut();
01201 }
01202
01203
01204 const char* TTreeViewer::ScanList()
01205 {
01206
01207
01208 return fLVContainer->ScanList();
01209 }
01210
01211
01212 void TTreeViewer::SetSession(TTVSession *session)
01213 {
01214
01215
01216 if (session) {
01217 delete fSession;
01218 fSession = session;
01219 }
01220 }
01221
01222
01223 const char* TTreeViewer::EmptyBrackets(const char* name)
01224 {
01225
01226
01227 TString stripped(name);
01228 if (!stripped.Contains("[")) return name;
01229 TString retstr(name);
01230 TObjString *objstr;
01231 Int_t index = 0;
01232 while (stripped.Index("[", index) != kNPOS) {
01233 Int_t start = stripped.Index("[", index);
01234 Int_t end = stripped.Index("]", index);
01235 if (end == kNPOS) {
01236 objstr = new TObjString(retstr.Data());
01237 fWidgets->Add(objstr);
01238 return (objstr->GetString()).Data();
01239 }
01240 index = start+2;
01241 retstr = stripped.Remove(start+1, end-start-1);
01242 stripped = retstr;
01243 }
01244 objstr = new TObjString(retstr.Data());
01245 fWidgets->Add(objstr);
01246 return (objstr->GetString()).Data();
01247 }
01248
01249
01250 void TTreeViewer::EmptyAll()
01251 {
01252
01253
01254 fLVContainer->EmptyAll();
01255 }
01256
01257
01258 void TTreeViewer::Empty()
01259 {
01260
01261
01262 void *p = 0;
01263 TTVLVEntry *item = 0;
01264 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
01265 Warning("Empty", "No item selected.");
01266 return;
01267 }
01268 ULong_t *itemType = (ULong_t *) item->GetUserData();
01269 if (!(*itemType & kLTExpressionType)) {
01270 Warning("Empty", "Not expression type.");
01271 return;
01272 }
01273 if (*itemType & kLTPackType) {
01274 item->SetSmallPic(fClient->GetPicture("pack-empty_t.xpm"));
01275 item->SetTrueName("");
01276 return;
01277 }
01278 item->Empty();
01279 }
01280
01281
01282 TTVLVEntry * TTreeViewer::ExpressionItem(Int_t index)
01283 {
01284
01285
01286 return fLVContainer->ExpressionItem(index);
01287 }
01288
01289
01290 TList* TTreeViewer::ExpressionList()
01291 {
01292
01293
01294 return fLVContainer->ExpressionList();
01295 }
01296
01297
01298 Int_t TTreeViewer::Dimension()
01299 {
01300
01301
01302 fDimension = 0;
01303 if (strlen(Ex())) fDimension++;
01304 if (strlen(Ey())) fDimension++;
01305 if (strlen(Ez())) fDimension++;
01306 return fDimension;
01307 }
01308
01309
01310 void TTreeViewer::ExecuteDraw()
01311 {
01312
01313
01314 TString varexp;
01315 TString command;
01316 Int_t dimension = 0;
01317 TString alias[3];
01318 TTVLVEntry *item;
01319 Int_t i;
01320
01321 if (fVarDraw) {
01322 void *p = 0;
01323 dimension = 1;
01324 if (!(item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p))) return;
01325 alias[0] = item->GetAlias();
01326 if (alias[0].BeginsWith("~")) alias[0].Remove(0, 1);
01327 varexp = item->ConvertAliases();
01328 } else {
01329 if (strlen(Ez())) {
01330 dimension++;
01331 varexp = Ez();
01332 item = ExpressionItem(2);
01333 alias[2] = item->GetAlias();
01334 if (alias[2].BeginsWith("~")) alias[2].Remove(0, 1);
01335 }
01336 if (strlen(Ez()) && (strlen(Ex()) || strlen(Ey()))) varexp += ":";
01337 if (strlen(Ey())) {
01338 dimension++;
01339 varexp += Ey();
01340 item = ExpressionItem(1);
01341 alias[1] = item->GetAlias();
01342 if (alias[1].BeginsWith("~")) alias[1].Remove(0, 1);
01343 }
01344 if (strlen(Ey()) && strlen(Ex())) varexp += ":";
01345 if (strlen(Ex())) {
01346 dimension++;
01347 varexp += Ex();
01348 item = ExpressionItem(0);
01349 alias[0] = item->GetAlias();
01350 if (alias[0].BeginsWith("~")) alias[0].Remove(0, 1);
01351 }
01352 }
01353 if (!dimension && !fScanMode) {
01354 Warning("ExecuteDraw", "Nothing to draw on X,Y,Z.");
01355 return;
01356 }
01357
01358 fTree->SetEventList(0);
01359 TEventList *elist = 0;
01360 if (strlen(fBarListIn->GetText())) {
01361 elist = (TEventList *) gROOT->FindObject(fBarListIn->GetText());
01362 if (elist) fTree->SetEventList(elist);
01363 }
01364
01365 if (strlen(fBarListOut->GetText())) varexp = TString::Format(">>%s", fBarListOut->GetText());
01366
01367 if (strcmp("htemp", fBarHist->GetText())) {
01368 varexp += ">>";
01369 varexp += fBarHist->GetText();
01370 }
01371
01372 TPad *pad = (TPad*)gROOT->GetSelectedPad();
01373 if (pad) pad->cd();
01374
01375 const char* gopt = fBarOption->GetText();
01376
01377 gROOT->SetInterrupt(kFALSE);
01378
01379 const char *cut = "";
01380 if (fEnableCut) cut = Cut();
01381
01382
01383 Long64_t nentries = (Long64_t)(fSlider->GetMaxPosition() -
01384 fSlider->GetMinPosition() + 1);
01385 Long64_t firstentry =(Long64_t) fSlider->GetMinPosition();
01386
01387
01388 if (fScanMode) {
01389
01390 fScanMode = kFALSE;
01391 if (strlen(ScanList())) varexp = ScanList();
01392 command = TString::Format("tv__tree->Scan(\"%s\",\"%s\",\"%s\", %lld, %lld);",
01393 varexp.Data(), cut, gopt, nentries, firstentry);
01394 if (fBarScan->GetState() == kButtonDown) {
01395 ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kTRUE);
01396 } else {
01397 ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kFALSE);
01398 }
01399 ExecuteCommand(command.Data(), kTRUE);
01400 return;
01401 }
01402
01403 if (fBarH->GetState() == kButtonDown) {
01404
01405 fBarH->SetState(kButtonUp);
01406 TH1 *hist = fTree->GetHistogram();
01407 if (hist && gPad) {
01408
01409 if (hist) {
01410
01411 TString last(fLastOption);
01412 TString current(gopt);
01413 current.ToUpper();
01414 last.ToUpper();
01415 if (current == last) {
01416 gPad->Update();
01417 return;
01418 }
01419 if (dimension == 3 && strlen(gopt)) {
01420 cout << "Graphics option " << gopt << " not valid for 3D histograms" << endl;
01421 return;
01422 }
01423 cout << " Graphics option for current histogram changed to " << gopt << endl;
01424 hist->Draw(gopt);
01425 fLastOption = fBarOption->GetText();
01426 gPad->Update();
01427 return;
01428 }
01429 }
01430 }
01431
01432 fLastOption = fBarOption->GetText();
01433 if (!strlen(gopt) && dimension!=3)
01434
01435
01436
01437
01438 if (dimension == 3 && strlen(gopt)) {
01439 cout << "Graphics option " << gopt << " not valid for 3D histograms" << endl;
01440 gopt = "";
01441 fLastOption = "";
01442 }
01443 command = TString::Format("tv__tree->Draw(\"%s\",\"%s\",\"%s\", %lld, %lld);",
01444 varexp.Data(), cut, gopt, nentries, firstentry);
01445 if (fCounting) return;
01446 fCounting = kTRUE;
01447 fTree->SetTimerInterval(200);
01448 fTimer->TurnOn();
01449 ExecuteCommand(command.Data());
01450 HandleTimer(fTimer);
01451 fTimer->TurnOff();
01452 fTree->SetTimerInterval(0);
01453 fCounting = kFALSE;
01454 fProgressBar->SetPosition(0);
01455 fProgressBar->ShowPosition();
01456 TH1 *hist = fTree->GetHistogram();
01457 if (hist) {
01458
01459 Int_t current = 0;
01460 for (i=0; i<3; i++) {
01461 if (alias[i].Length()) {
01462 if (i != current) {
01463 alias[current] = alias[i];
01464 alias[i] = "";
01465 }
01466 current++;
01467 }
01468 }
01469
01470 TAxis *axis[3];
01471 axis[0] = hist->GetXaxis();
01472 axis[1] = hist->GetYaxis();
01473 axis[2] = hist->GetZaxis();
01474 for (Int_t ind=0; ind<3; ind++) axis[ind]->SetTitle(alias[ind].Data());
01475 }
01476 if (gPad) gPad->Update();
01477 }
01478
01479
01480
01481 void TTreeViewer::ExecuteSpider()
01482 {
01483
01484
01485 TString varexp;
01486 Int_t dimension = 0;
01487 TString alias[3];
01488 TTVLVEntry *item;
01489 Bool_t previousexp = kFALSE;
01490
01491 if (strlen(Ez())) {
01492 previousexp = kTRUE;
01493 dimension++;
01494 varexp = Ez();
01495 item = ExpressionItem(2);
01496 alias[2] = item->GetAlias();
01497 if (alias[2].BeginsWith("~")) alias[2].Remove(0, 1);
01498 }
01499 if (strlen(Ez()) && (strlen(Ex()) || strlen(Ey()))) varexp += ":";
01500 if (strlen(Ey())) {
01501 previousexp = kTRUE;
01502 dimension++;
01503 varexp += Ey();
01504 item = ExpressionItem(1);
01505 alias[1] = item->GetAlias();
01506 if (alias[1].BeginsWith("~")) alias[1].Remove(0, 1);
01507 }
01508 if (strlen(Ey()) && strlen(Ex())) varexp += ":";
01509 if (strlen(Ex())) {
01510 previousexp = kTRUE;
01511 dimension++;
01512 varexp += Ex();
01513 item = ExpressionItem(0);
01514 alias[0] = item->GetAlias();
01515 if (alias[0].BeginsWith("~")) alias[0].Remove(0, 1);
01516 }
01517 for(Int_t i=0;i<10;++i){
01518 if(strlen(En(i+5))){
01519 ++dimension;
01520 if(previousexp){
01521 varexp += ":";
01522 varexp += En(i+5);
01523 } else varexp = En(i+5);
01524 previousexp = kTRUE;
01525 }
01526 }
01527 if (dimension<3) {
01528 Warning("ExecuteSpider", "Need at least 3 variables");
01529 return;
01530 }
01531
01532 fTree->SetEventList(0);
01533 TEventList *elist = 0;
01534 if (strlen(fBarListIn->GetText())) {
01535 elist = (TEventList *) gROOT->FindObject(fBarListIn->GetText());
01536 if (elist) fTree->SetEventList(elist);
01537 }
01538
01539 if (strlen(fBarListOut->GetText())) varexp = TString::Format(">>%s", fBarListOut->GetText());
01540
01541 TPad *pad = (TPad*)gROOT->GetSelectedPad();
01542 if (pad) pad->cd();
01543
01544 const char* gopt = fBarOption->GetText();
01545
01546 gROOT->SetInterrupt(kFALSE);
01547
01548 const char *cut = "";
01549 if (fEnableCut) cut = Cut();
01550
01551
01552 Long64_t nentries = (Long64_t)(fSlider->GetMaxPosition() -
01553 fSlider->GetMinPosition() + 1);
01554 Long64_t firstentry =(Long64_t) fSlider->GetMinPosition();
01555
01556
01557
01558 TSpider* spider = new TSpider(fTree,varexp.Data(),cut,Form("%s spider average",gopt),nentries,firstentry);
01559 spider->Draw();
01560
01561 if (gPad) gPad->Update();
01562 }
01563
01564
01565 const char* TTreeViewer::Ex()
01566 {
01567
01568
01569 return fLVContainer->Ex();
01570 }
01571
01572
01573 const char* TTreeViewer::Ey()
01574 {
01575
01576
01577 return fLVContainer->Ey();
01578 }
01579
01580
01581 const char* TTreeViewer::Ez()
01582 {
01583
01584
01585 return fLVContainer->Ez();
01586 }
01587
01588
01589 const char* TTreeViewer::En(Int_t n)
01590 {
01591
01592 TTVLVEntry *e = fLVContainer->ExpressionItem(n);
01593 if(e) return e->ConvertAliases();
01594 return "";
01595 }
01596
01597
01598 void TTreeViewer::EditExpression()
01599 {
01600
01601
01602 void *p = 0;
01603
01604 TTVLVEntry *item = 0;
01605 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
01606 Warning("EditExpression", "No item selected.");
01607 return;
01608 }
01609
01610 ULong_t *itemType = (ULong_t *) item->GetUserData();
01611 if (!(*itemType & kLTExpressionType)) {
01612 Warning("EditExpression", "Not expression type.");
01613 return;
01614 }
01615
01616 fDialogBox = TGSelectBox::GetInstance();
01617 if (!fDialogBox) {
01618 fDialogBox = new TGSelectBox(fClient->GetRoot(), this, fV1->GetWidth() - 10);
01619 }
01620
01621 fDialogBox->SetEntry(item);
01622 fDialogBox->SetWindowName("Expression editor");
01623
01624 if (*itemType & kLTCutType || item->IsCut()) {
01625 fDialogBox->SetLabel("Selection");
01626 } else {
01627 fDialogBox->SetLabel("Expression");
01628 }
01629 }
01630
01631
01632 Int_t TTreeViewer::MakeSelector(const char* selector)
01633 {
01634
01635
01636 if (!fTree) return 0;
01637 return fTree->MakeSelector(selector);
01638 }
01639
01640
01641 Long64_t TTreeViewer::Process(const char* filename, Option_t *option, Long64_t nentries, Long64_t firstentry)
01642 {
01643
01644
01645 if (!fTree) return 0;
01646 return fTree->Process(filename, option, nentries, firstentry);
01647 }
01648
01649
01650 const char *TTreeViewer::GetGrOpt()
01651 {
01652
01653
01654 return fBarOption->GetText();
01655 }
01656
01657
01658 void TTreeViewer::SetGrOpt(const char *option)
01659 {
01660
01661
01662 fBarOption->SetText(option);
01663 }
01664
01665
01666 Bool_t TTreeViewer::IsScanRedirected()
01667 {
01668
01669
01670 return (fBarScan->GetState()==kButtonDown);
01671 }
01672
01673
01674 void TTreeViewer::RemoveItem()
01675 {
01676
01677
01678 void *p = 0;
01679 TTVLVEntry *item = 0;
01680
01681 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
01682 Warning("RemoveItem", "No item selected.");
01683 return;
01684 }
01685
01686 ULong_t *itemType = (ULong_t *) item->GetUserData();
01687 if (!(*itemType & kLTDragType)) {
01688 Warning("RemoveItem", "Not removable type.");
01689 return;
01690 }
01691 fLVContainer->RemoveItem(item);
01692 fListView->Layout();
01693 }
01694
01695
01696 void TTreeViewer::RemoveLastRecord()
01697 {
01698
01699
01700 fSession->RemoveLastRecord();
01701 }
01702
01703
01704 Bool_t TTreeViewer::HandleTimer(TTimer *timer)
01705 {
01706
01707
01708 if (fCounting) {
01709 Float_t first = fSlider->GetMinPosition();
01710 Float_t last = fSlider->GetMaxPosition();
01711 Float_t current = (Float_t)fTree->GetReadEntry();
01712 Float_t percent = (current-first+1)/(last-first+1);
01713 fProgressBar->SetPosition(100.*percent);
01714 fProgressBar->ShowPosition();
01715 }
01716 timer->Reset();
01717 return kFALSE;
01718 }
01719
01720
01721 Bool_t TTreeViewer::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
01722 {
01723
01724
01725 TRootHelpDialog *hd;
01726
01727 switch (GET_MSG(msg)) {
01728 case kC_VSLIDER :
01729
01730 PrintEntries();
01731 break;
01732 case kC_TEXTENTRY:
01733 switch (GET_SUBMSG(msg)) {
01734
01735 case kTE_ENTER:
01736 if ((Int_t)parm1 == kBarCommand) {
01737 ExecuteCommand(fBarCommand->GetText());
01738 fBarCommand->Clear();
01739 }
01740 if ((Int_t)parm1 == kBarOption) {
01741 fVarDraw = kFALSE;
01742 fBarH->SetState(kButtonDown);
01743 ExecuteDraw();
01744 fBarH->SetState(kButtonUp);
01745 }
01746 break;
01747 default:
01748 break;
01749 }
01750 break;
01751 case kC_LISTTREE:
01752 switch (GET_SUBMSG(msg)) {
01753
01754 case kCT_ITEMCLICK :
01755 if ((parm1==kButton1) || (parm1==kButton3)) {
01756 TGListTreeItem *ltItem = 0;
01757
01758 if ((ltItem = fLt->GetSelected()) != 0) {
01759
01760 ULong_t *itemType = (ULong_t *)ltItem->GetUserData();
01761 if (*itemType & kLTTreeType) {
01762
01763 Int_t index = (Int_t)(*itemType >> 8);
01764 SwitchTree(index);
01765 if (fTree != fMappedTree) {
01766
01767 fLVContainer->RemoveNonStatic();
01768
01769 MapTree(fTree);
01770 fListView->Layout();
01771 }
01772
01773 if (parm1 == kButton3) {
01774 Int_t x = (Int_t)(parm2 &0xffff);
01775 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
01776 fContextMenu->Popup(x, y, fTree);
01777 }
01778 }
01779
01780 if (*itemType & kLTBranchType) {
01781
01782 SetParentTree(ltItem);
01783 if (!fTree) break;
01784 TBranch *branch = fTree->GetBranch(ltItem->GetText());
01785 if (!branch) break;
01786
01787 if (branch != fMappedBranch) {
01788 fLVContainer->RemoveNonStatic();
01789 MapBranch(branch);
01790 fStopMapping = kFALSE;
01791 fListView->Layout();
01792 }
01793
01794 if (parm1 == kButton3) {
01795 Int_t x = (Int_t)(parm2 &0xffff);
01796 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
01797 fContextMenu->Popup(x, y, branch);
01798 }
01799 }
01800
01801 if (*itemType & kLTLeafType) {
01802
01803 SetParentTree(ltItem);
01804 if (!fTree) break;
01805
01806 TBranch *branch = fTree->GetBranch(ltItem->GetParent()->GetText());
01807 if (!branch) {
01808 if (fTree != fMappedTree) {
01809 fLVContainer->RemoveNonStatic();
01810 MapTree(fTree);
01811 fListView->Layout();
01812 }
01813 } else {
01814
01815 if (branch!=fMappedBranch) {
01816 fLVContainer->RemoveNonStatic();
01817 MapBranch(branch);
01818 fStopMapping = kFALSE;
01819 fListView->Layout();
01820 }
01821 }
01822
01823 fLVContainer->SelectItem(ltItem->GetText());
01824 if (parm1 == kButton3) {
01825
01826 ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMCLICK), kButton3, parm2);
01827 }
01828 }
01829 }
01830 }
01831 break;
01832 case kCT_ITEMDBLCLICK :
01833 fClient->NeedRedraw(fLt);
01834 if (parm1 == kButton1) {
01835
01836 ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMDBLCLICK), kButton1, parm2);
01837 }
01838 break;
01839 default:
01840 break;
01841 }
01842 break;
01843 case kC_COMMAND:
01844 switch (GET_SUBMSG(msg)){
01845 case kCM_COMBOBOX:
01846 fSession->Show(fSession->GetRecord((Int_t)parm2));
01847 break;
01848 case kCM_BUTTON:
01849 switch (parm1) {
01850
01851 case kRESET:
01852 EmptyAll();
01853 break;
01854 case kDRAW:
01855 fVarDraw = kFALSE;
01856 ExecuteDraw();
01857 break;
01858 case kSTOP:
01859 if (fCounting)
01860 gROOT->SetInterrupt(kTRUE);
01861 break;
01862 case kCLOSE:
01863 SendCloseMessage();
01864 break;
01865 case kBGFirst:
01866 fSession->Show(fSession->First());
01867 break;
01868 case kBGPrevious:
01869 fSession->Show(fSession->Previous());
01870 break;
01871 case kBGRecord:
01872 fSession->AddRecord();
01873 break;
01874 case kBGNext:
01875 fSession->Show(fSession->Next());
01876 break;
01877 case kBGLast:
01878 fSession->Show(fSession->Last());
01879 break;
01880 default:
01881 break;
01882 }
01883 break;
01884 case kCM_MENU:
01885
01886
01887 if ((parm1>=kOptionsReset) && (parm1<kHelpAbout)) {
01888 Dimension();
01889 if ((fDimension==0) && (parm1>=kOptions1D)) {
01890 Warning("ProcessMessage", "Edit expressions first.");
01891 break;
01892 }
01893 if ((fDimension==1) && (parm1>=kOptions2D)) {
01894 Warning("ProcessMessage", "You have only one expression active.");
01895 break;
01896 }
01897 if ((fDimension==2) && (parm1>=kOptions1D) &&(parm1<kOptions2D)) {
01898 Warning("ProcessMessage", "1D drawing options not apply to 2D histograms.");
01899 break;
01900 }
01901
01902 MapOptions(parm1);
01903 break;
01904 }
01905 switch (parm1) {
01906 case kFileCanvas:
01907 gROOT->MakeDefCanvas();
01908 break;
01909 case kFileBrowse:
01910 if (1) {
01911 static TString dir(".");
01912 TGFileInfo info;
01913 info.fFileTypes = gOpenTypes;
01914 info.fIniDir = StrDup(dir);
01915 new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &info);
01916 if (!info.fFilename) return kTRUE;
01917 dir = info.fIniDir;
01918 TString command = TString::Format("tv__tree_file = new TFile(\"%s\");",
01919 gSystem->UnixPathName(info.fFilename));
01920 ExecuteCommand(command.Data());
01921 ExecuteCommand("tv__tree_file->ls();");
01922 cout << "Use SetTreeName() from context menu and supply a tree name" << endl;
01923 cout << "The context menu is activated by right-clicking the panel from right" << endl;
01924 }
01925 break;
01926 case kFileLoadLibrary:
01927 fBarCommand->SetText("gSystem->Load(\"\");");
01928 if (1) {
01929 Event_t event;
01930 event.fType = kButtonPress;
01931 event.fCode = kButton1;
01932
01933 fBarCommand->HandleButton(&event);
01934 }
01935 fBarCommand->SetCursorPosition(15);
01936 break;
01937 case kFileOpenSession:
01938 if (1) {
01939 static TString dir(".");
01940 TGFileInfo info;
01941 info.fFileTypes = gMacroTypes;
01942 info.fIniDir = StrDup(dir);
01943 new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &info);
01944 if (!info.fFilename) return kTRUE;
01945 dir = info.fIniDir;
01946 gInterpreter->Reset();
01947 if (!gInterpreter->IsLoaded(info.fFilename)) gInterpreter->LoadMacro(info.fFilename);
01948 char command[1024];
01949 command[0] = 0;
01950 snprintf(command,1024,"open_session((void*)0x%lx);", (Long_t)this);
01951 ExecuteCommand(command);
01952 }
01953 break;
01954 case kFileSaveMacro:
01955 SaveSource();
01956 break;
01957 case kFilePrint:
01958 break;
01959 case kFileClose:
01960 SendCloseMessage();
01961 break;
01962 case kFileQuit:
01963 gApplication->Terminate(0);
01964 break;
01965 case kEditExpression:
01966 EditExpression();
01967 break;
01968 case kEditCut:
01969 EditExpression();
01970 break;
01971 case kEditMacro:
01972 break;
01973 case kEditEvent:
01974 break;
01975 case kRunMacro:
01976 break;
01977 case kHelpAbout:
01978 {
01979 #ifdef R__UNIX
01980 TString rootx;
01981 # ifdef ROOTBINDIR
01982 rootx = ROOTBINDIR;
01983 # else
01984 rootx = gSystem->Getenv("ROOTSYS");
01985 if (!rootx.IsNull()) rootx += "/bin";
01986 # endif
01987 rootx += "/root -a &";
01988 gSystem->Exec(rootx);
01989 #else
01990 #ifdef WIN32
01991 new TWin32SplashThread(kTRUE);
01992 #else
01993 char str[32];
01994 snprintf(str,32, "About ROOT %s...", gROOT->GetVersion());
01995 hd = new TRootHelpDialog(this, str, 600, 400);
01996 hd->SetText(gHelpAbout);
01997 hd->Popup();
01998 #endif
01999 #endif
02000 }
02001 break;
02002 case kHelpAboutTV:
02003 hd = new TRootHelpDialog(this, "About TreeViewer...", 600, 400);
02004 hd->SetText(gTVHelpAbout);
02005 hd->Resize(hd->GetDefaultSize());
02006 hd->Popup();
02007 break;
02008 case kHelpStart:
02009 hd = new TRootHelpDialog(this, "Quick start...", 600, 400);
02010 hd->SetText(gTVHelpStart);
02011 hd->Popup();
02012 break;
02013 case kHelpLayout:
02014 hd = new TRootHelpDialog(this, "Layout...", 600, 400);
02015 hd->SetText(gTVHelpLayout);
02016 hd->Popup();
02017 break;
02018 case kHelpOpenSave:
02019 hd = new TRootHelpDialog(this, "Open/Save...", 600, 400);
02020 hd->SetText(gTVHelpOpenSave);
02021 hd->Popup();
02022 break;
02023 case kHelpDragging:
02024 hd = new TRootHelpDialog(this, "Dragging items...", 600, 400);
02025 hd->SetText(gTVHelpDraggingItems);
02026 hd->Popup();
02027 break;
02028 case kHelpEditing:
02029 hd = new TRootHelpDialog(this, "Editing expressions...", 600, 400);
02030 hd->SetText(gTVHelpEditExpressions);
02031 hd->Popup();
02032 break;
02033 case kHelpSession:
02034 hd = new TRootHelpDialog(this, "Session...", 600, 400);
02035 hd->SetText(gTVHelpSession);
02036 hd->Popup();
02037 break;
02038 case kHelpCommands:
02039 hd = new TRootHelpDialog(this, "Executing user commands...", 600, 400);
02040 hd->SetText(gTVHelpUserCommands);
02041 hd->Popup();
02042 break;
02043 case kHelpContext:
02044 hd = new TRootHelpDialog(this, "Context menus...", 600, 400);
02045 hd->SetText(gTVHelpContext);
02046 hd->Popup();
02047 break;
02048 case kHelpDrawing:
02049 hd = new TRootHelpDialog(this, "Drawing histograms...", 600, 400);
02050 hd->SetText(gTVHelpDrawing);
02051 hd->Popup();
02052 break;
02053 case kHelpMacros:
02054 hd = new TRootHelpDialog(this, "Using macros...", 600, 400);
02055 hd->SetText(gTVHelpMacros);
02056 hd->Popup();
02057 break;
02058 default:
02059 break;
02060 }
02061 break;
02062 default:
02063 break;
02064 }
02065 break;
02066 case kC_CONTAINER:
02067 switch (GET_SUBMSG(msg)) {
02068
02069 case kCT_SELCHANGED:
02070 break;
02071 case kCT_ITEMCLICK:
02072
02073 switch (parm1) {
02074 case kButton1:
02075 if (fLVContainer->NumSelected()) {
02076
02077 void *p = 0;
02078 TTVLVEntry *item;
02079 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
02080 const char* vname = item->GetTrueName();
02081 TString trueName(vname);
02082 if (trueName.Contains("[]")) {
02083 TIter next(fTree->GetListOfLeaves());
02084 TLeaf *leaf;
02085 while((leaf=(TLeaf*)next())) {
02086 if (!strcmp(vname, EmptyBrackets(leaf->GetName())))
02087 vname = leaf->GetName();
02088 }
02089 }
02090 char* msg2 = new char[2000];
02091
02092 ULong_t *itemType = (ULong_t *) item->GetUserData();
02093 if (*itemType & kLTTreeType) {
02094
02095 char symbol = (char)((*itemType) >> 8);
02096 snprintf(msg2,2000, "%c expression : %s", symbol, vname);
02097 } else {
02098 if (*itemType & kLTCutType) {
02099
02100 snprintf(msg2,2000, "Cut : %s", vname);
02101 } else {
02102 if (*itemType & kLTPackType) {
02103 snprintf(msg2,2000, "Box : %s", vname);
02104 } else {
02105 if (*itemType & kLTExpressionType) {
02106
02107 snprintf(msg2,2000, "Expression : %s", vname);
02108 } else {
02109 if (*itemType & kLTBranchType) {
02110 snprintf(msg2,2000, "Branch : %s", vname);
02111 } else {
02112 snprintf(msg2,2000, "Leaf : %s", vname);
02113 }
02114 }
02115 }
02116 }
02117 }
02118
02119 TString message = msg2;
02120 message = message(0,150);
02121 Message(msg2);
02122 delete[] msg2;
02123
02124 if ((*itemType & kLTBranchType) || (*itemType & kLTCutType)) break;
02125 fDialogBox = TGSelectBox::GetInstance();
02126 if (!fDialogBox || !strlen(vname)) break;
02127 if (item == fDialogBox->EditedEntry()) break;
02128
02129
02130 TString insert(item->GetAlias());
02131
02132
02133
02134
02135 fDialogBox->GrabPointer();
02136 fDialogBox->InsertText(insert.Data());
02137
02138 }
02139 }
02140 break;
02141 case kButton2:
02142 break;
02143 case kButton3:
02144
02145 if (fLVContainer->NumSelected()) {
02146 void *p = 0;
02147 Int_t x = (Int_t)(parm2 &0xffff);
02148 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
02149 TTVLVEntry *item = 0;
02150 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
02151 fContextMenu->Popup(x, y, item->GetContext());
02152 }
02153 } else {
02154 Int_t x = (Int_t)(parm2 &0xffff);
02155 Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
02156 fContextMenu->Popup(x, y, this);
02157 }
02158 break;
02159 default:
02160 break;
02161 }
02162 break;
02163 case kCT_ITEMDBLCLICK:
02164 switch (parm1) {
02165 case kButton1:
02166 if (fLVContainer->NumSelected()) {
02167
02168 void *p = 0;
02169 TTVLVEntry *item;
02170 if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
02171
02172 ULong_t *itemType = (ULong_t *) item->GetUserData();
02173 if (!(*itemType & kLTCutType) && !(*itemType & kLTBranchType)
02174 && !(*itemType & kLTPackType)) {
02175 if (strlen(item->GetTrueName())) {
02176 fVarDraw = kTRUE;
02177
02178 ExecuteDraw();
02179 break;
02180 } else {
02181
02182 EditExpression();
02183 }
02184 }
02185 if (*itemType & kLTCutType) {
02186 fEnableCut = !fEnableCut;
02187 if (fEnableCut) {
02188 item->SetSmallPic(gClient->GetPicture("cut_t.xpm"));
02189 } else {
02190 item->SetSmallPic(gClient->GetPicture("cut-disable_t.xpm"));
02191 }
02192 }
02193 if (*itemType & kLTPackType) {
02194 fScanMode = kTRUE;
02195 ExecuteDraw();
02196 }
02197 }
02198 }
02199 break;
02200 case kButton2:
02201 break;
02202 case kButton3:
02203 break;
02204 default:
02205 break;
02206 }
02207 break;
02208 case 4:
02209
02210 default:
02211 break;
02212 }
02213 break;
02214 default:
02215 break;
02216 }
02217 return kTRUE;
02218 }
02219
02220
02221 void TTreeViewer::CloseWindow()
02222 {
02223
02224
02225 DeleteWindow();
02226 }
02227
02228
02229 void TTreeViewer::ExecuteCommand(const char* command, Bool_t fast)
02230 {
02231
02232
02233
02234 if (fBarRec->GetState() == kButtonDown) {
02235
02236
02237 char comm[2000];
02238 comm[0] = 0;
02239 if (strlen(command) > 1999) {
02240 Warning("ExecuteCommand", "Command too long: aborting.");
02241 return;
02242 }
02243 snprintf(comm,2000, "%s", command);
02244
02245 Gl_histadd(comm);
02246 }
02247
02248 if (fast) {
02249 gROOT->ProcessLineFast(command);
02250 } else {
02251 gROOT->ProcessLine(command);
02252 }
02253
02254 fVarDraw = kFALSE;
02255 }
02256
02257 void TTreeViewer::MapOptions(Long_t parm1)
02258 {
02259
02260
02261 Int_t ind;
02262 if (parm1 == kOptionsReset) {
02263 for (ind=kOptionsGeneral; ind<kOptionsGeneral+16; ind++)
02264 fOptionsGen->UnCheckEntry(ind);
02265 for (ind=kOptions1D; ind<kOptions1D+12; ind++)
02266 fOptions1D->UnCheckEntry(ind);
02267 for (ind=kOptions2D; ind<kOptions2D+14; ind++)
02268 fOptions2D->UnCheckEntry(ind);
02269 }
02270 if ((parm1 < kOptions1D) && (parm1 != kOptionsReset)) {
02271 if (fOptionsGen->IsEntryChecked((Int_t)parm1)) {
02272 fOptionsGen->UnCheckEntry((Int_t)parm1);
02273 } else {
02274 fOptionsGen->CheckEntry((Int_t)parm1);
02275 if ((Int_t)parm1 != kOptionsGeneral) fOptionsGen->UnCheckEntry((Int_t)kOptionsGeneral);
02276 }
02277 if (fOptionsGen->IsEntryChecked((Int_t)kOptionsGeneral)) {
02278
02279 for (ind=kOptionsGeneral+1; ind<kOptionsGeneral+16; ind++) {
02280 fOptionsGen->UnCheckEntry(ind);
02281 }
02282 }
02283 }
02284
02285 if ((parm1 < kOptions2D) && (parm1 >= kOptions1D)) {
02286 if (fOptions1D->IsEntryChecked((Int_t)parm1)) {
02287 fOptions1D->UnCheckEntry((Int_t)parm1);
02288 } else {
02289 fOptions1D->CheckEntry((Int_t)parm1);
02290 if ((Int_t)parm1 != kOptions1D) fOptions1D->UnCheckEntry((Int_t)kOptions1D);
02291 }
02292 if (fOptions1D->IsEntryChecked((Int_t)kOptions1D)) {
02293
02294 for (ind=kOptions1D+1; ind<kOptions1D+12; ind++) {
02295 fOptions1D->UnCheckEntry(ind);
02296 }
02297 }
02298 }
02299
02300 if (parm1 >= kOptions2D) {
02301 if (fOptions2D->IsEntryChecked((Int_t)parm1)) {
02302 fOptions2D->UnCheckEntry((Int_t)parm1);
02303 } else {
02304 fOptions2D->CheckEntry((Int_t)parm1);
02305 if ((Int_t)parm1 != kOptions2D) fOptions2D->UnCheckEntry((Int_t)kOptions2D);
02306 }
02307 if (fOptions2D->IsEntryChecked((Int_t)kOptions2D)) {
02308
02309 for (ind=kOptions2D+1; ind<kOptions2D+14; ind++) {
02310 fOptions2D->UnCheckEntry(ind);
02311 }
02312 }
02313 }
02314
02315 fBarOption->SetText("");
02316 for (ind=kOptionsGeneral; ind<kOptionsGeneral+16; ind++) {
02317 if (fOptionsGen->IsEntryChecked(ind))
02318 fBarOption->AppendText(gOptgen[ind-kOptionsGeneral]);
02319 }
02320 if (Dimension() == 1) {
02321 for (ind=kOptions1D; ind<kOptions1D+12; ind++) {
02322 if (fOptions1D->IsEntryChecked(ind))
02323 fBarOption->AppendText(gOpt1D[ind-kOptions1D]);
02324 }
02325 }
02326 if (Dimension() == 2) {
02327 for (ind=kOptions2D; ind<kOptions2D+14; ind++) {
02328 if (fOptions2D->IsEntryChecked(ind))
02329 fBarOption->AppendText(gOpt2D[ind-kOptions2D]);
02330 }
02331 }
02332 }
02333
02334
02335 void TTreeViewer::MapTree(TTree *tree, TGListTreeItem *parent, Bool_t listIt)
02336 {
02337
02338
02339 if (!tree) return;
02340 TObjArray *branches = tree->GetListOfBranches();
02341 if (!branches) return;
02342 TBranch *branch;
02343
02344 Int_t id;
02345 for (id=0; id<branches->GetEntries(); id++) {
02346 branch = (TBranch *)branches->At(id);
02347 if (branch->TestBit(kDoNotProcess)) continue;
02348 TString name = branch->GetName();
02349 if (name.Contains("fBits") || name.Contains("fUniqueID")) continue;
02350
02351 MapBranch(branch, "", parent, listIt);
02352 fStopMapping = kFALSE;
02353 }
02354
02355
02356
02357 TIter nextf( tree->GetTree()->GetListOfFriends() );
02358 TFriendElement *fr;
02359 while ((fr = (TFriendElement*)nextf())) {
02360 TTree * t = fr->GetTree();
02361 branches = t->GetListOfBranches();
02362 for (id=0; id<branches->GetEntries(); id++) {
02363 branch = (TBranch *)branches->At(id);
02364 if (branch->TestBit(kDoNotProcess)) continue;
02365 TString name = branch->GetName();
02366 if (name.Contains("fBits") || name.Contains("fUniqueID")) continue;
02367
02368 MapBranch(branch, fr->GetName(), parent, listIt);
02369 fStopMapping = kFALSE;
02370 }
02371 }
02372
02373
02374 if (listIt) {
02375 fMappedTree = tree;
02376 fMappedBranch = 0;
02377 }
02378 }
02379
02380
02381 void TTreeViewer::MapBranch(TBranch *branch, const char *prefix, TGListTreeItem *parent, Bool_t listIt)
02382 {
02383
02384
02385 if (!branch) return;
02386 TString name;
02387 if (prefix && strlen(prefix) >0) name = Form("%s.%s",prefix,branch->GetName());
02388 else name = branch->GetName();
02389 Int_t ind;
02390 TGListTreeItem *branchItem = 0;
02391 ULong_t *itemType;
02392
02393 if (name.Contains("fBits") || name.Contains("fUniqueID")) return;
02394 if (parent) {
02395
02396 const TGPicture *pic, *spic;
02397 if ((branch->GetListOfBranches()->GetEntries()) ||
02398 (branch->GetNleaves())) {
02399 if (branch->GetListOfBranches()->GetEntries()) {
02400 itemType = new ULong_t(kLTBranchType);
02401 if (branch->InheritsFrom("TBranchObject")) {
02402 pic = gClient->GetPicture("branch-ob_t.xpm");
02403 spic = gClient->GetPicture("branch-ob_t.xpm");
02404 } else {
02405 if (branch->InheritsFrom("TBranchClones")) {
02406 pic = gClient->GetPicture("branch-cl_t.xpm");
02407 spic = gClient->GetPicture("branch-cl_t.xpm");
02408 } else {
02409 pic = gClient->GetPicture("branch_t.xpm");
02410 spic = gClient->GetPicture("branch_t.xpm");
02411 }
02412 }
02413 branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType, pic, spic);
02414 } else {
02415 if (branch->GetNleaves() > 1) {
02416 itemType = new ULong_t(kLTBranchType);
02417 pic = gClient->GetPicture("branch_t.xpm");
02418 spic = gClient->GetPicture("branch_t.xpm");
02419 branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType,pic, spic);
02420 TObjArray *leaves = branch->GetListOfLeaves();
02421 TLeaf *leaf = 0;
02422 TString leafName;
02423 for (Int_t lf=0; lf<leaves->GetEntries(); lf++) {
02424 leaf = (TLeaf *)leaves->At(lf);
02425 leafName = name;
02426 leafName.Append(".").Append(EmptyBrackets(leaf->GetName()));
02427 itemType = new ULong_t(kLTLeafType);
02428 pic = gClient->GetPicture("leaf_t.xpm");
02429 spic = gClient->GetPicture("leaf_t.xpm");
02430 fLt->AddItem(branchItem, leafName.Data(), itemType, pic, spic);
02431 }
02432 } else {
02433 itemType = new ULong_t(kLTLeafType);
02434 pic = gClient->GetPicture("leaf_t.xpm");
02435 spic = gClient->GetPicture("leaf_t.xpm");
02436 branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType, pic, spic);
02437 }
02438 }
02439 }
02440 }
02441
02442 if (listIt) {
02443 TGString *textEntry = 0;
02444 const TGPicture *pic, *spic;
02445 TTVLVEntry *entry;
02446
02447 if (!fStopMapping) {
02448 fMappedBranch = branch;
02449 fMappedTree = 0;
02450 fStopMapping = kTRUE;
02451 }
02452 if ((branch->GetListOfBranches()->GetEntries()) ||
02453 (branch->GetNleaves())) {
02454 textEntry = new TGString(EmptyBrackets(name.Data()));
02455 if (branch->GetListOfBranches()->GetEntries()) {
02456 if (branch->InheritsFrom("TBranchObject")) {
02457 pic = gClient->GetPicture("branch-ob_t.xpm");
02458 spic = gClient->GetPicture("branch-ob_t.xpm");
02459 } else {
02460 if (branch->InheritsFrom("TBranchClones")) {
02461 pic = gClient->GetPicture("branch-cl_t.xpm");
02462 spic = gClient->GetPicture("branch-cl_t.xpm");
02463 } else {
02464 pic = gClient->GetPicture("branch_t.xpm");
02465 spic = gClient->GetPicture("branch_t.xpm");
02466 }
02467 }
02468 entry = new TTVLVEntry(fLVContainer,pic,spic,textEntry,0,kLVSmallIcons);
02469 entry->SetUserData(new UInt_t(kLTBranchType));
02470 entry->SetToolTipText("Branch with sub-branches. Can not be dragged");
02471 fLVContainer->AddThisItem(entry);
02472 entry->MapWindow();
02473 entry->SetAlias(textEntry->GetString());
02474 } else {
02475 if (branch->GetNleaves() > 1) {
02476 if (textEntry) delete textEntry;
02477 textEntry = new TGString(EmptyBrackets(name.Data()));
02478 pic = gClient->GetPicture("branch_t.xpm");
02479 spic = gClient->GetPicture("branch_t.xpm");
02480 entry = new TTVLVEntry(fLVContainer, pic, spic, textEntry,0,kLVSmallIcons);
02481 entry->SetUserData(new UInt_t(kLTBranchType));
02482 entry->SetToolTipText("Branch with more than one leaf. Can not be dragged");
02483 fLVContainer->AddThisItem(entry);
02484 entry->MapWindow();
02485 entry->SetAlias(textEntry->GetString());
02486
02487 TObjArray *leaves = branch->GetListOfLeaves();
02488 TLeaf *leaf = 0;
02489 TString leafName;
02490 for (Int_t lf=0; lf<leaves->GetEntries(); lf++) {
02491 leaf = (TLeaf *)leaves->At(lf);
02492 leafName = name;
02493 leafName.Append(".").Append(EmptyBrackets(leaf->GetName()));
02494 textEntry = new TGString(leafName.Data());
02495 pic = gClient->GetPicture("leaf_t.xpm");
02496 spic = gClient->GetPicture("leaf_t.xpm");
02497 entry = new TTVLVEntry(fLVContainer, pic, spic, textEntry,0,kLVSmallIcons);
02498 entry->SetUserData(new UInt_t(kLTDragType | kLTLeafType));
02499 entry->SetToolTipText("Double-click to draw. Drag to X, Y, Z or scan box.");
02500 fLVContainer->AddThisItem(entry);
02501 entry->MapWindow();
02502 entry->SetAlias(textEntry->GetString());
02503 }
02504 } else {
02505 pic = (gClient->GetMimeTypeList())->GetIcon("TLeaf",kFALSE);
02506 if (!pic) pic = gClient->GetPicture("leaf_t.xpm");
02507 spic = gClient->GetMimeTypeList()->GetIcon("TLeaf",kTRUE);
02508 if (!spic) spic = gClient->GetPicture("leaf_t.xpm");
02509 entry = new TTVLVEntry(fLVContainer,pic,spic,textEntry,0,kLVSmallIcons);
02510 entry->SetUserData(new UInt_t(kLTDragType | kLTLeafType));
02511 entry->SetToolTipText("Double-click to draw. Drag to X, Y, Z or scan box.");
02512 fLVContainer->AddThisItem(entry);
02513 entry->MapWindow();
02514 entry->SetAlias(textEntry->GetString());
02515 }
02516 }
02517 }
02518 }
02519
02520 TObjArray *branches = branch->GetListOfBranches();
02521 TBranch *branchDaughter = 0;
02522
02523
02524 for (ind=0; ind<branches->GetEntries(); ind++) {
02525 branchDaughter = (TBranch *)branches->UncheckedAt(ind);
02526
02527 MapBranch(branchDaughter, "", branchItem, listIt);
02528 }
02529 }
02530
02531
02532 void TTreeViewer::NewExpression()
02533 {
02534
02535
02536 fLVContainer->RemoveNonStatic();
02537 const TGPicture *pic = gClient->GetPicture("expression_t.xpm");
02538 const TGPicture *spic = gClient->GetPicture("expression_t.xpm");
02539
02540 TTVLVEntry *entry = new TTVLVEntry(fLVContainer,pic,spic,
02541 new TGString(),0,kLVSmallIcons);
02542 entry->SetUserData(new ULong_t(kLTExpressionType | kLTDragType));
02543 fLVContainer->AddThisItem(entry);
02544 entry->MapWindow();
02545 entry->Empty();
02546 if (fMappedTree) MapTree(fTree);
02547 if (fMappedBranch) MapBranch(fMappedBranch);
02548 fListView->Layout();
02549 fNexpressions++;
02550 }
02551
02552
02553 void TTreeViewer::SetParentTree(TGListTreeItem *item)
02554 {
02555
02556
02557 if (!item) return;
02558 ULong_t *itemType = (ULong_t *)item->GetUserData();
02559 TGListTreeItem *parent = 0;
02560 Int_t index;
02561 if (!(*itemType & kLTTreeType)) {
02562 parent = item->GetParent();
02563 SetParentTree(parent);
02564 } else {
02565 index = (Int_t)(*itemType >> 8);
02566 SwitchTree(index);
02567 }
02568 }
02569
02570
02571 void TTreeViewer::Message(const char* msg)
02572 {
02573
02574
02575 fStatusBar->SetText(msg);
02576 }
02577
02578
02579 void TTreeViewer::DoError(int level, const char *location, const char *fmt, va_list va) const
02580 {
02581
02582
02583 TObject::DoError(level, location, fmt, va);
02584
02585
02586
02587 static const int buf_size = 2048;
02588 char buf[buf_size], *bp;
02589
02590 int n = vsnprintf(buf, buf_size, fmt, va);
02591
02592
02593 if (n == -1 || n >= buf_size) {
02594 TObject::Warning("DoError", "Error message string truncated...");
02595 }
02596 if (level >= kSysError && level < kFatal)
02597 bp = Form("%s (%s)", buf, gSystem->GetError());
02598 else
02599 bp = buf;
02600
02601 const char *title = "";
02602 if (level == kInfo)
02603 title = "Info";
02604 if (level == kWarning)
02605 title = "Warning";
02606 if (level == kError)
02607 title = "Error";
02608 if (level == kSysError)
02609 title = "System Error";
02610
02611 new TGMsgBox(fClient->GetRoot(), this, title, bp, kMBIconExclamation);
02612 }
02613
02614
02615 void TTreeViewer::PrintEntries()
02616 {
02617
02618
02619 if (!fTree) return;
02620 char * msg = new char[100];
02621 snprintf(msg,100, "First entry : %lld Last entry : %lld",
02622 (Long64_t)fSlider->GetMinPosition(), (Long64_t)fSlider->GetMaxPosition());
02623 Message(msg);
02624 delete[] msg;
02625 }
02626
02627
02628 void TTreeViewer::SaveSource(const char* filename, Option_t *)
02629 {
02630
02631
02632 if (!fTree) return;
02633 char quote = '"';
02634 ofstream out;
02635 Int_t lenfile = strlen(filename);
02636 char * fname;
02637 if (!lenfile) {
02638 fname = (char*)fSourceFile;
02639 lenfile = strlen(fname);
02640 } else {
02641 fname = (char*)filename;
02642 fSourceFile = filename;
02643 }
02644
02645
02646 if (lenfile) {
02647 out.open(fname, ios::out);
02648 } else {
02649 fname = new char[13];
02650 strlcpy(fname, "treeviewer.C",13);
02651 out.open(fname, ios::out);
02652 }
02653 if (!out.good ()) {
02654 printf("SaveSource cannot open file : %s\n", fname);
02655 fSourceFile = "treeviewer.C";
02656 if (!lenfile) delete [] fname;
02657 return;
02658 }
02659
02660 TDatime t;
02661 TString sname(fname);
02662 sname = sname.ReplaceAll(".C", "");
02663 out <<"void "<<sname.Data()<<"() {"<<endl;
02664 out <<"//=========Macro generated by ROOT version"<<gROOT->GetVersion()<<endl;
02665 out <<"//=========for tree "<<quote<<fTree->GetName()<<quote<<" ("<<t.AsString()<<")"<<endl;
02666 out <<"//===This macro can be opened from a TreeViewer session after loading"<<endl;
02667 out <<"//===the corresponding tree, or by running root with the macro name argument"<<endl<<endl;
02668 out <<" open_session();"<<endl;
02669 out <<"}"<<endl<<endl;
02670 out <<"open_session(void *p = 0) {"<<endl;
02671 out <<" gSystem->Load("<<quote<<"libTreeViewer"<<quote<<");"<<endl;
02672 out <<" TTreeViewer *treeview = (TTreeViewer *) p;"<<endl;
02673 out <<" if (!treeview) treeview = new TTreeViewer();"<<endl;
02674 out <<" TTree *tv_tree = (TTree*)gROOT->FindObject("<<quote<<fTree->GetName()<<quote<<");"<<endl;
02675 out <<" TFile *tv_file = (TFile*)gROOT->GetListOfFiles()->FindObject("<<quote<<fFilename<<quote<<");"<<endl;
02676 out <<" if (!tv_tree) {"<<endl;
02677 out <<" if (!tv_file) tv_file = new TFile("<<quote<<fFilename<<quote<<");"<<endl;
02678 out <<" if (tv_file) tv_tree = (TTree*)tv_file->Get("<<quote<<fTree->GetName()<<quote<<");"<<endl;
02679 out <<" if(!tv_tree) {"<<endl;
02680 out <<" printf(\"Tree %s not found\", fTree->GetName());"<<endl;
02681 out <<" return;"<<endl;
02682 out <<" }"<<endl;
02683 out <<" }"<<endl<<endl;
02684 out <<" treeview->SetTreeName("<<quote<<fTree->GetName()<<quote<<");"<<endl;
02685 out <<" treeview->SetNexpressions("<<fNexpressions<<");"<<endl;
02686
02687 TTVLVEntry *item;
02688 out <<"// Set expressions on axis and cut"<<endl;
02689 out <<" TTVLVEntry *item;"<<endl;
02690 for (Int_t i=0; i<4; i++) {
02691 switch (i) {
02692 case 0:
02693 out <<"// X expression"<<endl;
02694 break;
02695 case 1:
02696 out <<"// Y expression"<<endl;
02697 break;
02698 case 2:
02699 out <<"// Z expression"<<endl;
02700 break;
02701 case 3:
02702 out <<"// Cut expression"<<endl;
02703 break;
02704 default:
02705 break;
02706 }
02707 item = ExpressionItem(i);
02708 out <<" item = treeview->ExpressionItem("<<i<<");"<<endl;
02709 out <<" item->SetExpression("<<quote<<item->GetTrueName()<<quote
02710 <<", "<<quote<<item->GetAlias()<<quote<<");"<<endl;
02711 }
02712 out <<"// Scan list"<<endl;
02713 item = ExpressionItem(4);
02714 out <<" item = treeview->ExpressionItem(4);"<<endl;
02715 out <<" item->SetExpression("<<quote<<item->GetTrueName()<<quote
02716 <<", "<<quote<<"Scan box"<<quote<<");"<<endl;
02717 out <<"// User defined expressions"<<endl;
02718 TString itemType;
02719 for (Int_t crt=5; crt<fNexpressions+5; crt++) {
02720 item = ExpressionItem(crt);
02721 if (item->IsCut())
02722 itemType = "kTRUE";
02723 else
02724 itemType = "kFALSE";
02725 out <<" item = treeview->ExpressionItem("<<crt<<");"<<endl;
02726 out <<" item->SetExpression("<<quote<<item->GetTrueName()<<quote
02727 <<", "<<quote<<item->GetAlias()<<quote<<", "<<itemType.Data()<<");"<<endl;
02728 }
02729 fSession->SaveSource(out);
02730 out <<"}"<<endl;
02731 out.close();
02732 printf("C++ Macro file: %s has been generated\n", fname);
02733 if (!lenfile) delete [] fname;
02734 }
02735
02736
02737 Bool_t TTreeViewer::SwitchTree(Int_t index)
02738 {
02739
02740
02741 TTree *tree = (TTree *) fTreeList->At(index);
02742 if (!tree) {
02743 Warning("SwitchTree", "No tree found.");
02744 return kFALSE;
02745 }
02746 if ((tree == fTree) && (tree == fMappedTree)) return kFALSE;
02747 std::string command;
02748 if (tree != fTree) {
02749 command = "tv__tree = (TTree *) tv__tree_list->At";
02750 command += Form("(%i)",index);
02751 ExecuteCommand(command.c_str());
02752 }
02753
02754 fTree = tree;
02755 fSlider->SetRange(0,fTree->GetEntries()-1);
02756 fSlider->SetPosition(0,fTree->GetEntries()-1);
02757 command = "Current Tree : ";
02758 command += fTree->GetName();
02759 fLbl2->SetText(new TGString(command.c_str()));
02760 fTreeHdr->Layout();
02761 MapSubwindows();
02762 Resize(GetDefaultSize());
02763 MapWindow();
02764
02765 PrintEntries();
02766 return kTRUE;
02767 }
02768
02769
02770 void TTreeViewer::SetRecordName(const char *name)
02771 {
02772
02773
02774 fSession->SetRecordName(name);
02775 }
02776
02777
02778 void TTreeViewer::SetCurrentRecord(Long64_t entry)
02779 {
02780
02781
02782 fCombo->Select(entry);
02783 }
02784
02785
02786 void TTreeViewer::SetHistogramTitle(const char *title)
02787 {
02788
02789
02790 if (!gPad) return;
02791 TH1 *hist = (TH1*)gPad->GetListOfPrimitives()->FindObject(fBarHist->GetText());
02792 if (hist) {
02793 hist->SetTitle(title);
02794 gPad->Update();
02795 }
02796 }
02797
02798 void TTreeViewer::SetUserCode(const char *code, Bool_t autoexec)
02799 {
02800
02801
02802 TTVRecord *rec = fSession->GetCurrent();
02803 if (rec) rec->SetUserCode(code, autoexec);
02804 }
02805
02806 void TTreeViewer::UpdateCombo()
02807 {
02808
02809
02810 fCombo->RemoveEntries(0, 1000);
02811 for (Long64_t entry=0; entry<fSession->GetEntries(); entry++) {
02812 fCombo->AddEntry(fSession->GetRecord(entry)->GetName(), entry);
02813 }
02814 }
02815
02816
02817 void TTreeViewer::UpdateRecord(const char *name)
02818 {
02819
02820
02821 fSession->UpdateRecord(name);
02822 }
02823
02824
02825 void TTreeViewer::DoRefresh()
02826 {
02827
02828
02829 fTree->Refresh();
02830 Float_t min = fSlider->GetMinPosition();
02831 Float_t max = (Float_t)fTree->GetEntries()-1;
02832 fSlider->SetRange(min,max);
02833 fSlider->SetPosition(min,max);
02834 ExecuteDraw();
02835 }