File indexing completed on 2026-09-21 09:25:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RooFitHS3_JSONIO_h
0014 #define RooFitHS3_JSONIO_h
0015
0016 #include <map>
0017 #include <memory>
0018 #include <string>
0019 #include <vector>
0020
0021 class RooAbsArg;
0022 class RooJSONFactoryWSTool;
0023
0024 class TClass;
0025
0026 namespace RooFit {
0027 namespace Detail {
0028 class JSONNode;
0029 class JSONTree;
0030 }
0031
0032 namespace JSONIO {
0033
0034 class Importer {
0035 public:
0036 virtual ~Importer() {}
0037 virtual bool importArg(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
0038 {
0039 return importFunction(tool, node);
0040 }
0041
0042
0043
0044
0045
0046 virtual bool importFunction(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
0047 {
0048 return importPdf(tool, node);
0049 }
0050 virtual bool importPdf(RooJSONFactoryWSTool *tool, const RooFit::Detail::JSONNode &node) const
0051 {
0052 return importArg(tool, node);
0053 }
0054 };
0055 class Exporter {
0056 public:
0057 virtual std::string const &key() const = 0;
0058 virtual bool autoExportDependants() const { return true; }
0059 virtual bool exportObject(RooJSONFactoryWSTool *, const RooAbsArg *, RooFit::Detail::JSONNode &) const
0060 {
0061 return false;
0062 }
0063 virtual ~Exporter() {}
0064 };
0065 struct ExportKeys {
0066 std::string type;
0067 std::map<std::string, std::string> proxies;
0068 };
0069 struct ImportExpression {
0070 TClass const *tclass = nullptr;
0071 std::vector<std::string> arguments;
0072 };
0073
0074 using ImportMap = std::map<const std::string, std::vector<std::unique_ptr<const Importer>>>;
0075 using ExportMap = std::map<TClass const *, std::vector<std::unique_ptr<const Exporter>>>;
0076 using ExportKeysMap = std::map<TClass const *, ExportKeys>;
0077 using ImportExpressionMap = std::map<const std::string, ImportExpression>;
0078
0079 ImportMap &importers();
0080 ExportMap &exporters();
0081 ImportExpressionMap &importExpressions();
0082 ExportKeysMap &exportKeys();
0083
0084 template <class T>
0085 static bool registerImporter(const std::string &key, bool topPriority = true)
0086 {
0087 return registerImporter(key, std::make_unique<T>(), topPriority);
0088 }
0089 template <class T>
0090 static bool registerExporter(const TClass *key, bool topPriority = true)
0091 {
0092 return registerExporter(key, std::make_unique<T>(), topPriority);
0093 }
0094 template <class T>
0095 static bool registerExporter(const std::string &key, bool topPriority = true)
0096 {
0097 return registerExporter(key, std::make_unique<T>(), topPriority);
0098 }
0099
0100 bool registerImporter(const std::string &key, std::unique_ptr<const Importer> f, bool topPriority = true);
0101 bool registerExporter(const TClass *key, std::unique_ptr<const Exporter> f, bool topPriority = true);
0102 bool registerExporter(const std::string &key, std::unique_ptr<const Exporter> f, bool topPriority = true);
0103 int removeImporters(const std::string &needle);
0104 int removeExporters(const std::string &needle);
0105 void printImporters();
0106 void printExporters();
0107
0108 void loadFactoryExpressions(std::istream &is);
0109 void loadFactoryExpressions(const std::string &fname);
0110 void clearFactoryExpressions();
0111 void printFactoryExpressions();
0112 void loadExportKeys(std::istream &is);
0113 void loadExportKeys(const std::string &fname);
0114 void clearExportKeys();
0115 void printExportKeys();
0116
0117 }
0118
0119 }
0120
0121 #endif