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};
65
66using ImportMap = std::map<const std::string, std::vector<std::unique_ptr<const Importer>>>;
67using ExportMap = std::map<TClass const *, std::vector<std::unique_ptr<const Exporter>>>;
68
71
72template <class T>
73static bool registerImporter(const std::string &key, bool topPriority = true)
74{
75 return registerImporter(key, std::make_unique<T>(), topPriority);
76}
77template <class T>
78static bool registerExporter(const TClass *key, bool topPriority = true)
79{
80 return registerExporter(key, std::make_unique<T>(), topPriority);
81}
82template <class T>
83static bool registerExporter(const std::string &key, bool topPriority = true)
84{
85 return registerExporter(key, std::make_unique<T>(), topPriority);
86}
87
88bool registerImporter(const std::string &key, std::unique_ptr<const Importer> f, bool topPriority = true);
89bool registerExporter(const TClass *key, std::unique_ptr<const Exporter> f, bool topPriority = true);
90bool registerExporter(const std::string &key, std::unique_ptr<const Exporter> f, bool topPriority = true);
91int removeImporters(const std::string &needle);
92int removeExporters(const std::string &needle);
93void printImporters();
94void printExporters();
95
96} // namespace JSONIO
97
98} // namespace RooFit
99
100#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:84
ImportMap & importers()
Definition JSONIO.cxx:23
ExportMap & exporters()
Definition JSONIO.cxx:45
static bool registerImporter(const std::string &key, bool topPriority=true)
Definition JSONIO.h:73
static bool registerExporter(const TClass *key, bool topPriority=true)
Definition JSONIO.h:78
int removeImporters(const std::string &needle)
Definition JSONIO.cxx:132
int removeExporters(const std::string &needle)
Definition JSONIO.cxx:137
std::map< TClass const *, std::vector< std::unique_ptr< const Exporter > > > ExportMap
Definition JSONIO.h:67
void printExporters()
Definition JSONIO.cxx:146
void printImporters()
Definition JSONIO.cxx:142
std::map< const std::string, std::vector< std::unique_ptr< const Importer > > > ImportMap
Definition JSONIO.h:66
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73