A class to maintain the context for squashing of RooFit models into code.
Definition at line 42 of file CodeSquashContext.h.
Classes | |
class | LoopScope |
A class to manage loop scopes using the RAII technique. More... | |
Public Member Functions | |
CodeSquashContext (std::map< RooFit::Detail::DataKey, std::size_t > const &outputSizes, std::vector< double > &xlarr, Experimental::RooFuncWrapper &wrapper) | |
void | addResult (const char *key, std::string const &value) |
Adds (or overwrites) the string representing the result of a node. | |
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. | |
void | addToCodeBody (std::string const &in, bool isScopeIndep=false) |
A variation of the previous addToCodeBody that takes in a bool value that determines if input is independent. | |
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. | |
void | addVecObs (const char *key, int idx) |
Since the squashed code represents all observables as a single flattened array, it is important to keep track of the start index for a vector valued observable which can later be expanded to access the correct element. | |
std::string | assembleCode (std::string const &returnExpr) |
Assemble and return the final code with the return expression and global statements. | |
std::unique_ptr< LoopScope > | beginLoop (RooAbsArg const *in) |
Create a RAII scope for iterating over vector observables. | |
std::string | buildArg (RooAbsCollection const &x) |
Function to save a RooListProxy as an array in the squashed code. | |
std::string | buildArg (std::span< const double > arr) |
std::string | buildArg (std::span< const int > arr) |
template<typename... Args_t> | |
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 const & | getResult (RooAbsArg const &arg) |
Gets the result for the given node using the node name. | |
template<class T > | |
std::string const & | getResult (RooTemplateProxy< T > const &key) |
std::string | getTmpVarName () const |
Get a unique variable name to be used in the generated code. | |
std::size_t | outputSize (RooFit::Detail::DataKey key) const |
Figure out the output size of a node. | |
Public Attributes | |
Experimental::RooFuncWrapper * | _wrapper = nullptr |
Private Member Functions | |
void | addResult (TNamed const *key, std::string const &value) |
std::string | buildArg (RooAbsArg const &arg) |
template<class T > | |
std::string | buildArg (RooTemplateProxy< T > const &arg) |
std::string | buildArg (std::nullptr_t) |
std::string | buildArg (std::string const &x) |
template<class T , typename std::enable_if< std::is_floating_point< T >{}, bool >::type = true> | |
std::string | buildArg (T x) |
template<class T , typename std::enable_if< std::is_integral< T >{}, bool >::type = true> | |
std::string | buildArg (T x) |
std::string | buildArgs () |
template<class Arg_t > | |
std::string | buildArgs (Arg_t const &arg) |
template<typename Arg_t , typename... Args_t> | |
std::string | buildArgs (Arg_t const &arg, Args_t const &...args) |
template<class T > | |
std::string | buildArgSpanImpl (std::span< const T > arr) |
void | endLoop (LoopScope const &scope) |
bool | isScopeIndependent (RooAbsArg const *in) const |
template<class T > | |
std::string | typeName () const |
template<> | |
std::string | typeName () const |
template<> | |
std::string | typeName () const |
Private Attributes | |
std::string | _code |
Stores the squashed code body. | |
std::string | _globalScope |
Block of code that is placed before the rest of the function body. | |
int | _loopLevel = 0 |
The current number of for loops the started. | |
std::unordered_map< const TNamed *, std::string > | _nodeNames |
Map of node names to their result strings. | |
std::map< RooFit::Detail::DataKey, std::size_t > | _nodeOutputSizes |
Map of node output sizes. | |
int | _scopePtr = -1 |
Keeps track of the position to go back and insert code to. | |
std::string | _tempScope |
Stores code that eventually gets injected into main code body. | |
int | _tmpVarIdx = 0 |
Index to get unique names for temporary variables. | |
std::unordered_map< const TNamed *, int > | _vecObsIndices |
A map to keep track of the observable indices if they are non scalar. | |
std::vector< double > & | _xlArr |
std::unordered_map< RooFit::UniqueId< RooAbsCollection >::Value_t, std::string > | listNames |
A map to keep track of list names as assigned by addResult. | |
#include <RooFit/Detail/CodeSquashContext.h>
RooFit::Detail::CodeSquashContext::CodeSquashContext | ( | std::map< RooFit::Detail::DataKey, std::size_t > const & | outputSizes, |
std::vector< double > & | xlarr, | ||
Experimental::RooFuncWrapper & | wrapper | ||
) |
Definition at line 25 of file CodeSquashContext.cxx.
void RooFit::Detail::CodeSquashContext::addResult | ( | const char * | key, |
std::string const & | value | ||
) |
Adds (or overwrites) the string representing the result of a node.
key | The name of the node to add the result for. |
value | The new name to assign/overwrite. |
Definition at line 34 of file CodeSquashContext.cxx.
void RooFit::Detail::CodeSquashContext::addResult | ( | RooAbsArg const * | in, |
std::string const & | valueToSave | ||
) |
A function to save an expression that includes/depends on the result of the input node.
in | The node on which the valueToSave depends on/belongs to. |
valueToSave | The actual string value to save as a temporary. |
Definition at line 197 of file CodeSquashContext.cxx.
|
private |
Definition at line 41 of file CodeSquashContext.cxx.
void RooFit::Detail::CodeSquashContext::addToCodeBody | ( | RooAbsArg const * | klass, |
std::string const & | in | ||
) |
Adds the input string to the squashed code body.
If a class implements a translate function that wants to emit something to the squashed code body, it must call this function with the code it wants to emit. In case of loops, automatically determines if code needs to be stored inside or outside loop scope.
klass | The class requesting this addition, usually 'this'. |
in | String to add to the squashed code. |
Definition at line 109 of file CodeSquashContext.cxx.
void RooFit::Detail::CodeSquashContext::addToCodeBody | ( | std::string const & | in, |
bool | isScopeIndep = false |
||
) |
A variation of the previous addToCodeBody that takes in a bool value that determines if input is independent.
This overload exists because there might other ways to determine if a value/collection of values is scope independent.
in | String to add to the squashed code. |
isScopeIndep | The value determining if the input is scope dependent. |
Definition at line 121 of file CodeSquashContext.cxx.
void RooFit::Detail::CodeSquashContext::addToGlobalScope | ( | std::string const & | str | ) |
Adds the given string to the string block that will be emitted at the top of the squashed function.
Useful for variable declarations.
str | The string to add to the global scope. |
Definition at line 79 of file CodeSquashContext.cxx.
void RooFit::Detail::CodeSquashContext::addVecObs | ( | const char * | key, |
int | idx | ||
) |
Since the squashed code represents all observables as a single flattened array, it is important to keep track of the start index for a vector valued observable which can later be expanded to access the correct element.
For example, a vector valued variable x with 10 entries will be squashed to obs[start_idx + i].
key | The name of the node representing the vector valued observable. |
idx | The start index (or relative position of the observable in the set of all observables). |
Definition at line 97 of file CodeSquashContext.cxx.
std::string RooFit::Detail::CodeSquashContext::assembleCode | ( | std::string const & | returnExpr | ) |
Assemble and return the final code with the return expression and global statements.
returnExpr | The string representation of what the squashed function should return, usually the head node. |
Definition at line 87 of file CodeSquashContext.cxx.
std::unique_ptr< CodeSquashContext::LoopScope > RooFit::Detail::CodeSquashContext::beginLoop | ( | RooAbsArg const * | in | ) |
Create a RAII scope for iterating over vector observables.
You can't use the result of vector observables outside these loop scopes.
in | A pointer to the calling class, used to determine the loop dependent variables. |
Definition at line 135 of file CodeSquashContext.cxx.
|
inlineprivate |
Definition at line 144 of file CodeSquashContext.h.
std::string RooFit::Detail::CodeSquashContext::buildArg | ( | RooAbsCollection const & | in | ) |
Function to save a RooListProxy as an array in the squashed code.
in | The list to convert to array. |
Definition at line 222 of file CodeSquashContext.cxx.
|
inlineprivate |
Definition at line 147 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 142 of file CodeSquashContext.h.
std::string RooFit::Detail::CodeSquashContext::buildArg | ( | std::span< const double > | arr | ) |
Definition at line 250 of file CodeSquashContext.cxx.
|
inline |
Definition at line 113 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 140 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 128 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 135 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 152 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 155 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 161 of file CodeSquashContext.h.
|
private |
Definition at line 205 of file CodeSquashContext.h.
|
inline |
Build the code to call the function with name funcname
, passing some arguments.
The arguments can either be doubles or some RooFit arguments whose results will be looked up in the context.
Definition at line 81 of file CodeSquashContext.h.
|
private |
Definition at line 171 of file CodeSquashContext.cxx.
std::string const & RooFit::Detail::CodeSquashContext::getResult | ( | RooAbsArg const & | arg | ) |
Gets the result for the given node using the node name.
This node also performs the necessary code generation through recursive calls to 'translate'. A call to this function modifies the already existing code body.
key | The node to get the result string for. |
Definition at line 51 of file CodeSquashContext.cxx.
|
inline |
Definition at line 52 of file CodeSquashContext.h.
std::string RooFit::Detail::CodeSquashContext::getTmpVarName | ( | ) | const |
Get a unique variable name to be used in the generated code.
Definition at line 189 of file CodeSquashContext.cxx.
Definition at line 261 of file CodeSquashContext.cxx.
|
inline |
Figure out the output size of a node.
It is the size of the vector observable that it depends on, or 1 if it doesn't depend on any or is a reducer node.
key | The node to look up the size for. |
Definition at line 61 of file CodeSquashContext.h.
|
private |
|
inlineprivate |
Definition at line 194 of file CodeSquashContext.h.
|
inlineprivate |
Definition at line 199 of file CodeSquashContext.h.
|
private |
Stores the squashed code body.
Definition at line 178 of file CodeSquashContext.h.
|
private |
Block of code that is placed before the rest of the function body.
Definition at line 172 of file CodeSquashContext.h.
|
private |
The current number of for loops the started.
Definition at line 180 of file CodeSquashContext.h.
|
private |
Map of node names to their result strings.
Definition at line 170 of file CodeSquashContext.h.
|
private |
Map of node output sizes.
Definition at line 176 of file CodeSquashContext.h.
|
private |
Keeps track of the position to go back and insert code to.
Definition at line 184 of file CodeSquashContext.h.
|
private |
Stores code that eventually gets injected into main code body.
Mainly used for placing decls outside of loops.
Definition at line 187 of file CodeSquashContext.h.
|
mutableprivate |
Index to get unique names for temporary variables.
Definition at line 182 of file CodeSquashContext.h.
A map to keep track of the observable indices if they are non scalar.
Definition at line 174 of file CodeSquashContext.h.
Experimental::RooFuncWrapper* RooFit::Detail::CodeSquashContext::_wrapper = nullptr |
Definition at line 115 of file CodeSquashContext.h.
|
private |
Definition at line 190 of file CodeSquashContext.h.
|
private |
A map to keep track of list names as assigned by addResult.
Definition at line 189 of file CodeSquashContext.h.