14#ifndef RooFit_Detail_CodegenContext_h
15#define RooFit_Detail_CodegenContext_h
27#include <unordered_map>
28#include <unordered_set>
38 static_assert(P >= 1 && P <= 10,
"P must be 1 <= P <= 10!");
49 void addResult(
const char *key, std::string
const &value);
65 void addToCodeBody(std::string
const &in,
bool isScopeIndep =
false);
70 template <
typename... Args_t>
71 std::string
buildCall(std::string
const &funcname, Args_t
const &...args)
74 ss << funcname <<
"(" <<
buildArgs(args...) <<
")";
89 std::vector<TNamed const *>
const &
vars()
const {
return _vars; }
93 const std::vector<TNamed const *>
_vars;
102 std::string
buildArg(std::span<const double> arr);
134 void endLoop(LoopScope
const &scope);
138 template <
class T,
typename std::enable_if<std::is_
floating_po
int<T>{},
bool>::type = true>
141 std::stringstream ss;
142 ss << std::setprecision(std::numeric_limits<double>::max_digits10) <<
x;
147 template <
class T,
typename std::enable_if<std::is_
integral<T>{},
bool>::type = true>
150 return std::to_string(
x);
155 std::string
buildArg(std::nullptr_t) {
return "nullptr"; }
167 template <
class Arg_t>
173 template <
typename Arg_t,
typename... Args_t>
174 std::string
buildArgs(Arg_t
const &arg, Args_t
const &...args)
195 std::unordered_map<RooFit::UniqueId<RooAbsCollection>::Value_t, std::string>
_listNames;
215 unsigned int n = arr.size();
217 std::stringstream ss;
218 ss << typeName<T>() <<
" " << arrName <<
"[" <<
n <<
"] = {";
219 for (
unsigned int i = 0; i <
n; i++) {
220 ss <<
" " << arr[i] <<
",";
222 std::string arrDecl = ss.str();
223 arrDecl.back() =
'}';
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Abstract container object that can hold multiple RooAbsArg objects.
std::vector< TNamed const * > const & vars() const
const std::vector< TNamed const * > _vars
LoopScope(CodegenContext &ctx, std::vector< TNamed const * > &&vars)
A class to maintain the context for squashing of RooFit models into code.
std::string buildArgs(Arg_t const &arg)
std::unordered_map< RooFit::UniqueId< RooAbsCollection >::Value_t, std::string > _listNames
A map to keep track of list names as assigned by addResult.
void addToGlobalScope(std::string const &str)
Adds the given string to the string block that will be emitted at the top of the squashed function.
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
std::string getTmpVarName() const
Get a unique variable name to be used in the generated code.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
void addToCodeBody(RooAbsArg const *klass, std::string const &in)
Adds the input string to the squashed code body.
std::unique_ptr< LoopScope > beginLoop(RooAbsArg const *in)
Create a RAII scope for iterating over vector observables.
std::string const & getResult(RooTemplateProxy< T > const &key)
void collectFunction(std::string const &name)
Register a function that is only know to the interpreter to the context.
std::string buildArg(std::string const &x)
std::vector< double > _xlArr
void addVecObs(const char *key, int idx)
Since the squashed code represents all observables as a single flattened array, it is important to ke...
std::unordered_map< const TNamed *, int > _vecObsIndices
A map to keep track of the observable indices if they are non scalar.
int observableIndexOf(const RooAbsArg &arg) const
std::string buildArg(RooAbsCollection const &x, std::string const &arrayType="double")
Function to save a RooListProxy as an array in the squashed code.
void endLoop(LoopScope const &scope)
std::unordered_set< RooFit::Detail::DataKey > _dependsOnData
Indicate whether a node depends on the dataset.
std::vector< std::string > _collectedFunctions
std::string _collectedCode
bool isScopeIndependent(RooAbsArg const *in) const
std::string buildArg(T x)
std::string typeName() const
std::vector< std::string > _code
The code layered by lexical scopes used as a stack.
std::string buildArgSpanImpl(std::span< const T > arr)
unsigned _indent
The indentation level for pretty-printing.
std::string buildFunction(RooAbsArg const &arg, std::unordered_set< RooFit::Detail::DataKey > const &dependsOnData={})
Assemble and return the final code with the return expression and global statements.
std::string buildArg(std::span< const int > arr)
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
std::string buildArg(std::nullptr_t)
std::vector< std::string > const & collectedFunctions()
std::string const & collectedCode()
std::unordered_map< const TNamed *, std::string > _nodeNames
Map of node names to their result strings.
auto const & dependsOnData() const
ScopeRAII OutputScopeRangeComment(RooAbsArg const *arg)
std::string buildArg(RooTemplateProxy< T > const &arg)
int _tmpVarIdx
Index to get unique names for temporary variables.
std::vector< double > const & xlArr()
std::string buildArg(RooAbsArg const &arg)
std::string buildArgs(Arg_t const &arg, Args_t const &...args)
const T & arg() const
Return reference to object held in proxy.
The TNamed class is the base class for all named ROOT classes.
void declareDispatcherCode(std::string const &funcName)
void codegen(RooAbsArg &arg, CodegenContext &ctx)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
ScopeRAII(RooAbsArg const *arg, CodegenContext &ctx)