6bool startsWith(std::string_view str, std::string_view prefix)
8 return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
11bool endsWith(std::string_view str, std::string_view suffix)
13 return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
18 std::string varName = treeRoot.
find(
"name")->
val();
22 bool isConstant =
false;
25 if (
auto n = treeRoot.
find(
"value")) {
26 val =
n->val_double();
30 auto maxNode = treeRoot.
find(
"max");
31 auto minNode = treeRoot.
find(
"min");
32 if (maxNode && minNode) {
33 maxVal = maxNode->val_double();
34 minVal = minNode->val_double();
38 val = (maxVal + minVal) / 2;
41 if (!isConstant && !isRange) {
42 throw std::invalid_argument(
"Invalid Syntax: Please provide either 'value' or 'min' and 'max' or both");
46 JSONNode &
n = jsonDict->rootnode().set_map();
47 JSONNode &_domains =
n[
"domains"].set_seq().append_child().set_map();
48 JSONNode &_parameterPoints =
n[
"parameter_points"].set_seq().append_child().set_map();
50 _domains[
"name"] <<
"default_domain";
51 _domains[
"type"] <<
"product_domain";
53 _axes[
"name"] << varName;
55 _parameterPoints[
"name"] <<
"default_values";
57 _parameters[
"name"] << varName;
58 _parameters[
"value"] << val;
61 _axes[
"max"] << maxVal;
62 _axes[
"min"] << minVal;
65 if (isConstant && !isRange) {
66 _parameters[
"const"] <<
true;
70 _var[
"tags"] <<
"Constant";
std::unique_ptr< RooFit::Detail::JSONTree > varJSONString(const JSONNode &treeRoot)
bool startsWith(std::string_view str, std::string_view prefix)
bool endsWith(std::string_view str, std::string_view suffix)
virtual std::string val() const =0
virtual JSONNode & set_map()=0
virtual JSONNode & append_child()=0
virtual JSONNode & set_seq()=0
JSONNode const * find(std::string const &key) const
static std::unique_ptr< JSONTree > create()