Logo ROOT  
Reference Guide
JSONInterface.cxx
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
14
15#ifdef ROOFIT_WITH_RYML
16#include "RYMLParser.h"
17using Tree_t = TRYMLTree;
18#else
19#include "JSONParser.h"
21#endif
22
23namespace {
24template <class Nd>
25class ChildItImpl final : public RooFit::Detail::JSONNode::child_iterator_t<Nd>::Impl {
26public:
28 ChildItImpl(Nd &n, size_t p) : node(n), pos(p) {}
29 ChildItImpl(const ChildItImpl &other) : node(other.node), pos(other.pos) {}
30 std::unique_ptr<typename child_iterator::Impl> clone() const override
31 {
32 return std::make_unique<ChildItImpl>(node, pos);
33 }
34 void forward() override { ++pos; }
35 void backward() override { --pos; }
36 Nd &current() override { return node.child(pos); }
37 bool equal(const typename child_iterator::Impl &other) const override
38 {
39 auto it = dynamic_cast<const ChildItImpl<Nd> *>(&other);
40 return it && &(it->node) == &(this->node) && (it->pos) == this->pos;
41 }
42
43private:
44 Nd &node;
45 size_t pos;
46};
47} // namespace
48
49namespace RooFit {
50namespace Detail {
51
52template class JSONNode::child_iterator_t<JSONNode>;
53template class JSONNode::child_iterator_t<const JSONNode>;
54
56{
57 return {child_iterator(std::make_unique<::ChildItImpl<JSONNode>>(*this, 0)),
58 child_iterator(std::make_unique<::ChildItImpl<JSONNode>>(*this, this->num_children()))};
59}
61{
62 return {const_child_iterator(std::make_unique<::ChildItImpl<const JSONNode>>(*this, 0)),
63 const_child_iterator(std::make_unique<::ChildItImpl<const JSONNode>>(*this, this->num_children()))};
64}
65
66std::ostream &operator<<(std::ostream &os, JSONNode const &s)
67{
68 s.writeJSON(os);
69 return os;
70}
71
72template <>
73int JSONNode::val_t<int>() const
74{
75 return val_int();
76}
77template <>
78float JSONNode::val_t<float>() const
79{
80 return val_float();
81}
82template <>
83double JSONNode::val_t<double>() const
84{
85 return val_float();
86}
87template <>
88bool JSONNode::val_t<bool>() const
89{
90 return val_bool();
91}
92template <>
93std::string JSONNode::val_t<std::string>() const
94{
95 return val();
96}
97
98std::unique_ptr<JSONTree> JSONTree::create()
99{
100 return std::make_unique<Tree_t>();
101}
102
103std::unique_ptr<JSONTree> JSONTree::create(std::istream &is)
104{
105 return std::make_unique<Tree_t>(is);
106}
107
108} // namespace Detail
109} // namespace RooFit
winID h TVirtualViewer3D TVirtualGLPainter p
virtual bool val_bool() const
child_iterator_t< JSONNode > child_iterator
Definition: JSONInterface.h:64
virtual children_view children()
virtual size_t num_children() const =0
virtual float val_float() const
virtual int val_int() const
child_iterator_t< const JSONNode > const_child_iterator
Definition: JSONInterface.h:65
static std::unique_ptr< JSONTree > create()
const Int_t n
Definition: legend1.C:16
std::ostream & operator<<(std::ostream &os, RooFit::Detail::JSONNode const &s)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
static constexpr double s
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
Definition: NeuralNet.icc:546
void backward(LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
backward application of the weights (back-propagation of the error)
Definition: NeuralNet.icc:572