14#ifndef RooFit_Detail_CodeSquashContext_h
15#define RooFit_Detail_CodeSquashContext_h
26#include <unordered_map>
71 void addToCodeBody(std::string
const &in,
bool isScopeIndep =
false);
76 template <
typename... Args_t>
77 std::string
buildCall(std::string
const &funcname, Args_t
const &...args)
80 ss << funcname <<
"(" <<
buildArgs(args...) <<
")";
95 std::vector<TNamed const *>
const &
vars()
const {
return _vars; }
99 const std::vector<TNamed const *>
_vars;
107 std::string
buildArg(std::span<const double> arr);
116 template <
class T,
typename std::enable_if<std::is_
floating_po
int<T>{},
bool>::type = true>
123 template <
class T,
typename std::enable_if<std::is_
integral<T>{},
bool>::type = true>
126 return std::to_string(
x);
131 std::string
buildArg(std::nullptr_t) {
return "nullptr"; }
143 template <
class Arg_t>
149 template <
typename Arg_t,
typename... Args_t>
150 std::string
buildArgs(Arg_t
const &arg, Args_t
const &...args)
175 std::unordered_map<RooFit::UniqueId<RooAbsCollection>::Value_t, std::string>
listNames;
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 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
CodeSquashContext(std::map< RooFit::Detail::DataKey, std::size_t > const &outputSizes)
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 getTmpVarName()
Get a unique variable name to be used in the generated code.
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(RooAbsCollection const &x)
Function to save a RooListProxy as an array in the squashed code.
std::string buildArgs(Arg_t const &arg)
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::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)
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...