14#ifndef RooFit_Detail_CodegenContext_h
15#define RooFit_Detail_CodegenContext_h
28#include <unordered_map>
34namespace Experimental {
38 static_assert(P >= 1 && P <= 10,
"P must be 1 <= P <= 10!");
76 void addToCodeBody(std::string
const &in,
bool isScopeIndep =
false);
81 template <
typename... Args_t>
82 std::string
buildCall(std::string
const &funcname, Args_t
const &...args)
85 ss << funcname <<
"(" <<
buildArgs(args...) <<
")";
100 std::vector<TNamed const *>
const &
vars()
const {
return _vars; }
104 const std::vector<TNamed const *>
_vars;
113 std::string
buildArg(std::span<const double> arr);
145 void endLoop(LoopScope
const &scope);
149 template <
class T,
typename std::enable_if<std::is_
floating_po
int<T>{},
bool>::type = true>
156 template <
class T,
typename std::enable_if<std::is_
integral<T>{},
bool>::type = true>
159 return std::to_string(
x);
164 std::string
buildArg(std::nullptr_t) {
return "nullptr"; }
176 template <
class Arg_t>
182 template <
typename Arg_t,
typename... Args_t>
183 std::string
buildArgs(Arg_t
const &arg, Args_t
const &...args)
204 std::unordered_map<RooFit::UniqueId<RooAbsCollection>::Value_t, std::string>
_listNames;
210inline std::string CodegenContext::typeName<double>()
const
215inline std::string CodegenContext::typeName<int>()
const
223 unsigned int n = arr.size();
225 std::string arrDecl = typeName<T>() +
" " + arrName +
"[" + std::to_string(
n) +
"] = {";
226 for (
unsigned int i = 0; i <
n; i++) {
227 arrDecl +=
" " + std::to_string(arr[i]) +
",";
229 arrDecl.back() =
'}';
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Abstract container object that can hold multiple RooAbsArg objects.
A class to manage loop scopes using the RAII technique.
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.
auto const & outputSizes() const
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.
std::map< RooFit::Detail::DataKey, std::size_t > _nodeOutputSizes
Map of node output sizes.
std::string buildFunction(RooAbsArg const &arg, std::map< RooFit::Detail::DataKey, std::size_t > const &outputSizes={})
Assemble and return the final code with the return expression and global statements.
void endLoop(LoopScope const &scope)
std::vector< std::string > _collectedFunctions
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 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::unordered_map< const TNamed *, std::string > _nodeNames
Map of node names to their result strings.
std::size_t outputSize(RooFit::Detail::DataKey key) const
Figure out the output size of a node.
ScopeRAII OutputScopeRangeComment(RooAbsArg const *arg)
std::string buildArg(RooAbsCollection const &x)
Function to save a RooListProxy as an array in the squashed code.
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)
static std::string toString(double x)
Returns an std::to_string compatible number (i.e.
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...