When using RooFit
, statistical models can be conveniently handled and stored as a RooWorkspace
.
However, for the sake of interoperability with other statistical frameworks, and also ease of manipulation, it may be useful to store statistical models in text form.
The RooJSONFactoryWSTool is a helper class to achieve exactly this, exporting to and importing from JSON and YML.
In order to import a workspace from a JSON file, you can do
~~ {.py} ws = ROOT.RooWorkspace("ws") tool = ROOT.RooJSONFactoryWSTool(ws) tool.importJSON("myjson.json") ~~
Similarly, in order to export a workspace to a JSON file, you can do
~~ {.py} tool = ROOT.RooJSONFactoryWSTool(ws) tool.exportJSON("myjson.json") ~~
For more details, consult the tutorial rf515_hfJSON.
In order to import and export YML files, ROOT
needs to be compiled with the external dependency RapidYAML, which needs to be installed on your system and enabled via the CMake option roofit_hs3_ryml
.
The RooJSONFactoryWSTool only knows about a limited set of classes for import and export. If import or export of a class you're interested in fails, you might need to add your own importer or exporter. Please consult the README to learn how to do that.
You can always get a list of all the avialable importers and exporters by calling the following functions: ~~ {.py} ROOT.RooFit.JSONIO.printImporters() ROOT.RooFit.JSONIO.printExporters() ROOT.RooFit.JSONIO.printFactoryExpressions() ROOT.RooFit.JSONIO.printExportKeys() ~~
Alternatively, you can generate a LaTeX version of the available importers and exporters by calling ~~ {.py} tool = ROOT.RooJSONFactoryWSTool(ws) tool.writedoc("hs3.tex") ~~
Definition at line 38 of file RooJSONFactoryWSTool.h.
Classes | |
struct | CombinedData |
class | DependencyMissingError |
Public Member Functions | |
RooJSONFactoryWSTool (RooWorkspace &ws) | |
~RooJSONFactoryWSTool () | |
bool | exportJSON (std::ostream &os) |
bool | exportJSON (std::string const &fileName) |
std::string | exportJSONtoString () |
bool | exportYML (std::ostream &os) |
bool | exportYML (std::string const &fileName) |
std::string | exportYMLtoString () |
void | importFunction (const RooFit::Detail::JSONNode &n, bool importAllDependants) |
void | importFunction (const std::string &jsonString, bool importAllDependants) |
bool | importJSON (std::istream &os) |
bool | importJSON (std::string const &filename) |
void | importJSONElement (const std::string &name, const std::string &jsonString) |
bool | importJSONfromString (const std::string &s) |
void | importVariableElement (const RooFit::Detail::JSONNode &n) |
bool | importYML (std::istream &os) |
bool | importYML (std::string const &filename) |
bool | importYMLfromString (const std::string &s) |
void | queueExport (RooAbsArg const &arg) |
template<class T > | |
T * | request (const std::string &objname, const std::string &requestAuthor) |
template<class T > | |
T * | requestArg (const RooFit::Detail::JSONNode &node, const std::string &key) |
template<class T > | |
RooArgList | requestArgList (const RooFit::Detail::JSONNode &node, const std::string &seqName) |
template<class T > | |
RooArgSet | requestArgSet (const RooFit::Detail::JSONNode &node, const std::string &seqName) |
template<class T , class Coll_t > | |
Coll_t | requestCollection (const RooFit::Detail::JSONNode &node, const std::string &seqName) |
RooWorkspace * | workspace () |
template<class Obj_t , typename... Args_t> | |
Obj_t & | wsEmplace (RooStringView name, Args_t &&...args) |
template<class Obj_t > | |
Obj_t & | wsImport (Obj_t const &obj) |
Static Public Member Functions | |
static RooFit::Detail::JSONNode & | appendNamedChild (RooFit::Detail::JSONNode &node, std::string const &name) |
static std::unique_ptr< RooFit::Detail::JSONTree > | createNewJSONTree () |
Create a new JSON tree with version information. | |
static void | error (const char *s) |
static void | error (const std::string &s) |
static void | exportArray (std::size_t n, double const *contents, RooFit::Detail::JSONNode &output) |
static void | exportCategory (RooAbsCategory const &cat, RooFit::Detail::JSONNode &node) |
static void | exportHisto (RooArgSet const &vars, std::size_t n, double const *contents, RooFit::Detail::JSONNode &output) |
static void | fillSeq (RooFit::Detail::JSONNode &node, RooAbsCollection const &coll) |
static RooFit::Detail::JSONNode const * | findNamedChild (RooFit::Detail::JSONNode const &node, std::string const &name) |
template<typename... Keys_t> | |
static RooFit::Detail::JSONNode & | getRooFitInternal (RooFit::Detail::JSONNode &node, Keys_t const &...keys) |
static std::ostream & | log (int level) |
static RooFit::Detail::JSONNode & | makeVariablesNode (RooFit::Detail::JSONNode &rootNode) |
static std::string | name (const RooFit::Detail::JSONNode &n) |
static std::unique_ptr< RooDataHist > | readBinnedData (const RooFit::Detail::JSONNode &n, const std::string &namecomp) |
static std::unique_ptr< RooDataHist > | readBinnedData (const RooFit::Detail::JSONNode &n, const std::string &namecomp, RooArgList const &varlist) |
Static Public Attributes | |
static constexpr bool | useListsInsteadOfDicts = true |
Private Attributes | |
const RooFit::Detail::JSONNode * | _attributesNode = nullptr |
std::unique_ptr< RooFit::JSONIO::Detail::Domains > | _domains |
const RooFit::Detail::JSONNode * | _rootnodeInput = nullptr |
RooFit::Detail::JSONNode * | _rootnodeOutput = nullptr |
std::vector< RooAbsArg const * > | _serversToExport |
RooFit::Detail::JSONNode * | _varsNode = nullptr |
RooWorkspace & | _workspace |
#include <RooFitHS3/RooJSONFactoryWSTool.h>
RooJSONFactoryWSTool::RooJSONFactoryWSTool | ( | RooWorkspace & | ws | ) |
Definition at line 600 of file RooJSONFactoryWSTool.cxx.
RooJSONFactoryWSTool::~RooJSONFactoryWSTool | ( | ) |
Definition at line 602 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 615 of file RooJSONFactoryWSTool.cxx.
|
static |
Create a new JSON tree with version information.
Definition at line 1465 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 1701 of file RooJSONFactoryWSTool.cxx.
|
inlinestatic |
Definition at line 125 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 1362 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 1002 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 1016 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 1029 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 1086 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 976 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::exportJSON | ( | std::ostream & | os | ) |
Definition at line 1487 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::exportJSON | ( | std::string const & | fileName | ) |
Definition at line 1496 of file RooJSONFactoryWSTool.cxx.
std::string RooJSONFactoryWSTool::exportJSONtoString | ( | ) |
Definition at line 1448 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 1288 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 745 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 1311 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 703 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 737 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::exportYML | ( | std::ostream & | os | ) |
Definition at line 1509 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::exportYML | ( | std::string const & | fileName | ) |
Definition at line 1518 of file RooJSONFactoryWSTool.cxx.
std::string RooJSONFactoryWSTool::exportYMLtoString | ( | ) |
Definition at line 1456 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 604 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 625 of file RooJSONFactoryWSTool.cxx.
|
inlinestatic |
Definition at line 171 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 1531 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 1268 of file RooJSONFactoryWSTool.cxx.
void RooJSONFactoryWSTool::importFunction | ( | const RooFit::Detail::JSONNode & | n, |
bool | importAllDependants | ||
) |
Definition at line 883 of file RooJSONFactoryWSTool.cxx.
void RooJSONFactoryWSTool::importFunction | ( | const std::string & | jsonString, |
bool | importAllDependants | ||
) |
Definition at line 971 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::importJSON | ( | std::istream & | os | ) |
Definition at line 1599 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::importJSON | ( | std::string const & | filename | ) |
Definition at line 1607 of file RooJSONFactoryWSTool.cxx.
void RooJSONFactoryWSTool::importJSONElement | ( | const std::string & | name, |
const std::string & | jsonString | ||
) |
Definition at line 1640 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::importJSONfromString | ( | const std::string & | s | ) |
Definition at line 1434 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 1242 of file RooJSONFactoryWSTool.cxx.
void RooJSONFactoryWSTool::importVariableElement | ( | const RooFit::Detail::JSONNode & | n | ) |
Definition at line 1658 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::importYML | ( | std::istream & | os | ) |
Definition at line 1620 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::importYML | ( | std::string const & | filename | ) |
Definition at line 1627 of file RooJSONFactoryWSTool.cxx.
bool RooJSONFactoryWSTool::importYMLfromString | ( | const std::string & | s | ) |
Definition at line 1441 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 1696 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 647 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 642 of file RooJSONFactoryWSTool.cxx.
|
inline |
Definition at line 183 of file RooJSONFactoryWSTool.h.
|
static |
Definition at line 1164 of file RooJSONFactoryWSTool.cxx.
|
static |
Definition at line 1197 of file RooJSONFactoryWSTool.cxx.
|
inline |
Definition at line 61 of file RooJSONFactoryWSTool.h.
|
inline |
Definition at line 70 of file RooJSONFactoryWSTool.h.
|
inline |
Definition at line 104 of file RooJSONFactoryWSTool.h.
|
inline |
Definition at line 98 of file RooJSONFactoryWSTool.h.
|
inline |
Definition at line 80 of file RooJSONFactoryWSTool.h.
|
private |
|
private |
Definition at line 653 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 668 of file RooJSONFactoryWSTool.cxx.
|
private |
Definition at line 683 of file RooJSONFactoryWSTool.cxx.
|
inline |
Definition at line 109 of file RooJSONFactoryWSTool.h.
|
inline |
Definition at line 119 of file RooJSONFactoryWSTool.h.
|
inline |
Definition at line 112 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 213 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 219 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 212 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 214 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 220 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 215 of file RooJSONFactoryWSTool.h.
|
private |
Definition at line 216 of file RooJSONFactoryWSTool.h.
|
staticconstexpr |
Definition at line 40 of file RooJSONFactoryWSTool.h.