1010#include < ROOT/Browsable/RProvider.hxx>
1111#include < ROOT/Browsable/TObjectItem.hxx>
1212#include < ROOT/Browsable/RLevelIter.hxx>
13+ #include < ROOT/Browsable/RShared.hxx>
1314
1415#include < RooFit/xRooFit/xRooNode.h>
1516
17+ #include " TVirtualPad.h"
1618
1719#include " RooWorkspace.h"
1820
1921using namespace ROOT ::Browsable;
2022using namespace std ::string_literals;
21-
23+ using namespace ROOT ::Experimental::XRooFit ;
2224
2325class xRooBrowsingElement : public RElement {
24- std::shared_ptr<ROOT::Experimental::XRooFit:: xRooNode> fNode ;
26+ std::shared_ptr<xRooNode> fNode ;
2527public:
26- xRooBrowsingElement (std::shared_ptr<ROOT::Experimental::XRooFit::xRooNode> node);
27- bool IsCapable (EActionKind action) const override ;
28+ xRooBrowsingElement (std::shared_ptr<xRooNode> node)
29+ {
30+ fNode = node;
31+ }
32+
33+ bool IsCapable (EActionKind action) const override
34+ {
35+ return (action == kActDraw6 ) || (action == kActBrowse );
36+ }
37+
2838 /* * Get default action */
29- EActionKind GetDefaultAction () const override ;
39+ EActionKind GetDefaultAction () const override
40+ {
41+ if (fNode ->IsFolder ())
42+ return kActBrowse ;
43+ return kActDraw6 ;
44+ }
45+
46+ std::string GetName () const override
47+ {
48+ return fNode ->GetName ();
49+ }
50+
51+ std::string GetTitle () const override
52+ {
53+ return fNode ->GetTitle ();
54+ }
3055
31- std::string GetName () const override { return fNode ->GetName (); }
56+
57+ bool IsFolder () const override
58+ {
59+ return fNode ->IsFolder ();
60+ }
61+
62+ int GetNumChilds () override
63+ {
64+ return fNode ->IsFolder () ? (int ) fNode ->size () : 0 ;
65+ }
66+
67+ std::unique_ptr<RHolder> GetObject () override
68+ {
69+ return std::make_unique<RShared<xRooNode>>(fNode );
70+ }
3271
3372 std::unique_ptr<RLevelIter> GetChildsIter () override ;
3473};
3574
3675class xRooLevelIter : public RLevelIter {
3776
38- std::shared_ptr<ROOT::Experimental::XRooFit:: xRooNode> fNode ;
77+ std::shared_ptr<xRooNode> fNode ;
3978
4079 int fCounter {-1 };
4180
4281public:
43- explicit xRooLevelIter (std::shared_ptr<ROOT::Experimental::XRooFit:: xRooNode> node) { fNode = node; }
82+ explicit xRooLevelIter (std::shared_ptr<xRooNode> node) { fNode = node; }
4483
4584 ~xRooLevelIter () override = default ;
4685
4786 auto NumElements () const { return fNode ->size (); }
4887
4988 bool Next () override { return ++fCounter < (int ) fNode ->size (); }
5089
51- // use default implementation for now
52- // bool Find(const std::string &name) override { return FindDirEntry(name); }
53-
5490 std::string GetItemName () const override { return (*fNode )[fCounter ]->GetName (); }
5591
5692 bool CanItemHaveChilds () const override
@@ -89,27 +125,9 @@ class xRooLevelIter : public RLevelIter {
89125
90126 return RLevelIter::Find (name, -1 );
91127 }
92-
93128};
94129
95130
96- xRooBrowsingElement::xRooBrowsingElement (std::shared_ptr<ROOT::Experimental::XRooFit::xRooNode> node)
97- {
98- fNode = node;
99- }
100-
101- /* * Check if want to perform action */
102- bool xRooBrowsingElement::IsCapable (RElement::EActionKind action) const
103- {
104- return action == kActDraw6 ;
105- }
106-
107- /* * Get default action */
108- RElement::EActionKind xRooBrowsingElement::GetDefaultAction () const
109- {
110- return kActDraw6 ;
111- }
112-
113131std::unique_ptr<RLevelIter> xRooBrowsingElement::GetChildsIter ()
114132{
115133 // here central part of hole story
@@ -123,7 +141,6 @@ std::unique_ptr<RLevelIter> xRooBrowsingElement::GetChildsIter()
123141 return std::make_unique<xRooLevelIter>(fNode );
124142}
125143
126-
127144// ==============================================================================================
128145
129146class xRooProvider : public RProvider {
@@ -134,12 +151,23 @@ class xRooProvider : public RProvider {
134151 RegisterBrowse (RooWorkspace::Class (), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
135152 auto wk = object->get_shared <RooWorkspace>();
136153
137- printf (" Create entry for workspace %s %s\n " , wk->GetName (), wk->ClassName ());
138-
139- auto wkNode = std::make_shared<ROOT::Experimental::XRooFit::xRooNode>(wk);
154+ auto wkNode = std::make_shared<xRooNode>(wk);
140155
141156 return std::make_shared<xRooBrowsingElement>(wkNode);
142157 });
158+
159+ RegisterDraw6 (xRooNode::Class (), [this ](TVirtualPad *pad, std::unique_ptr<RHolder> &obj, const std::string &opt) -> bool {
160+ auto xnode = const_cast <xRooNode *>(obj->Get <xRooNode>());
161+ if (!xnode)
162+ return false ;
163+
164+ pad->cd ();
165+ xnode->Draw (opt.c_str ());
166+ return true ;
167+ });
168+
169+ // example how custom icons can be provided
170+ RegisterClass (" RooRealVar" , " sap-icon://picture" );
143171 }
144172
145173} newxRooProvider;
0 commit comments