61 throw std::runtime_error(
"You requested the result of a vector observable outside a loop scope for it!");
130 std::string idx =
"loopIdx" + std::to_string(
_loopLevel);
132 std::vector<TNamed const *> vars;
138 vars.push_back(it.first);
139 _nodeNames[it.first] =
"obs[" + std::to_string(it.second) +
" + " + idx +
"]";
145 std::size_t numEntries = 1;
146 for (
auto &it : vars) {
148 if (
n > 1 && numEntries > 1 &&
n != numEntries) {
149 throw std::runtime_error(
"Trying to loop over variables with different sizes!");
151 numEntries = std::max(
n, numEntries);
158 addToCodeBody(in,
"for(int " + idx +
" = 0; " + idx +
" < " + std::to_string(numEntries) +
"; " + idx +
"++) {\n");
161 return std::make_unique<LoopScope>(*
this, std::move(vars));
174 for (
auto const &ptr : scope.
vars()) {
184 return "tmpVar" + std::to_string(
_tmpVarIdx++);
195 bool hasOperations = valueToSave.find_first_of(
":-+/*") != std::string::npos;
202 std::string outVarDecl =
"const double " + savedName +
" = " + valueToSave +
";\n";
205 savedName = valueToSave;
221 bool canSaveOutside =
true;
223 std::stringstream declStrm;
224 declStrm <<
"double " << savedName <<
"[] = {";
225 for (
const auto arg : in) {
229 declStrm.seekp(-1, declStrm.cur);
240 unsigned int n = arr.size();
242 std::string arrDecl =
"double " + arrName +
"[" + std::to_string(
n) +
"] = {";
243 for (
unsigned int i = 0; i <
n; i++) {
244 arrDecl +=
" " + std::to_string(arr[i]) +
",";
246 arrDecl.back() =
'}';
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.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
virtual void translate(RooFit::Detail::CodeSquashContext &ctx) const
This function defines a translation for each RooAbsReal based object that can be used to express the ...
virtual bool isReducerNode() const
Abstract container object that can hold multiple RooAbsArg objects.
RooFit::UniqueId< RooAbsCollection > const & uniqueId() const
Returns a unique ID that is different for every instantiated RooAbsCollection.
A class to manage loop scopes using the RAII technique.
std::vector< TNamed const * > const & vars() const
std::string assembleCode(std::string const &returnExpr)
Assemble and return the final code with the return expression and global statements.
std::string _tempScope
Stores code that eventually gets injected into main code body.
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 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::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 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 buildArg(RooAbsCollection const &x)
Function to save a RooListProxy as an array in the squashed code.
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.
static const TNamed * known(const char *stringPtr)
If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name)...
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
std::string makeValidVarName(std::string const &in)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
constexpr Value_t value() const
Return numerical value of ID.