Skip to content
Snippets Groups Projects
Commit 96eaf3f8 authored by Carsten Burgard's avatar Carsten Burgard Committed by Jonas Rembser
Browse files

[RF][HS3] Improved attribute handling, caught some typecast-errors

parent 3d1783cf
No related branches found
No related tags found
No related merge requests found
...@@ -307,25 +307,15 @@ void genIndicesHelper(std::vector<std::vector<int>> &combinations, std::vector<i ...@@ -307,25 +307,15 @@ void genIndicesHelper(std::vector<std::vector<int>> &combinations, std::vector<i
} }
} }
void importAttributes(RooAbsArg *arg, JSONNode const &rootnode) void importAttributes(RooAbsArg *arg, JSONNode const &node)
{ {
JSONNode const &attributesNode = dereference(rootnode, {"misc", "ROOT_internal", "attributes"}, rootnode); if (node.has_child("dict")) {
for (const auto &attr : (node)["dict"].children()) {
// If the attributes node was not found, it will not be a sequence node
if (!attributesNode.is_seq())
return;
JSONNode const *node = RooJSONFactoryWSTool::findNamedChild(attributesNode, arg->GetName());
if (node == nullptr)
return;
if (node->has_child("dict")) {
for (const auto &attr : (*node)["dict"].children()) {
arg->setStringAttribute(RooJSONFactoryWSTool::name(attr).c_str(), attr.val().c_str()); arg->setStringAttribute(RooJSONFactoryWSTool::name(attr).c_str(), attr.val().c_str());
} }
} }
if (node->has_child("tags")) { if (node.has_child("tags")) {
for (const auto &attr : (*node)["tags"].children()) { for (const auto &attr : (node)["tags"].children()) {
arg->setAttribute(attr.val().c_str()); arg->setAttribute(attr.val().c_str());
} }
} }
...@@ -628,7 +618,7 @@ JSONNode *RooJSONFactoryWSTool::exportObject(const RooAbsArg *func) ...@@ -628,7 +618,7 @@ JSONNode *RooJSONFactoryWSTool::exportObject(const RooAbsArg *func)
// Exporting the dependants will invalidate the iterator in "elem". So // Exporting the dependants will invalidate the iterator in "elem". So
// instead of returning elem, we have to find again the element with // instead of returning elem, we have to find again the element with
// the right name. // the right name.
return const_cast<JSONNode*>(findNamedChild(collectionNode, name)); return const_cast<JSONNode *>(findNamedChild(collectionNode, name));
} }
} }
...@@ -682,7 +672,7 @@ JSONNode *RooJSONFactoryWSTool::exportObject(const RooAbsArg *func) ...@@ -682,7 +672,7 @@ JSONNode *RooJSONFactoryWSTool::exportObject(const RooAbsArg *func)
// Exporting the dependants will invalidate the iterator in "elem". So // Exporting the dependants will invalidate the iterator in "elem". So
// instead of returning elem, we have to find again the element with the // instead of returning elem, we have to find again the element with the
// right name. // right name.
return const_cast<JSONNode*>(findNamedChild(collectionNode, name)); return const_cast<JSONNode *>(findNamedChild(collectionNode, name));
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -1388,7 +1378,9 @@ void RooJSONFactoryWSTool::importAnalysis(const RooFit::Detail::JSONNode &analys ...@@ -1388,7 +1378,9 @@ void RooJSONFactoryWSTool::importAnalysis(const RooFit::Detail::JSONNode &analys
RooArgSet nps; RooArgSet nps;
RooArgSet pois; RooArgSet pois;
for (auto const &child : analysisNode["pois"].children()) { for (auto const &child : analysisNode["pois"].children()) {
pois.add(*_workspace.var(child.val())); if (auto var = _workspace.var(child.val())) {
pois.add(*var);
}
} }
RooArgSet globs; RooArgSet globs;
std::unique_ptr<RooArgSet> pdfVars{pdf->getVariables()}; std::unique_ptr<RooArgSet> pdfVars{pdf->getVariables()};
...@@ -1461,8 +1453,13 @@ void RooJSONFactoryWSTool::importAllNodes(const RooFit::Detail::JSONNode &n) ...@@ -1461,8 +1453,13 @@ void RooJSONFactoryWSTool::importAllNodes(const RooFit::Detail::JSONNode &n)
_workspace.loadSnapshot("fromJSON"); _workspace.loadSnapshot("fromJSON");
// Import attributes // Import attributes
for (RooAbsArg *arg : _workspace.components()) { JSONNode const &attributesNode =
importAttributes(arg, *_rootnodeInput); dereference(*_rootnodeInput, {"misc", "ROOT_internal", "attributes"}, *_rootnodeInput);
if (attributesNode.is_seq()) {
for (const auto &elem : attributesNode.children()) {
if (RooAbsArg *arg = _workspace.arg(elem["name"].val()))
importAttributes(arg, elem);
}
} }
_rootnodeInput = nullptr; _rootnodeInput = nullptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment