27 : _wrapper{&wrapper}, _nodeOutputSizes(outputSizes), _xlArr(xlarr)
67 throw std::runtime_error(
"You requested the result of a vector observable outside a loop scope for it!");
137 std::string idx =
"loopIdx" + std::to_string(
_loopLevel);
139 std::vector<TNamed const *> vars;
145 vars.push_back(it.first);
146 _nodeNames[it.first] =
"obs[" + std::to_string(it.second) +
" + " + idx +
"]";
152 std::size_t numEntries = 1;
153 for (
auto &it : vars) {
155 if (
n > 1 && numEntries > 1 &&
n != numEntries) {
156 throw std::runtime_error(
"Trying to loop over variables with different sizes!");
158 numEntries = std::max(
n, numEntries);
165 addToCodeBody(in,
"for(int " + idx +
" = 0; " + idx +
" < " + std::to_string(numEntries) +
"; " + idx +
"++) {\n");
168 return std::make_unique<LoopScope>(*
this, std::move(vars));
181 for (
auto const &ptr : scope.
vars()) {
203 bool hasOperations = valueToSave.find_first_of(
":-+/*") != std::string::npos;
210 std::string outVarDecl =
"const double " + savedName +
" = " + valueToSave +
";\n";
213 savedName = valueToSave;
233 bool canSaveOutside =
true;
235 std::stringstream declStrm;
236 declStrm <<
"double " << savedName <<
"[] = {";
237 for (
const auto arg : in) {
241 declStrm.seekp(-1, declStrm.cur);
252 unsigned int n = arr.size();
255 for (
unsigned int i = 0; i <
n; i++) {
258 return "xlArr + " +
offset;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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 getTmpVarName() const
Get a unique variable name to be used in the generated code.
std::string const & getResult(RooAbsArg const &arg)
Gets the result for the given node using the node name.
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.
CodeSquashContext(std::map< RooFit::Detail::DataKey, std::size_t > const &outputSizes, std::vector< double > &xlarr, Experimental::RooFuncWrapper &wrapper)
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::vector< double > & _xlArr
std::unique_ptr< LoopScope > beginLoop(RooAbsArg const *in)
Create a RAII scope for iterating over vector observables.
A wrapper class to store a C++ function of type 'double (*)(double*, double*)'.
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.
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.