14#ifndef RooFit_Detail_CodeSquashContext_h
15#define RooFit_Detail_CodeSquashContext_h
28#include <unordered_map>
35namespace Experimental {
75 void addToCodeBody(std::string
const &in,
bool isScopeIndep =
false);
80 template <
typename... Args_t>
81 std::string
buildCall(std::string
const &funcname, Args_t
const &...args)
84 ss << funcname <<
"(" <<
buildArgs(args...) <<
")";
99 std::vector<TNamed const *>
const &
vars()
const {
return _vars; }
103 const std::vector<TNamed const *>
_vars;
112 std::string
buildArg(std::span<const double> arr);
127 template <
class T,
typename std::enable_if<std::is_
floating_po
int<T>{},
bool>::type = true>
134 template <
class T,
typename std::enable_if<std::is_
integral<T>{},
bool>::type = true>
137 return std::to_string(
x);
142 std::string
buildArg(std::nullptr_t) {
return "nullptr"; }
154 template <
class Arg_t>
160 template <
typename Arg_t,
typename... Args_t>
161 std::string
buildArgs(Arg_t
const &arg, Args_t
const &...args)
189 std::unordered_map<RooFit::UniqueId<RooAbsCollection>::Value_t, std::string>
listNames;
194inline std::string CodeSquashContext::typeName<double>()
const
199inline std::string CodeSquashContext::typeName<int>()
const
207 unsigned int n = arr.size();
209 std::string arrDecl = typeName<T>() +
" " + arrName +
"[" + std::to_string(
n) +
"] = {";
210 for (
unsigned int i = 0; i <
n; i++) {
211 arrDecl +=
" " + std::to_string(arr[i]) +
",";
213 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
LoopScope(CodeSquashContext &ctx, std::vector< TNamed const * > &&vars)
const std::vector< TNamed const * > _vars
A class to maintain the context for squashing of RooFit models into code.
std::string assembleCode(std::string const &returnExpr)
Assemble and return the final code with the return expression and global statements.
std::map< RooFit::Detail::DataKey, std::size_t > _nodeOutputSizes
Map of node output sizes.
std::string _tempScope
Stores code that eventually gets injected into main code body.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
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.
std::string typeName() const
std::string buildArg(std::string const &x)
void endLoop(LoopScope const &scope)
std::unordered_map< const TNamed *, int > _vecObsIndices
A map to keep track of the observable indices if they are non scalar.
int _loopLevel
The current number of for loops the started.
int _tmpVarIdx
Index to get unique names for temporary variables.
std::string buildArg(T x)
std::size_t outputSize(RooFit::Detail::DataKey key) const
Figure out the output size of a node.
std::unordered_map< const TNamed *, std::string > _nodeNames
Map of node names to their result strings.
void addToCodeBody(RooAbsArg const *klass, std::string const &in)
Adds the input string to the squashed code body.
void addVecObs(const char *key, int idx)
Since the squashed code represents all observables as a single flattened array, it is important to ke...
bool isScopeIndependent(RooAbsArg const *in) const
std::string getTmpVarName() const
Get a unique variable name to be used in the generated code.
std::string const & getResult(RooTemplateProxy< T > const &key)
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
std::string _code
Stores the squashed code body.
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::unordered_map< RooFit::UniqueId< RooAbsCollection >::Value_t, std::string > listNames
A map to keep track of list names as assigned by addResult.
std::string buildArgs(Arg_t const &arg, Args_t const &...args)
std::string buildArg(std::span< const int > arr)
std::string buildArg(RooAbsCollection const &x)
Function to save a RooListProxy as an array in the squashed code.
Experimental::RooFuncWrapper * _wrapper
std::string buildArgs(Arg_t const &arg)
std::string buildArgSpanImpl(std::span< const T > arr)
std::string buildArg(RooAbsArg const &arg)
int _scopePtr
Keeps track of the position to go back and insert code to.
std::string _globalScope
Block of code that is placed before the rest of the function body.
std::vector< double > & _xlArr
std::unique_ptr< LoopScope > beginLoop(RooAbsArg const *in)
Create a RAII scope for iterating over vector observables.
std::string buildArg(RooTemplateProxy< T > const &arg)
std::string buildArg(std::nullptr_t)
A wrapper class to store a C++ function of type 'double (*)(double*, double*)'.
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.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...