Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooBatchCompute::RunContext Struct Reference

This struct enables passing computation data around between elements of a computation graph.

Separating data and computation graph

The RunContext stores read-only spans to data that has already been computed. This can be data of the observables (which is constant during a fit) or intermediate computation results from evaluating PDFs or formulae for every point in a dataset. The latter may change as fit parameters change.

Instead of storing information about these data inside nodes of the computation graph (requiring a change of their state, possibly violating const-correctness), this information is stored in RunContext::spans using the pointer of the element that produced those results as a key. In this way, one or multiple RunContext instances can be passed around when computations are running, leaving the objects of the computation graph invariant.

Memory ownership model

The RunContext can provide memory for temporary data, that is, data that can vanish after a fit converges. Using RunContext::makeBatch(), a suitable amount of memory is allocated to store computation results. When intermediate data are cleared, this memory is not freed. In this way, temporary data can be invalidated when fit parameters change, but the memory is only allocated once per fit.

When a RunContext goes out of scope, the memory is freed. That means that in between fit cycles, a RunContext should be cleared using clear(), or single results should be invalidated by removing these from RunContext::spans. The RunContext object should be destroyed only after a fit completes.

Definition at line 31 of file RunContext.h.

Public Member Functions

 RunContext ()
 Create an empty RunContext that doesn't have access to any computation results.
 
 RunContext (const RunContext &)=delete
 Deleted because copying the owned memory is expensive.
 
 RunContext (RunContext &&)=default
 Move a RunContext. All spans pointing to data retrieved from the original remain valid.
 
void clear ()
 Clear all computation results without freeing memory.
 
RooSpan< const doublegetBatch (const RooAbsReal *owner) const
 Check if there is a span of data corresponding to the object passed as owner.
 
RooSpan< const doublegetBatch (const RooArgProxy &proxy) const
 
RooSpan< doublegetWritableBatch (const RooAbsReal *owner)
 Check if there is a writable span of data corresponding to the object passed as owner.
 
RooSpan< doublemakeBatch (const RooAbsReal *owner, std::size_t size)
 Create a writable batch.
 
RooSpan< const doubleoperator[] (const RooAbsReal *owner) const
 Retrieve a batch of data corresponding to the element passed as owner.
 

Public Attributes

std::vector< doublelogProbabilities
 If evaluation should only occur in a range, the range name can be passed here.
 
std::unordered_map< const RooAbsReal *, std::vector< double > > ownedMemory
 Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
 
const char * rangeName {nullptr}
 
std::unordered_map< const RooAbsReal *, RooSpan< const double > > spans
 Once an object has computed its value(s), the span pointing to the results is registered here.
 

#include <RunContext.h>

Constructor & Destructor Documentation

◆ RunContext() [1/3]

RooBatchCompute::RunContext::RunContext ( )
inline

Create an empty RunContext that doesn't have access to any computation results.

Definition at line 33 of file RunContext.h.

◆ RunContext() [2/3]

RooBatchCompute::RunContext::RunContext ( const RunContext )
delete

Deleted because copying the owned memory is expensive.

If needed, it can be implemented, though.

Warning
Remember to relocate all spans in spans to new location in ownedMemory after data have been copied!

◆ RunContext() [3/3]

RooBatchCompute::RunContext::RunContext ( RunContext &&  )
default

Move a RunContext. All spans pointing to data retrieved from the original remain valid.

Member Function Documentation

◆ clear()

void RooBatchCompute::RunContext::clear ( )
inline

Clear all computation results without freeing memory.

Definition at line 49 of file RunContext.h.

◆ getBatch() [1/2]

RooSpan< const double > RooBatchCompute::RunContext::getBatch ( const RooAbsReal owner) const

Check if there is a span of data corresponding to the object passed as owner.

Definition at line 55 of file RunContext.cxx.

◆ getBatch() [2/2]

RooSpan< const double > RooBatchCompute::RunContext::getBatch ( const RooArgProxy proxy) const

◆ getWritableBatch()

RooSpan< double > RooBatchCompute::RunContext::getWritableBatch ( const RooAbsReal owner)

Check if there is a writable span of data corresponding to the object passed as owner.

The span can be used both for reading and writing.

Definition at line 66 of file RunContext.cxx.

◆ makeBatch()

RooSpan< double > RooBatchCompute::RunContext::makeBatch ( const RooAbsReal owner,
std::size_t  size 
)

Create a writable batch.

If the RunContext already owns memory for the object owner, just resize the memory. If it doesn't exist yet, allocate it.

Warning
The memory will be uninitialised, so every entry must be overwritten. On first use, all values are initialised to NaN to help detect such errors.

A read-only reference to the memory will be stored in spans.

Parameters
ownerRooFit object whose value should be written into the memory.
sizeRequested size of the span.
Returns
A writeable RooSpan of the requested size, whose memory is owned by the RunContext.

Definition at line 87 of file RunContext.cxx.

◆ operator[]()

RooSpan< const double > RooBatchCompute::RunContext::operator[] ( const RooAbsReal owner) const
inline

Retrieve a batch of data corresponding to the element passed as owner.

Definition at line 44 of file RunContext.h.

Member Data Documentation

◆ logProbabilities

std::vector<double> RooBatchCompute::RunContext::logProbabilities

If evaluation should only occur in a range, the range name can be passed here.

Definition at line 56 of file RunContext.h.

◆ ownedMemory

std::unordered_map<const RooAbsReal*, std::vector<double> > RooBatchCompute::RunContext::ownedMemory

Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.

Definition at line 54 of file RunContext.h.

◆ rangeName

const char* RooBatchCompute::RunContext::rangeName {nullptr}

Definition at line 55 of file RunContext.h.

◆ spans

std::unordered_map<const RooAbsReal*, RooSpan<const double> > RooBatchCompute::RunContext::spans

Once an object has computed its value(s), the span pointing to the results is registered here.

Definition at line 52 of file RunContext.h.

Collaboration diagram for RooBatchCompute::RunContext:
[legend]

The documentation for this struct was generated from the following files: