Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooJSONFactoryWSTool Class Reference

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)
 
RooWorkspaceworkspace ()
 
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::JSONNodeappendNamedChild (RooFit::Detail::JSONNode &node, std::string const &name)
 
static std::unique_ptr< RooFit::Detail::JSONTreecreateNewJSONTree ()
 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::JSONNodegetRooFitInternal (RooFit::Detail::JSONNode &node, Keys_t const &...keys)
 
static std::ostream & log (int level)
 
static RooFit::Detail::JSONNodemakeVariablesNode (RooFit::Detail::JSONNode &rootNode)
 
static std::string name (const RooFit::Detail::JSONNode &n)
 
static std::unique_ptr< RooDataHistreadBinnedData (const RooFit::Detail::JSONNode &n, const std::string &namecomp)
 
static std::unique_ptr< RooDataHistreadBinnedData (const RooFit::Detail::JSONNode &n, const std::string &namecomp, RooArgList const &varlist)
 

Static Public Attributes

static constexpr bool useListsInsteadOfDicts = true
 

Private Member Functions

void exportAllObjects (RooFit::Detail::JSONNode &n)
 
RooJSONFactoryWSTool::CombinedData exportCombinedData (RooAbsData const &data)
 
void exportData (RooAbsData const &data)
 
void exportModelConfig (RooFit::Detail::JSONNode &rootnode, RooStats::ModelConfig const &mc, const std::vector< RooJSONFactoryWSTool::CombinedData > &d)
 
void exportObject (RooAbsArg const &func, std::set< std::string > &exportedObjectNames)
 
void exportSingleModelConfig (RooFit::Detail::JSONNode &rootnode, RooStats::ModelConfig const &mc, std::string const &analysisName, std::map< std::string, std::string > const *dataComponents)
 
void exportVariable (const RooAbsArg *v, RooFit::Detail::JSONNode &n)
 
void exportVariables (const RooArgSet &allElems, RooFit::Detail::JSONNode &n)
 
void importAllNodes (const RooFit::Detail::JSONNode &n)
 
void importDependants (const RooFit::Detail::JSONNode &n)
 
void importVariable (const RooFit::Detail::JSONNode &n)
 
template<class T >
T * requestImpl (const std::string &objname)
 
template<>
RooRealVarrequestImpl (const std::string &objname)
 
template<>
RooAbsPdfrequestImpl (const std::string &objname)
 
template<>
RooAbsRealrequestImpl (const std::string &objname)
 

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>

Constructor & Destructor Documentation

◆ RooJSONFactoryWSTool()

RooJSONFactoryWSTool::RooJSONFactoryWSTool ( RooWorkspace ws)

Definition at line 600 of file RooJSONFactoryWSTool.cxx.

◆ ~RooJSONFactoryWSTool()

RooJSONFactoryWSTool::~RooJSONFactoryWSTool ( )

Definition at line 602 of file RooJSONFactoryWSTool.cxx.

Member Function Documentation

◆ appendNamedChild()

JSONNode & RooJSONFactoryWSTool::appendNamedChild ( RooFit::Detail::JSONNode node,
std::string const &  name 
)
static

Definition at line 615 of file RooJSONFactoryWSTool.cxx.

◆ createNewJSONTree()

std::unique_ptr< JSONTree > RooJSONFactoryWSTool::createNewJSONTree ( )
static

Create a new JSON tree with version information.

Definition at line 1465 of file RooJSONFactoryWSTool.cxx.

◆ error() [1/2]

void RooJSONFactoryWSTool::error ( const char *  s)
static

Definition at line 1701 of file RooJSONFactoryWSTool.cxx.

◆ error() [2/2]

static void RooJSONFactoryWSTool::error ( const std::string &  s)
inlinestatic

Definition at line 125 of file RooJSONFactoryWSTool.h.

◆ exportAllObjects()

void RooJSONFactoryWSTool::exportAllObjects ( RooFit::Detail::JSONNode n)
private

Definition at line 1362 of file RooJSONFactoryWSTool.cxx.

◆ exportArray()

void RooJSONFactoryWSTool::exportArray ( std::size_t  n,
double const *  contents,
RooFit::Detail::JSONNode output 
)
static

Definition at line 1002 of file RooJSONFactoryWSTool.cxx.

◆ exportCategory()

void RooJSONFactoryWSTool::exportCategory ( RooAbsCategory const &  cat,
RooFit::Detail::JSONNode node 
)
static

Definition at line 1016 of file RooJSONFactoryWSTool.cxx.

◆ exportCombinedData()

RooJSONFactoryWSTool::CombinedData RooJSONFactoryWSTool::exportCombinedData ( RooAbsData const &  data)
private

Definition at line 1029 of file RooJSONFactoryWSTool.cxx.

◆ exportData()

void RooJSONFactoryWSTool::exportData ( RooAbsData const &  data)
private

Definition at line 1086 of file RooJSONFactoryWSTool.cxx.

◆ exportHisto()

void RooJSONFactoryWSTool::exportHisto ( RooArgSet const &  vars,
std::size_t  n,
double const *  contents,
RooFit::Detail::JSONNode output 
)
static

Definition at line 976 of file RooJSONFactoryWSTool.cxx.

◆ exportJSON() [1/2]

bool RooJSONFactoryWSTool::exportJSON ( std::ostream &  os)

Definition at line 1487 of file RooJSONFactoryWSTool.cxx.

◆ exportJSON() [2/2]

bool RooJSONFactoryWSTool::exportJSON ( std::string const &  fileName)

Definition at line 1496 of file RooJSONFactoryWSTool.cxx.

◆ exportJSONtoString()

std::string RooJSONFactoryWSTool::exportJSONtoString ( )

Definition at line 1448 of file RooJSONFactoryWSTool.cxx.

◆ exportModelConfig()

void RooJSONFactoryWSTool::exportModelConfig ( RooFit::Detail::JSONNode rootnode,
RooStats::ModelConfig const &  mc,
const std::vector< RooJSONFactoryWSTool::CombinedData > &  d 
)
private

Definition at line 1288 of file RooJSONFactoryWSTool.cxx.

◆ exportObject()

void RooJSONFactoryWSTool::exportObject ( RooAbsArg const &  func,
std::set< std::string > &  exportedObjectNames 
)
private

Definition at line 745 of file RooJSONFactoryWSTool.cxx.

◆ exportSingleModelConfig()

void RooJSONFactoryWSTool::exportSingleModelConfig ( RooFit::Detail::JSONNode rootnode,
RooStats::ModelConfig const &  mc,
std::string const &  analysisName,
std::map< std::string, std::string > const *  dataComponents 
)
private

Definition at line 1311 of file RooJSONFactoryWSTool.cxx.

◆ exportVariable()

void RooJSONFactoryWSTool::exportVariable ( const RooAbsArg v,
RooFit::Detail::JSONNode n 
)
private

Definition at line 703 of file RooJSONFactoryWSTool.cxx.

◆ exportVariables()

void RooJSONFactoryWSTool::exportVariables ( const RooArgSet allElems,
RooFit::Detail::JSONNode n 
)
private

Definition at line 737 of file RooJSONFactoryWSTool.cxx.

◆ exportYML() [1/2]

bool RooJSONFactoryWSTool::exportYML ( std::ostream &  os)

Definition at line 1509 of file RooJSONFactoryWSTool.cxx.

◆ exportYML() [2/2]

bool RooJSONFactoryWSTool::exportYML ( std::string const &  fileName)

Definition at line 1518 of file RooJSONFactoryWSTool.cxx.

◆ exportYMLtoString()

std::string RooJSONFactoryWSTool::exportYMLtoString ( )

Definition at line 1456 of file RooJSONFactoryWSTool.cxx.

◆ fillSeq()

void RooJSONFactoryWSTool::fillSeq ( RooFit::Detail::JSONNode node,
RooAbsCollection const &  coll 
)
static

Definition at line 604 of file RooJSONFactoryWSTool.cxx.

◆ findNamedChild()

JSONNode const * RooJSONFactoryWSTool::findNamedChild ( RooFit::Detail::JSONNode const &  node,
std::string const &  name 
)
static

Definition at line 625 of file RooJSONFactoryWSTool.cxx.

◆ getRooFitInternal()

template<typename... Keys_t>
static RooFit::Detail::JSONNode & RooJSONFactoryWSTool::getRooFitInternal ( RooFit::Detail::JSONNode node,
Keys_t const &...  keys 
)
inlinestatic

Definition at line 171 of file RooJSONFactoryWSTool.h.

◆ importAllNodes()

void RooJSONFactoryWSTool::importAllNodes ( const RooFit::Detail::JSONNode n)
private

Definition at line 1531 of file RooJSONFactoryWSTool.cxx.

◆ importDependants()

void RooJSONFactoryWSTool::importDependants ( const RooFit::Detail::JSONNode n)
private

Definition at line 1268 of file RooJSONFactoryWSTool.cxx.

◆ importFunction() [1/2]

void RooJSONFactoryWSTool::importFunction ( const RooFit::Detail::JSONNode n,
bool  importAllDependants 
)

Definition at line 883 of file RooJSONFactoryWSTool.cxx.

◆ importFunction() [2/2]

void RooJSONFactoryWSTool::importFunction ( const std::string &  jsonString,
bool  importAllDependants 
)

Definition at line 971 of file RooJSONFactoryWSTool.cxx.

◆ importJSON() [1/2]

bool RooJSONFactoryWSTool::importJSON ( std::istream &  os)

Definition at line 1599 of file RooJSONFactoryWSTool.cxx.

◆ importJSON() [2/2]

bool RooJSONFactoryWSTool::importJSON ( std::string const &  filename)

Definition at line 1607 of file RooJSONFactoryWSTool.cxx.

◆ importJSONElement()

void RooJSONFactoryWSTool::importJSONElement ( const std::string &  name,
const std::string &  jsonString 
)

Definition at line 1640 of file RooJSONFactoryWSTool.cxx.

◆ importJSONfromString()

bool RooJSONFactoryWSTool::importJSONfromString ( const std::string &  s)

Definition at line 1434 of file RooJSONFactoryWSTool.cxx.

◆ importVariable()

void RooJSONFactoryWSTool::importVariable ( const RooFit::Detail::JSONNode n)
private

Definition at line 1242 of file RooJSONFactoryWSTool.cxx.

◆ importVariableElement()

void RooJSONFactoryWSTool::importVariableElement ( const RooFit::Detail::JSONNode n)

Definition at line 1658 of file RooJSONFactoryWSTool.cxx.

◆ importYML() [1/2]

bool RooJSONFactoryWSTool::importYML ( std::istream &  os)

Definition at line 1620 of file RooJSONFactoryWSTool.cxx.

◆ importYML() [2/2]

bool RooJSONFactoryWSTool::importYML ( std::string const &  filename)

Definition at line 1627 of file RooJSONFactoryWSTool.cxx.

◆ importYMLfromString()

bool RooJSONFactoryWSTool::importYMLfromString ( const std::string &  s)

Definition at line 1441 of file RooJSONFactoryWSTool.cxx.

◆ log()

std::ostream & RooJSONFactoryWSTool::log ( int  level)
static

Definition at line 1696 of file RooJSONFactoryWSTool.cxx.

◆ makeVariablesNode()

JSONNode & RooJSONFactoryWSTool::makeVariablesNode ( RooFit::Detail::JSONNode rootNode)
static

Definition at line 647 of file RooJSONFactoryWSTool.cxx.

◆ name()

std::string RooJSONFactoryWSTool::name ( const RooFit::Detail::JSONNode n)
static

Definition at line 642 of file RooJSONFactoryWSTool.cxx.

◆ queueExport()

void RooJSONFactoryWSTool::queueExport ( RooAbsArg const &  arg)
inline

Definition at line 183 of file RooJSONFactoryWSTool.h.

◆ readBinnedData() [1/2]

std::unique_ptr< RooDataHist > RooJSONFactoryWSTool::readBinnedData ( const RooFit::Detail::JSONNode n,
const std::string &  namecomp 
)
static

Definition at line 1164 of file RooJSONFactoryWSTool.cxx.

◆ readBinnedData() [2/2]

std::unique_ptr< RooDataHist > RooJSONFactoryWSTool::readBinnedData ( const RooFit::Detail::JSONNode n,
const std::string &  namecomp,
RooArgList const &  varlist 
)
static

Definition at line 1197 of file RooJSONFactoryWSTool.cxx.

◆ request()

template<class T >
T * RooJSONFactoryWSTool::request ( const std::string &  objname,
const std::string &  requestAuthor 
)
inline

Definition at line 61 of file RooJSONFactoryWSTool.h.

◆ requestArg()

template<class T >
T * RooJSONFactoryWSTool::requestArg ( const RooFit::Detail::JSONNode node,
const std::string &  key 
)
inline

Definition at line 70 of file RooJSONFactoryWSTool.h.

◆ requestArgList()

template<class T >
RooArgList RooJSONFactoryWSTool::requestArgList ( const RooFit::Detail::JSONNode node,
const std::string &  seqName 
)
inline

Definition at line 104 of file RooJSONFactoryWSTool.h.

◆ requestArgSet()

template<class T >
RooArgSet RooJSONFactoryWSTool::requestArgSet ( const RooFit::Detail::JSONNode node,
const std::string &  seqName 
)
inline

Definition at line 98 of file RooJSONFactoryWSTool.h.

◆ requestCollection()

template<class T , class Coll_t >
Coll_t RooJSONFactoryWSTool::requestCollection ( const RooFit::Detail::JSONNode node,
const std::string &  seqName 
)
inline

Definition at line 80 of file RooJSONFactoryWSTool.h.

◆ requestImpl() [1/4]

template<class T >
T * RooJSONFactoryWSTool::requestImpl ( const std::string &  objname)
private

◆ requestImpl() [2/4]

template<>
RooRealVar * RooJSONFactoryWSTool::requestImpl ( const std::string &  objname)
private

Definition at line 653 of file RooJSONFactoryWSTool.cxx.

◆ requestImpl() [3/4]

template<>
RooAbsPdf * RooJSONFactoryWSTool::requestImpl ( const std::string &  objname)
private

Definition at line 668 of file RooJSONFactoryWSTool.cxx.

◆ requestImpl() [4/4]

template<>
RooAbsReal * RooJSONFactoryWSTool::requestImpl ( const std::string &  objname)
private

Definition at line 683 of file RooJSONFactoryWSTool.cxx.

◆ workspace()

RooWorkspace * RooJSONFactoryWSTool::workspace ( )
inline

Definition at line 109 of file RooJSONFactoryWSTool.h.

◆ wsEmplace()

template<class Obj_t , typename... Args_t>
Obj_t & RooJSONFactoryWSTool::wsEmplace ( RooStringView  name,
Args_t &&...  args 
)
inline

Definition at line 119 of file RooJSONFactoryWSTool.h.

◆ wsImport()

template<class Obj_t >
Obj_t & RooJSONFactoryWSTool::wsImport ( Obj_t const &  obj)
inline

Definition at line 112 of file RooJSONFactoryWSTool.h.

Member Data Documentation

◆ _attributesNode

const RooFit::Detail::JSONNode* RooJSONFactoryWSTool::_attributesNode = nullptr
private

Definition at line 213 of file RooJSONFactoryWSTool.h.

◆ _domains

std::unique_ptr<RooFit::JSONIO::Detail::Domains> RooJSONFactoryWSTool::_domains
private

Definition at line 219 of file RooJSONFactoryWSTool.h.

◆ _rootnodeInput

const RooFit::Detail::JSONNode* RooJSONFactoryWSTool::_rootnodeInput = nullptr
private

Definition at line 212 of file RooJSONFactoryWSTool.h.

◆ _rootnodeOutput

RooFit::Detail::JSONNode* RooJSONFactoryWSTool::_rootnodeOutput = nullptr
private

Definition at line 214 of file RooJSONFactoryWSTool.h.

◆ _serversToExport

std::vector<RooAbsArg const *> RooJSONFactoryWSTool::_serversToExport
private

Definition at line 220 of file RooJSONFactoryWSTool.h.

◆ _varsNode

RooFit::Detail::JSONNode* RooJSONFactoryWSTool::_varsNode = nullptr
private

Definition at line 215 of file RooJSONFactoryWSTool.h.

◆ _workspace

RooWorkspace& RooJSONFactoryWSTool::_workspace
private

Definition at line 216 of file RooJSONFactoryWSTool.h.

◆ useListsInsteadOfDicts

constexpr bool RooJSONFactoryWSTool::useListsInsteadOfDicts = true
staticconstexpr

Definition at line 40 of file RooJSONFactoryWSTool.h.

Libraries for RooJSONFactoryWSTool:

The documentation for this class was generated from the following files: