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.
In order to import a workspace from a JSON file, you can do
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Similarly, in order to export a workspace to a JSON file, you can do
Analogously, in C++, you can do
tool.importJSON(
"myjson.json");
Persistable container for RooFit projects.
and
tool.exportJSON(
"myjson.json");
For more details, consult the tutorial rf515_hfJSON.
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 relevant section in the RooFit Developer Documentation to learn how to do that (Implement JSON I/O for a RooFit class with RooFit HS3).
You can always get a list of all the available importers and exporters by calling the following functions:
Alternatively, you can generate a LaTeX version of the available importers and exporters by calling
Definition at line 40 of file RooJSONFactoryWSTool.h.
|
| | RooJSONFactoryWSTool (RooWorkspace &ws) |
| |
| | ~RooJSONFactoryWSTool () |
| |
| void | exportCategory (RooAbsCategory const &cat, RooFit::Detail::JSONNode &node) |
| | Export a RooAbsCategory object to a JSONNode.
|
| |
| bool | exportJSON (std::ostream &os) |
| | Export the workspace to JSON format and write to the output stream.
|
| |
| bool | exportJSON (std::string const &fileName) |
| | Export the workspace to JSON format and write to the specified file.
|
| |
| std::string | exportJSONtoString () |
| | Export the workspace to a JSON string.
|
| |
| std::string | exportTransformed (const RooAbsReal *original, const std::string &suffix, const std::string &formula) |
| |
| std::string | getStringAttribute (const std::string &obj, const std::string &attrib) |
| |
| bool | hasAttribute (const std::string &obj, const std::string &attrib) |
| |
| void | importFunction (const RooFit::Detail::JSONNode &p, bool importAllDependants) |
| | Import a function from the JSONNode into the workspace.
|
| |
| void | importFunction (const std::string &jsonString, bool importAllDependants) |
| | Import a function from a JSON string into the workspace.
|
| |
| bool | importJSON (std::istream &os) |
| | Imports a JSON file from the given input stream to the workspace.
|
| |
| bool | importJSON (std::string const &filename) |
| | Imports a JSON file from the given filename to the workspace.
|
| |
| void | importJSONElement (const std::string &name, const std::string &jsonString) |
| |
| bool | importJSONfromString (const std::string &s) |
| | Import the workspace from a JSON string.
|
| |
| void | importVariableElement (const RooFit::Detail::JSONNode &n) |
| |
| void | queueExport (RooAbsArg const &arg) |
| |
| void | queueExportTemporary (RooAbsArg *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) |
| |
| void | setAttribute (const std::string &obj, const std::string &attrib) |
| |
| void | setStringAttribute (const std::string &obj, const std::string &attrib, const std::string &value) |
| |
| 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 RooFit::Detail::JSONNode & | appendNamedChild (RooFit::Detail::JSONNode &node, std::string const &name) |
| |
| static RooWorkspace | cleanWS (const RooWorkspace &ws, bool onlyModelConfig=false) |
| |
| static Config & | config () |
| |
| static std::unique_ptr< RooFit::Detail::JSONTree > | createNewJSONTree () |
| | Create a new JSON tree with version information.
|
| |
| static void | error (const char *s) |
| | Writes an error message to the RooFit message service and throws a runtime_error.
|
| |
| static void | error (const std::string &s) |
| |
| static void | exportArray (std::size_t n, double const *contents, RooFit::Detail::JSONNode &output) |
| | Export an array of doubles to a JSONNode.
|
| |
| static void | exportAxis (RooFit::Detail::JSONNode &obsNode, RooRealVar const &var) |
| | Export the name and binning of a RooRealVar to a JSONNode.
|
| |
| static void | exportHisto (RooArgSet const &vars, std::size_t n, double const *contents, RooFit::Detail::JSONNode &output) |
| | Export histogram data to a JSONNode.
|
| |
| static void | fillSeq (RooFit::Detail::JSONNode &node, RooAbsCollection const &coll, size_t nMax=-1) |
| |
| 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 bool | isValidName (const std::string &str) |
| | Check if a string is a valid name.
|
| |
| static RooFit::Detail::JSONNode & | makeVariablesNode (RooFit::Detail::JSONNode &rootNode) |
| |
| static std::string | name (const RooFit::Detail::JSONNode &n) |
| |
| static RooArgSet | readAxes (const RooFit::Detail::JSONNode &node) |
| | Read axes from the JSONNode and create a RooArgSet representing them.
|
| |
| static std::unique_ptr< RooDataHist > | readBinnedData (const RooFit::Detail::JSONNode &n, const std::string &namecomp, RooArgSet const &vars) |
| | Read binned data from the JSONNode and create a RooDataHist object.
|
| |
| static void | rebuildModelConfigInWorkspace (RooStats::ModelConfig *mc, RooWorkspace &ws) |
| |
| static std::string | sanitizeName (const std::string str) |
| | Cleans up names to the HS3 standard.
|
| |
| static RooWorkspace | sanitizeWS (const RooWorkspace &ws) |
| |
| static bool | testValidName (const std::string &str, bool forcError) |
| |
| static std::ostream & | warning (const std::string &s) |
| | Writes a warning message to the RooFit message service.
|
| |
|
| 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 > &combined, const std::vector< RooAbsData * > &single) |
| |
| void | exportObject (RooAbsArg const &func, std::set< std::string > &exportedObjectNames) |
| |
| template<class T > |
| void | exportObjects (T const &args, 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, bool storeConstant, bool storeBins) |
| |
| void | exportVariables (const RooArgSet &allElems, RooFit::Detail::JSONNode &n, bool storeConstant, bool storeBins) |
| |
| void | importAllNodes (const RooFit::Detail::JSONNode &n) |
| |
| void | importDependants (const RooFit::Detail::JSONNode &n) |
| |
| void | importVariable (const RooFit::Detail::JSONNode &p) |
| |
| template<class T > |
| T * | requestImpl (const std::string &objname) |
| |
| template<> |
| RooRealVar * | requestImpl (const std::string &objname) |
| |
| template<> |
| RooAbsPdf * | requestImpl (const std::string &objname) |
| |
| template<> |
| RooAbsReal * | requestImpl (const std::string &objname) |
| |