diff --git a/gui/browsable/inc/ROOT/Browsable/RShared.hxx b/gui/browsable/inc/ROOT/Browsable/RShared.hxx index d12e645500120..7f34ab3be6ab1 100644 --- a/gui/browsable/inc/ROOT/Browsable/RShared.hxx +++ b/gui/browsable/inc/ROOT/Browsable/RShared.hxx @@ -26,7 +26,7 @@ template class RShared : public RHolder { std::shared_ptr fShared; ///(fShared); } public: RShared(T *obj) { fShared.reset(obj); } diff --git a/gui/browsable/src/TObjectElement.cxx b/gui/browsable/src/TObjectElement.cxx index d65e0588c8f12..6a792e4e29fcb 100644 --- a/gui/browsable/src/TObjectElement.cxx +++ b/gui/browsable/src/TObjectElement.cxx @@ -593,6 +593,8 @@ class RTObjectProvider : public RProvider { RegisterClass("TGeoVolume", "sap-icon://product", "libROOTGeoBrowseProvider"); RegisterClass("TGeoNode", "sap-icon://product", "libROOTGeoBrowseProvider"); + RegisterClass("RooWorkspace", "sap-icon://list", "libROOTFitWorkspaceProvider"); + RegisterBrowse(TFolder::Class(), [](std::unique_ptr &object) -> std::shared_ptr { return std::make_shared(object); }); diff --git a/roofit/xroofit/CMakeLists.txt b/roofit/xroofit/CMakeLists.txt index c7c0a2638ffd5..4a3f746e103f7 100644 --- a/roofit/xroofit/CMakeLists.txt +++ b/roofit/xroofit/CMakeLists.txt @@ -34,3 +34,16 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitXRooFit target_include_directories(RooFitXRooFit PRIVATE inc/RooFit) ROOT_ADD_TEST_SUBDIRECTORY(test) + +if(webgui) + # provider for browsing of RooWorkspace + + ROOT_LINKER_LIBRARY(ROOTFitWorkspaceProvider + src/xRooProvider.cxx + DEPENDENCIES + ROOTBrowsable + RooFitCore + RooFitXRooFit + ) + +endif(webgui) diff --git a/roofit/xroofit/src/xRooNode.cxx b/roofit/xroofit/src/xRooNode.cxx index e894bff99cae3..e36ccdb25d566 100644 --- a/roofit/xroofit/src/xRooNode.cxx +++ b/roofit/xroofit/src/xRooNode.cxx @@ -110,7 +110,7 @@ auto &GETWSSNAPSHOTS(RooWorkspace *w) } auto GETACTBROWSER(TRootBrowser *b) { - return b->GetActBrowser(); + return b ? b->GetActBrowser() : nullptr; } auto GETROOTDIR(TGFileBrowser *b) { diff --git a/roofit/xroofit/src/xRooProvider.cxx b/roofit/xroofit/src/xRooProvider.cxx new file mode 100644 index 0000000000000..b9c8c9a23c47e --- /dev/null +++ b/roofit/xroofit/src/xRooProvider.cxx @@ -0,0 +1,173 @@ +/************************************************************************* + * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#include +#include +#include +#include +#include + +#include + +#include "TVirtualPad.h" + +#include "RooWorkspace.h" + +using namespace ROOT::Browsable; +using namespace std::string_literals; +using namespace ROOT::Experimental::XRooFit; + +class xRooBrowsingElement : public RElement { + std::shared_ptr fNode; +public: + xRooBrowsingElement(std::shared_ptr node) + { + fNode = node; + } + + bool IsCapable(EActionKind action) const override + { + return (action == kActDraw6) || (action == kActBrowse); + } + + /** Get default action */ + EActionKind GetDefaultAction() const override + { + if (fNode->IsFolder()) + return kActBrowse; + return kActDraw6; + } + + std::string GetName() const override + { + return fNode->GetName(); + } + + std::string GetTitle() const override + { + return fNode->GetTitle(); + } + + + bool IsFolder() const override + { + return fNode->IsFolder(); + } + + int GetNumChilds() override + { + return fNode->IsFolder() ? (int) fNode->size() : 0; + } + + std::unique_ptr GetObject() override + { + return std::make_unique>(fNode); + } + + std::unique_ptr GetChildsIter() override; +}; + +class xRooLevelIter : public RLevelIter { + + std::shared_ptr fNode; + + int fCounter{-1}; + +public: + explicit xRooLevelIter(std::shared_ptr node) { fNode = node; } + + ~xRooLevelIter() override = default; + + auto NumElements() const { return fNode->size(); } + + bool Next() override { return ++fCounter < (int) fNode->size(); } + + std::string GetItemName() const override { return (*fNode)[fCounter]->GetName(); } + + bool CanItemHaveChilds() const override + { + return (*fNode)[fCounter]->IsFolder(); + } + + /** Create item for the browser */ + std::unique_ptr CreateItem() override + { + auto xnode = (*fNode)[fCounter]; + + auto item = std::make_unique(xnode->GetName(), xnode->size()); + + item->SetTitle(xnode->GetTitle()); + + item->SetClassName(xnode->get()->ClassName()); + item->SetIcon(RProvider::GetClassIcon(xnode->get()->IsA(), xnode->IsFolder())); + + return item; + } + + /** Returns full information for current element */ + std::shared_ptr GetElement() override + { + auto xnode = (*fNode)[fCounter]; + return std::make_shared(xnode); + } + + bool Find(const std::string &name, int indx = -1) override + { + if ((indx >= 0) && (indx < (int) fNode->size()) && (name == (*fNode)[indx]->GetName())) { + fCounter = indx; + return true; + } + + return RLevelIter::Find(name, -1); + } +}; + + +std::unique_ptr xRooBrowsingElement::GetChildsIter() +{ + // here central part of hole story + // one need to provide list of sub-items via iterator + + fNode->browse(); + + if (fNode->size() == 0) + return nullptr; + + return std::make_unique(fNode); +} + +// ============================================================================================== + +class xRooProvider : public RProvider { + +public: + xRooProvider() + { + RegisterBrowse(RooWorkspace::Class(), [](std::unique_ptr &object) -> std::shared_ptr { + auto wk = object->get_shared(); + + auto wkNode = std::make_shared(wk); + + return std::make_shared(wkNode); + }); + + RegisterDraw6(xRooNode::Class(), [this](TVirtualPad *pad, std::unique_ptr &obj, const std::string &opt) -> bool { + auto xnode = const_cast(obj->Get()); + if (!xnode) + return false; + + pad->cd(); + xnode->Draw(opt.c_str()); + return true; + }); + + // example how custom icons can be provided + RegisterClass("RooRealVar", "sap-icon://picture"); + } + +} newxRooProvider;