Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui/browsable/inc/ROOT/Browsable/RShared.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template<class T>
class RShared : public RHolder {
std::shared_ptr<T> fShared; ///<! holder without IO
protected:
void *GetShared() const final { return &fShared; }
void *GetShared() const final { return (void *) &fShared; }
RHolder* DoCopy() const final { return new RShared<T>(fShared); }
public:
RShared(T *obj) { fShared.reset(obj); }
Expand Down
2 changes: 2 additions & 0 deletions gui/browsable/src/TObjectElement.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RHolder> &object) -> std::shared_ptr<RElement> {
return std::make_shared<TFolderElement>(object);
});
Expand Down
13 changes: 13 additions & 0 deletions roofit/xroofit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion roofit/xroofit/src/xRooNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ auto &GETWSSNAPSHOTS(RooWorkspace *w)
}
auto GETACTBROWSER(TRootBrowser *b)
{
return b->GetActBrowser();
return b ? b->GetActBrowser() : nullptr;
}
auto GETROOTDIR(TGFileBrowser *b)
{
Expand Down
173 changes: 173 additions & 0 deletions roofit/xroofit/src/xRooProvider.cxx
Original file line number Diff line number Diff line change
@@ -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 <ROOT/Browsable/RElement.hxx>
#include <ROOT/Browsable/RProvider.hxx>
#include <ROOT/Browsable/TObjectItem.hxx>
#include <ROOT/Browsable/RLevelIter.hxx>
#include <ROOT/Browsable/RShared.hxx>

#include <RooFit/xRooFit/xRooNode.h>

#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<xRooNode> fNode;
public:
xRooBrowsingElement(std::shared_ptr<xRooNode> 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<RHolder> GetObject() override
{
return std::make_unique<RShared<xRooNode>>(fNode);
}

std::unique_ptr<RLevelIter> GetChildsIter() override;
};

class xRooLevelIter : public RLevelIter {

std::shared_ptr<xRooNode> fNode;

int fCounter{-1};

public:
explicit xRooLevelIter(std::shared_ptr<xRooNode> 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<RItem> CreateItem() override
{
auto xnode = (*fNode)[fCounter];

auto item = std::make_unique<TObjectItem>(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<RElement> GetElement() override
{
auto xnode = (*fNode)[fCounter];
return std::make_shared<xRooBrowsingElement>(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<RLevelIter> 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<xRooLevelIter>(fNode);
}

// ==============================================================================================

class xRooProvider : public RProvider {

public:
xRooProvider()
{
RegisterBrowse(RooWorkspace::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
auto wk = object->get_shared<RooWorkspace>();

auto wkNode = std::make_shared<xRooNode>(wk);

return std::make_shared<xRooBrowsingElement>(wkNode);
});

RegisterDraw6(xRooNode::Class(), [this](TVirtualPad *pad, std::unique_ptr<RHolder> &obj, const std::string &opt) -> bool {

Check warning on line 159 in roofit/xroofit/src/xRooProvider.cxx

View workflow job for this annotation

GitHub Actions / mac15 ARM64 CMAKE_CXX_STANDARD=23

lambda capture 'this' is not used [-Wunused-lambda-capture]

Check warning on line 159 in roofit/xroofit/src/xRooProvider.cxx

View workflow job for this annotation

GitHub Actions / mac26 ARM64

lambda capture 'this' is not used [-Wunused-lambda-capture]

Check warning on line 159 in roofit/xroofit/src/xRooProvider.cxx

View workflow job for this annotation

GitHub Actions / mac14 X64 CMAKE_CXX_STANDARD=20

lambda capture 'this' is not used [-Wunused-lambda-capture]

Check warning on line 159 in roofit/xroofit/src/xRooProvider.cxx

View workflow job for this annotation

GitHub Actions / mac-beta ARM64

lambda capture 'this' is not used [-Wunused-lambda-capture]

Check warning on line 159 in roofit/xroofit/src/xRooProvider.cxx

View workflow job for this annotation

GitHub Actions / alma10 clang Ninja CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

lambda capture 'this' is not used [-Wunused-lambda-capture]
auto xnode = const_cast<xRooNode *>(obj->Get<xRooNode>());
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;
Loading