File indexing completed on 2025-01-30 10:22:16
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 void setupKeys();
0080 ImportMap &importers();
0081 ExportMap &exporters();
0082 ImportExpressionMap &importExpressions();
0083 ExportKeysMap &exportKeys();
0084
0085 template <class T>
0086 static bool registerImporter(const std::string &key, bool topPriority = true)
0087 {
0088 return registerImporter(key, std::make_unique<T>(), topPriority);
0089 }
0090 template <class T>
0091 static bool registerExporter(const TClass *key, bool topPriority = true)
0092 {
0093 return registerExporter(key, std::make_unique<T>(), topPriority);
0094 }
0095
0096 bool registerImporter(const std::string &key, std::unique_ptr<const Importer> f, bool topPriority = true);
0097 bool registerExporter(const TClass *key, std::unique_ptr<const Exporter> f, bool topPriority = true);
0098 int removeImporters(const std::string &needle);
0099 int removeExporters(const std::string &needle);
0100 void printImporters();
0101 void printExporters();
0102
0103 void loadFactoryExpressions(const std::string &fname);
0104 void clearFactoryExpressions();
0105 void printFactoryExpressions();
0106 void loadExportKeys(const std::string &fname);
0107 void clearExportKeys();
0108 void printExportKeys();
0109
0110 }
0111
0112 }
0113
0114 #endif