A class to maintain the context for squashing of RooFit models into code.
Definition at line 46 of file CodegenContext.h.
Classes | |
class | LoopScope |
A class to manage loop scopes using the RAII technique. More... | |
struct | ScopeRAII |
Public Member Functions | |
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::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 | 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. | |
std::vector< std::string > const & | collectedFunctions () |
void | collectFunction (std::string const &name) |
Register a function that is only know to the interpreter to the context. | |
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. | |
ScopeRAII | OutputScopeRangeComment (RooAbsArg const *arg) |
std::size_t | outputSize (RooFit::Detail::DataKey key) const |
Figure out the output size of a node. | |
auto const & | outputSizes () const |
std::vector< double > const & | xlArr () |
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 |
void | popScope () |
void | pushScope () |
template<class T > | |
std::string | typeName () const |
template<> | |
std::string | typeName () const |
template<> | |
std::string | typeName () const |
Private Attributes | |
std::vector< std::string > | _code |
The code layered by lexical scopes used as a stack. | |
std::vector< std::string > | _collectedFunctions |
unsigned | _indent = 0 |
The indentation level for pretty-printing. | |
std::unordered_map< RooFit::UniqueId< RooAbsCollection >::Value_t, std::string > | _listNames |
A map to keep track of list names as assigned by addResult. | |
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 | _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 |
#include <RooFit/CodegenContext.h>
void RooFit::Experimental::CodegenContext::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 41 of file CodegenContext.cxx.
void RooFit::Experimental::CodegenContext::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 204 of file CodegenContext.cxx.
|
private |
Definition at line 48 of file CodegenContext.cxx.
void RooFit::Experimental::CodegenContext::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 111 of file CodegenContext.cxx.
void RooFit::Experimental::CodegenContext::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 123 of file CodegenContext.cxx.
void RooFit::Experimental::CodegenContext::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 88 of file CodegenContext.cxx.
void RooFit::Experimental::CodegenContext::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 99 of file CodegenContext.cxx.
std::unique_ptr< CodegenContext::LoopScope > RooFit::Experimental::CodegenContext::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 149 of file CodegenContext.cxx.
|
inlineprivate |
Definition at line 166 of file CodegenContext.h.
std::string RooFit::Experimental::CodegenContext::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 229 of file CodegenContext.cxx.
|
inlineprivate |
Definition at line 169 of file CodegenContext.h.
|
inlineprivate |
Definition at line 164 of file CodegenContext.h.
std::string RooFit::Experimental::CodegenContext::buildArg | ( | std::span< const double > | arr | ) |
Definition at line 257 of file CodegenContext.cxx.
|
inline |
Definition at line 114 of file CodegenContext.h.
|
inlineprivate |
Definition at line 162 of file CodegenContext.h.
|
inlineprivate |
Definition at line 150 of file CodegenContext.h.
|
inlineprivate |
Definition at line 157 of file CodegenContext.h.
|
inlineprivate |
Definition at line 174 of file CodegenContext.h.
|
inlineprivate |
Definition at line 177 of file CodegenContext.h.
|
inlineprivate |
Definition at line 183 of file CodegenContext.h.
|
private |
Definition at line 221 of file CodegenContext.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 82 of file CodegenContext.h.
std::string RooFit::Experimental::CodegenContext::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.
returnExpr | The string representation of what the squashed function should return, usually the head node. |
Definition at line 314 of file CodegenContext.cxx.
|
inline |
Definition at line 119 of file CodegenContext.h.
void RooFit::Experimental::CodegenContext::collectFunction | ( | std::string const & | name | ) |
Register a function that is only know to the interpreter to the context.
This is useful to dump the standalone C++ code for the computation graph.
Definition at line 305 of file CodegenContext.cxx.
|
private |
Definition at line 183 of file CodegenContext.cxx.
std::string const & RooFit::Experimental::CodegenContext::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 58 of file CodegenContext.cxx.
|
inline |
Definition at line 54 of file CodegenContext.h.
std::string RooFit::Experimental::CodegenContext::getTmpVarName | ( | ) | const |
Get a unique variable name to be used in the generated code.
Definition at line 196 of file CodegenContext.cxx.
Definition at line 298 of file CodegenContext.cxx.
|
inline |
Definition at line 135 of file CodegenContext.h.
|
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 63 of file CodegenContext.h.
|
inline |
Definition at line 124 of file CodegenContext.h.
|
private |
Definition at line 291 of file CodegenContext.cxx.
|
private |
Definition at line 286 of file CodegenContext.cxx.
|
private |
|
inlineprivate |
Definition at line 210 of file CodegenContext.h.
|
inlineprivate |
Definition at line 215 of file CodegenContext.h.
|
inline |
Definition at line 116 of file CodegenContext.h.
|
private |
The code layered by lexical scopes used as a stack.
Definition at line 198 of file CodegenContext.h.
|
private |
Definition at line 206 of file CodegenContext.h.
|
private |
The indentation level for pretty-printing.
Definition at line 200 of file CodegenContext.h.
|
private |
A map to keep track of list names as assigned by addResult.
Definition at line 204 of file CodegenContext.h.
|
private |
Map of node names to their result strings.
Definition at line 192 of file CodegenContext.h.
|
private |
Map of node output sizes.
Definition at line 196 of file CodegenContext.h.
|
mutableprivate |
Index to get unique names for temporary variables.
Definition at line 202 of file CodegenContext.h.
|
private |
A map to keep track of the observable indices if they are non scalar.
Definition at line 194 of file CodegenContext.h.
|
private |
Definition at line 205 of file CodegenContext.h.