8bool startsWith(std::string_view str, std::string_view prefix)
10 return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
13bool endsWith(std::string_view str, std::string_view suffix)
15 return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
18std::string
removePrefix(std::string_view str, std::string_view prefix)
22 out = out.substr(prefix.length());
25std::string
removeSuffix(std::string_view str, std::string_view suffix)
29 out = out.substr(0, out.length() - suffix.length());
35 std::string varName = treeRoot.
find(
"name")->
val();
39 bool isConstant =
false;
42 if (
auto n = treeRoot.
find(
"value")) {
43 val =
n->val_double();
47 auto maxNode = treeRoot.
find(
"max");
48 auto minNode = treeRoot.
find(
"min");
49 if (maxNode && minNode) {
50 maxVal = maxNode->val_double();
51 minVal = minNode->val_double();
55 val = (maxVal + minVal) / 2;
58 if (!isConstant && !isRange) {
59 throw std::invalid_argument(
"Invalid Syntax: Please provide either 'value' or 'min' and 'max' or both");
63 JSONNode &
n = jsonDict->rootnode().set_map();
64 JSONNode &_domains =
n[
"domains"].set_seq().append_child().set_map();
65 JSONNode &_parameterPoints =
n[
"parameter_points"].set_seq().append_child().set_map();
67 _domains[
"name"] <<
"default_domain";
68 _domains[
"type"] <<
"product_domain";
70 _axes[
"name"] << varName;
72 _parameterPoints[
"name"] <<
"default_values";
74 _parameters[
"name"] << varName;
75 _parameters[
"value"] << val;
78 _axes[
"max"] << maxVal;
79 _axes[
"min"] << minVal;
82 if (isConstant && !isRange) {
83 _parameters[
"const"] <<
true;
87 _var[
"tags"] <<
"Constant";
std::unique_ptr< RooFit::Detail::JSONTree > varJSONString(const JSONNode &treeRoot)
std::string removePrefix(std::string_view str, std::string_view prefix)
bool startsWith(std::string_view str, std::string_view prefix)
bool endsWith(std::string_view str, std::string_view suffix)
std::string removeSuffix(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()