Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
JSONIO.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Carsten D. Burgard, DESY/ATLAS, Dec 2021
5 *
6 * Copyright (c) 2022, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef RooFitHS3_JSONIO_h
14#define RooFitHS3_JSONIO_h
15
16#include <map>
17#include <memory>
18#include <string>
19#include <vector>
20
21class RooAbsArg;
23
24class TClass;
25
26namespace RooFit {
27namespace Detail {
28class JSONNode;
29class JSONTree;
30} // namespace Detail
31
32namespace JSONIO {
33
34class Importer {
35public:
36 virtual ~Importer() {}
37 virtual bool importArg(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
38 {
39 return importFunction(tool, node);
40 }
41 // These two functions importPdf() and importFunction() are supposed to get
42 // deprecated at some point, and get superseded by the general importArg().
43 // The reason for having these functions call each other in a loop by
44 // default is backwards compatibility: no matter which function is
45 // overridden, it will be called eventually.
46 virtual bool importFunction(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
47 {
48 return importPdf(tool, node);
49 }
50 virtual bool importPdf(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
51 {
52 return importArg(tool, node);
53 }
54};
55class Exporter {
56public:
57 virtual std::string const &key() const = 0;
58 virtual bool autoExportDependants() const { return true; }
60 {
61 return false;
62 }
63 virtual ~Exporter() {}
64};
65struct ExportKeys {
66 std::string type;
67 std::map<std::string, std::string> proxies;
68};
70 TClass const *tclass = nullptr;
71 std::vector<std::string> arguments;
72};
73
74using ImportMap = std::map<const std::string, std::vector<std::unique_ptr<const Importer>>>;
75using ExportMap = std::map<TClass const *, std::vector<std::unique_ptr<const Exporter>>>;
76using ExportKeysMap = std::map<TClass const *, ExportKeys>;
77using ImportExpressionMap = std::map<const std::string, ImportExpression>;
78
79void setupKeys();
84
85template <class T>
86static bool registerImporter(const std::string &key, bool topPriority = true)
87{
88 return registerImporter(key, std::make_unique<T>(), topPriority);
89}
90template <class T>
91static bool registerExporter(const TClass *key, bool topPriority = true)
92{
93 return registerExporter(key, std::make_unique<T>(), topPriority);
94}
95
96bool registerImporter(const std::string &key, std::unique_ptr<const Importer> f, bool topPriority = true);
97bool registerExporter(const TClass *key, std::unique_ptr<const Exporter> f, bool topPriority = true);
98int removeImporters(const std::string &needle);
99int removeExporters(const std::string &needle);
100void printImporters();
101void printExporters();
102
103void loadFactoryExpressions(const std::string &fname);
106void loadExportKeys(const std::string &fname);
107void clearExportKeys();
108void printExportKeys();
109
110} // namespace JSONIO
111
112} // namespace RooFit
113
114#endif
#define f(i)
Definition RSha256.hxx:104
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
virtual bool autoExportDependants() const
Definition JSONIO.h:58
virtual std::string const & key() const =0
virtual bool exportObject(RooJSONFactoryWSTool *, const RooAbsArg *, RooFit::Detail::JSONNode &) const
Definition JSONIO.h:59
virtual bool importPdf(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
Definition JSONIO.h:50
virtual bool importFunction(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
Definition JSONIO.h:46
virtual bool importArg(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
Definition JSONIO.h:37
When using RooFit, statistical models can be conveniently handled and stored as a RooWorkspace.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
ImportMap & importers()
Definition JSONIO.cxx:42
ExportMap & exporters()
Definition JSONIO.cxx:48
static bool registerImporter(const std::string &key, bool topPriority=true)
Definition JSONIO.h:86
void loadFactoryExpressions(const std::string &fname)
Definition JSONIO.cxx:135
std::map< const std::string, ImportExpression > ImportExpressionMap
Definition JSONIO.h:77
std::map< TClass const *, ExportKeys > ExportKeysMap
Definition JSONIO.h:76
ImportExpressionMap & importExpressions()
Definition JSONIO.cxx:54
void loadExportKeys(const std::string &fname)
Definition JSONIO.cxx:197
static bool registerExporter(const TClass *key, bool topPriority=true)
Definition JSONIO.h:91
void clearExportKeys()
Definition JSONIO.cxx:236
void clearFactoryExpressions()
Definition JSONIO.cxx:174
int removeImporters(const std::string &needle)
Definition JSONIO.cxx:82
int removeExporters(const std::string &needle)
Definition JSONIO.cxx:98
std::map< TClass const *, std::vector< std::unique_ptr< const Exporter > > > ExportMap
Definition JSONIO.h:75
void printExporters()
Definition JSONIO.cxx:124
std::map< const std::string, std::vector< std::unique_ptr< const Importer > > > ImportMap
Definition JSONIO.h:74
void printImporters()
Definition JSONIO.cxx:114
void printFactoryExpressions()
Definition JSONIO.cxx:180
void printExportKeys()
Definition JSONIO.cxx:242
void setupKeys()
Definition JSONIO.cxx:28
ExportKeysMap & exportKeys()
Definition JSONIO.cxx:61
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
std::map< std::string, std::string > proxies
Definition JSONIO.h:67
std::vector< std::string > arguments
Definition JSONIO.h:71