13#ifndef RooFit_Detail_JSONInterface_h
14#define RooFit_Detail_JSONInterface_h
20#include <unordered_map>
37 virtual std::unique_ptr<Impl>
clone()
const = 0;
62 return !lhs.
it->equal(*rhs.
it);
66 return lhs.
it->equal(*rhs.
it);
70 std::unique_ptr<Impl>
it;
89 virtual void writeYML(std::ostream &)
const {
throw std::runtime_error(
"YML not supported"); }
107 virtual std::string
key()
const = 0;
108 virtual std::string
val()
const = 0;
109 virtual int val_int()
const {
return atoi(this->
val().c_str()); }
111 virtual bool val_bool()
const {
return atoi(this->
val().c_str()); }
128 template <
typename Collection>
132 for (
auto const &item : coll) {
137 template <
typename Collection>
142 for (
auto const &item : coll) {
150 template <
typename Collection,
typename TransformationFunc>
151 void fill_seq(Collection
const &coll, TransformationFunc func)
154 for (
auto const &item : coll) {
159 template <
typename Matrix>
163 for (
int i = 0; i < mat.
GetNrows(); ++i) {
166 for (
int j = 0; j < mat.
GetNcols(); ++j) {
167 row.append_child() << mat(i, j);
178 template <
typename... Keys_t>
192 template <
typename... Keys_t>
197 return next.get(keys...);
207 static std::unique_ptr<JSONTree>
create();
208 static std::unique_ptr<JSONTree>
create(std::istream &is);
209 static std::unique_ptr<JSONTree>
create(std::string
const &str);
222 template <
typename... Args>
223 static std::unique_ptr<JSONTree>
createImpl(Args &&...args);
231 for (
const auto &
e : cv) {
232 v.push_back(
e.val_t<T>());
240 for (
const auto &
e : cv) {
241 v.push_back(
e.val_t<T>());
250 throw std::runtime_error(
"node " +
n.key() +
" is not of sequence type!");
268template <
class Key,
class T,
class Hash,
class KeyEqual,
class Allocator>
273 for (
const auto &it :
m) {
274 n[it.first] << it.second;
279template <
class Key,
class T,
class Compare,
class Allocator>
283 for (
const auto &it :
m) {
284 n[it.first] << it.second;
290inline int JSONNode::val_t<int>()
const
295inline double JSONNode::val_t<double>()
const
300inline bool JSONNode::val_t<bool>()
const
305inline std::string JSONNode::val_t<std::string>()
const
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
virtual std::unique_ptr< Impl > clone() const =0
virtual bool equal(const Impl &other) const =0
virtual void backward()=0
child_iterator_t & operator--()
child_iterator_t & operator++()
child_iterator_t(std::unique_ptr< Impl > impl)
child_iterator_t(const child_iterator_t &other)
friend bool operator==(child_iterator_t const &lhs, child_iterator_t const &rhs)
std::unique_ptr< Impl > it
friend bool operator!=(child_iterator_t const &lhs, child_iterator_t const &rhs)
child_iterator_t< Nd > begin() const
children_view_t(child_iterator_t< Nd > const &b_, child_iterator_t< Nd > const &e_)
child_iterator_t< Nd > end() const
virtual JSONNode & operator<<(std::string const &s)=0
virtual bool val_bool() const
JSONNode & get(std::string const &key)
virtual std::string val() const =0
virtual const JSONNode & operator>>(std::string &v) const =0
void fill_seq(Collection const &coll, size_t nmax)
JSONNode & get(std::string const &key, Keys_t const &...keys)
void fill_seq(Collection const &coll)
virtual JSONNode & set_map()=0
virtual JSONNode & append_child()=0
JSONNode const * find(std::string const &key, Keys_t const &...keys) const
virtual JSONNode & operator<<(double d)=0
virtual children_view children()
virtual size_t num_children() const =0
virtual JSONNode & child(size_t pos)=0
virtual JSONNode & set_seq()=0
virtual bool is_container() const =0
virtual void writeJSON(std::ostream &os) const =0
virtual bool is_seq() const =0
virtual const JSONNode & operator[](std::string const &k) const =0
virtual JSONNode & operator<<(bool b)=0
virtual void writeYML(std::ostream &) const
virtual bool is_map() const =0
virtual bool has_child(std::string const &) const =0
virtual std::string key() const =0
JSONNode & operator<<(const char *s)
void fill_seq(Collection const &coll, TransformationFunc func)
virtual JSONNode & operator[](std::string const &k)=0
void fill_mat(Matrix const &mat)
virtual bool has_key() const =0
virtual const JSONNode & child(size_t pos) const =0
virtual double val_double() const
JSONNode const * find(std::string const &key) const
virtual bool has_val() const =0
virtual int val_int() const
virtual JSONNode & operator<<(int i)=0
static void setBackend(std::string const &name)
Set the library that serves as the backend for the JSON interface.
static Backend & getBackendEnum()
static std::unique_ptr< JSONTree > create()
static bool hasBackend(std::string const &name)
Check if ROOT was compiled with support for a certain JSON backend library.
static std::string getBackend()
Returns the name of the library that serves as the backend for the JSON interface,...
static std::unique_ptr< JSONTree > createImpl(Args &&...args)
virtual ~JSONTree()=default
virtual JSONNode & rootnode()=0
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...