Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include "JSONParser.h"
16
17#include <sstream>
18
19namespace {
20template <class Node_t>
21class ChildItImpl final : public RooFit::Detail::JSONNode::child_iterator_t<Node_t>::Impl {
22public:
24 ChildItImpl(Node_t &n, size_t p) : node(n), pos(p) {}
25 ChildItImpl(const ChildItImpl &other) : node(other.node), pos(other.pos) {}
26 std::unique_ptr<typename child_iterator::Impl> clone() const override
27 {
28 return std::make_unique<ChildItImpl>(node, pos);
29 }
30 void forward() override { ++pos; }
31 void backward() override { --pos; }
32 Node_t &current() override { return node.child(pos); }
33 bool equal(const typename child_iterator::Impl &other) const override
34 {
35 auto it = dynamic_cast<const ChildItImpl<Node_t> *>(&other);
36 return it && &(it->node) == &(this->node) && (it->pos) == this->pos;
37 }
38
39private:
40 Node_t &node;
41 size_t pos;
42};
43} // namespace
44
45namespace RooFit {
46namespace Detail {
47
48template class JSONNode::child_iterator_t<JSONNode>;
49template class JSONNode::child_iterator_t<const JSONNode>;
50
52{
53 double out;
54 std::stringstream ss{val()};
55 ss >> out;
56 return out;
57}
58
60{
61 return {child_iterator(std::make_unique<::ChildItImpl<JSONNode>>(*this, 0)),
62 child_iterator(std::make_unique<::ChildItImpl<JSONNode>>(*this, this->num_children()))};
63}
69
70std::ostream &operator<<(std::ostream &os, JSONNode const &s)
71{
72 s.writeJSON(os);
73 return os;
74}
75
76template <typename... Args>
77std::unique_ptr<JSONTree> JSONTree::createImpl(Args &&...args)
78{
79 return std::make_unique<TJSONTree>(std::forward<Args>(args)...);
80}
81
82std::unique_ptr<JSONTree> JSONTree::create()
83{
84 return createImpl();
85}
86
87std::unique_ptr<JSONTree> JSONTree::create(std::istream &is)
88{
89 return createImpl(is);
90}
91
92std::unique_ptr<JSONTree> JSONTree::create(std::string const &str)
93{
94 std::stringstream ss{str};
95 return JSONTree::create(ss);
96}
97
98} // namespace Detail
99} // namespace RooFit
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
virtual std::string val() const =0
virtual double val_double() const
child_iterator_t< JSONNode > child_iterator
virtual children_view children()
virtual size_t num_children() const =0
virtual void writeJSON(std::ostream &os) const =0
child_iterator_t< const JSONNode > const_child_iterator
static std::unique_ptr< JSONTree > create()
static std::unique_ptr< JSONTree > createImpl(Args &&...args)
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 CodegenImpl.h:72
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
void backward(LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
backward application of the weights (back-propagation of the error)