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, std::string const &arrayType="double") |
| 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::unordered_set< RooFit::Detail::DataKey > const &dependsOnData={}) |
| Assemble and return the final code with the return expression and global statements. | |
| std::string const & | collectedCode () |
| 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. | |
| auto const & | dependsOnData () const |
| 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. | |
| int | observableIndexOf (const RooAbsArg &arg) const |
| ScopeRAII | OutputScopeRangeComment (RooAbsArg const *arg) |
| 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::string | _collectedCode |
| std::vector< std::string > | _collectedFunctions |
| std::unordered_set< RooFit::Detail::DataKey > | _dependsOnData |
| Indicate whether a node depends on the dataset. | |
| 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. | |
| 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 43 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 217 of file CodegenContext.cxx.
|
private |
Definition at line 50 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 122 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 134 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 90 of file CodegenContext.cxx.
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 101 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 160 of file CodegenContext.cxx.
Definition at line 157 of file CodegenContext.h.
| std::string RooFit::Experimental::CodegenContext::buildArg | ( | RooAbsCollection const & | in, |
| std::string const & | arrayType = "double" ) |
Function to save a RooListProxy as an array in the squashed code.
| in | The list to convert to array. |
Definition at line 246 of file CodegenContext.cxx.
|
inlineprivate |
Definition at line 160 of file CodegenContext.h.
|
inlineprivate |
Definition at line 155 of file CodegenContext.h.
Definition at line 274 of file CodegenContext.cxx.
Definition at line 103 of file CodegenContext.h.
|
inlineprivate |
Definition at line 153 of file CodegenContext.h.
|
inlineprivate |
Definition at line 139 of file CodegenContext.h.
|
inlineprivate |
Definition at line 148 of file CodegenContext.h.
|
inlineprivate |
Definition at line 165 of file CodegenContext.h.
Definition at line 168 of file CodegenContext.h.
|
inlineprivate |
Definition at line 174 of file CodegenContext.h.
|
private |
Definition at line 213 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 71 of file CodegenContext.h.
| std::string RooFit::Experimental::CodegenContext::buildFunction | ( | RooAbsArg const & | arg, |
| std::unordered_set< RooFit::Detail::DataKey > const & | dependsOnData = {} ) |
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 331 of file CodegenContext.cxx.
|
inline |
Definition at line 108 of file CodegenContext.h.
|
inline |
Definition at line 109 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 322 of file CodegenContext.cxx.
Definition at line 111 of file CodegenContext.h.
Definition at line 196 of file CodegenContext.cxx.
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 60 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 209 of file CodegenContext.cxx.
Definition at line 315 of file CodegenContext.cxx.
Definition at line 108 of file CodegenContext.cxx.
|
inline |
Definition at line 124 of file CodegenContext.h.
|
private |
Definition at line 308 of file CodegenContext.cxx.
|
private |
Definition at line 303 of file CodegenContext.cxx.
|
private |
|
inlineprivate |
Definition at line 202 of file CodegenContext.h.
|
inlineprivate |
Definition at line 207 of file CodegenContext.h.
Definition at line 105 of file CodegenContext.h.
|
private |
The code layered by lexical scopes used as a stack.
Definition at line 189 of file CodegenContext.h.
|
private |
Definition at line 198 of file CodegenContext.h.
|
private |
Definition at line 197 of file CodegenContext.h.
|
private |
Indicate whether a node depends on the dataset.
Definition at line 187 of file CodegenContext.h.
|
private |
The indentation level for pretty-printing.
Definition at line 191 of file CodegenContext.h.
|
private |
A map to keep track of list names as assigned by addResult.
Definition at line 195 of file CodegenContext.h.
|
private |
Map of node names to their result strings.
Definition at line 183 of file CodegenContext.h.
|
mutableprivate |
Index to get unique names for temporary variables.
Definition at line 193 of file CodegenContext.h.
|
private |
A map to keep track of the observable indices if they are non scalar.
Definition at line 185 of file CodegenContext.h.
|
private |
Definition at line 196 of file CodegenContext.h.