14#ifndef RooFit_Detail_CodeSquashContext_h
15#define RooFit_Detail_CodeSquashContext_h
28#include <unordered_map>
35namespace Experimental {
81 template <
typename...
Args_t>
100 std::vector<TNamed const *>
const &
vars()
const {
return _vars; }
104 const std::vector<TNamed const *>
_vars;
130 template <
class T,
typename std::enable_if<std::is_
floating_po
int<T>{},
bool>::type = true>
137 template <
class T,
typename std::enable_if<std::is_
integral<T>{},
bool>::type = true>
140 return std::to_string(
x);
145 std::string
buildArg(std::nullptr_t) {
return "nullptr"; }
157 template <
class Arg_t>
192 std::unordered_map<RooFit::UniqueId<RooAbsCollection>::Value_t, std::string>
listNames;
197inline std::string CodeSquashContext::typeName<double>()
const
202inline std::string CodeSquashContext::typeName<int>()
const
210 unsigned int n =
arr.size();
213 for (
unsigned int i = 0; i <
n; i++) {
214 arrDecl +=
" " + std::to_string(
arr[i]) +
",";
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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)
void collectFunction(std::string const &name)
Register a function that is only know to the interpreter to the context.
std::string buildArg(RooAbsArg const &arg)
CodeSquashContext(std::map< RooFit::Detail::DataKey, std::size_t > const &outputSizes, std::vector< double > &xlarr, Experimental::RooFuncWrapper &wrapper)
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.
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...