Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBrowserTreeWidget.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2022-10-07
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "RBrowserWidget.hxx"
14
15#include "ROOT/RTreeViewer.hxx"
16#include "ROOT/RBrowser.hxx"
18#include "TTree.h"
19#include "TBranch.h"
20#include "TBranchBrowsable.h"
21#include "TLeaf.h"
22
23using namespace ROOT;
24
25using namespace std::string_literals;
26
27
30 std::unique_ptr<Browsable::RHolder> fObject; // tree object
31 std::string fTitle;
32
33public:
34
36 {
39 fViewer.SetCallback([this](const std::string &canvas_name) {
40 GetBrowser()->ActivateWidget(canvas_name, "tcanvas");
41 });
42 }
43
44 virtual ~RBrowserTreeWidget() = default;
45
46 std::string GetKind() const override { return "tree"s; }
47 std::string GetTitle() override { return fTitle; }
48 std::string GetUrl() override { return fViewer.GetWindowUrl(false); }
49
50 void Show(const std::string &arg) override { fViewer.Show(arg); }
51
52 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string & = "") override
53 {
54 if (!elem->IsCapable(Browsable::RElement::kActTree))
55 return false;
56
57 auto obj = elem->GetObject();
58 if (!obj)
59 return false;
60
61 auto tree = obj->Get<TTree>();
62 if (tree) {
63 fObject = std::move(obj);
64 fTitle = tree->GetName();
65 fViewer.SetTree(const_cast<TTree *>(tree));
66 return true;
67 }
68
69 tree = fObject ? fObject->Get<TTree>() : nullptr;
70
71 TTree *new_tree = nullptr;
72 std::string expr = elem->GetContent("tree");
73
74 auto branch = obj->Get<TBranch>();
75 auto leaf = obj->Get<TLeaf>();
76 auto browsable = obj->Get<TVirtualBranchBrowsable>();
77
78 if (branch) {
79 new_tree = branch->GetTree();
80 if (expr.empty())
81 expr = branch->GetFullName().Data();
82 } else if (leaf) {
83 new_tree = leaf->GetBranch()->GetTree();
84 if (expr.empty())
85 expr = leaf->GetFullName().Data();
86 } else if (browsable) {
87 new_tree = browsable->GetBranch()->GetTree();
88 if (expr.empty())
89 expr = browsable->GetBranch()->GetFullName().Data();
90 }
91
92 if (!new_tree || expr.empty())
93 return false;
94
95 if (new_tree != tree) {
96 fObject = std::make_unique<Browsable::TObjectHolder>(new_tree);
97 fTitle = new_tree->GetName();
98 fViewer.SetTree(new_tree);
99 }
100
101 return fViewer.SuggestExpression(expr);
102 }
103
104 std::string SendWidgetContent() override { return SendWidgetTitle(); }
105
106};
107
108// ======================================================================
109
111protected:
112 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
113 {
114 return std::make_shared<RBrowserTreeWidget>(name);
115 }
116public:
RBrowserTreeProvider sRBrowserTreeProvider
char name[80]
Definition TGX11.cxx:110
~RBrowserTreeProvider()=default
std::shared_ptr< RBrowserWidget > Create(const std::string &name) final
void Show(const std::string &arg) override
std::string GetUrl() override
virtual ~RBrowserTreeWidget()=default
std::unique_ptr< Browsable::RHolder > fObject
std::string GetKind() const override
bool DrawElement(std::shared_ptr< Browsable::RElement > &elem, const std::string &="") override
std::string SendWidgetContent() override
std::string GetTitle() override
RBrowserTreeWidget(const std::string &name)
@ kActTree
can be shown in tree viewer
Definition RElement.hxx:58
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
RBrowser * GetBrowser() const
std::string SendWidgetTitle()
Returns string which can be send to browser client to set/change title of the widget tab.
bool ActivateWidget(const std::string &title, const std::string &kind="")
Activate widget in RBrowser One should specify title and (optionally) kind of widget like "tcanvas" o...
Definition RBrowser.cxx:975
Web-based ROOT TTree viewer.
void Show(const RWebDisplayArgs &args="", bool always_start_new_browser=false)
Show or update viewer in web window If web browser already started - just refresh drawing like "reloa...
void SetTree(TTree *tree)
assign new TTree to the viewer
std::string GetWindowUrl(bool remote)
Return URL of web window used for tree viewer See ROOT::RWebWindow::GetUrl docu for more details.
bool SuggestExpression(const std::string &expr)
Suggest to use expression in the gui Normally just assign as last edited expression.
void SetCallback(PerformDrawCallback_t func)
void SetTitle(const std::string &title)
void SetShowHierarchy(bool on=true)
Configures default hierarchy browser visibility, only has effect before showing web window.
A TTree is a list of TBranches.
Definition TBranch.h:93
TTree * GetTree() const
Definition TBranch.h:252
virtual TString GetFullName() const
Return the 'full' name of the branch.
Definition TBranch.cxx:2031
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
TBranch * GetBranch() const
Definition TLeaf.h:116
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * Data() const
Definition TString.h:376
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual TTree * GetTree() const
Definition TTree.h:557
TVirtualBranchBrowsable is a base class (not really abstract, but useless by itself) for helper objec...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...