Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RunContext.h
Go to the documentation of this file.
1// Author: Stephan Hageboeck, CERN Jul 2020
2
3/*****************************************************************************
4 * RooFit
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2020, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROOFIT_BATCHCOMPUTE_RUNCONTEXT_H
18#define ROOFIT_BATCHCOMPUTE_RUNCONTEXT_H
19
20#include "RooSpan.h"
21
22#include <unordered_map>
23#include <vector>
24
25class RooArgSet;
26class RooAbsReal;
27class RooArgProxy;
28
29namespace RooBatchCompute {
30
31struct RunContext {
32 /// Create an empty RunContext that doesn't have access to any computation results.
34 /// Deleted because copying the owned memory is expensive.
35 /// If needed, it can be implemented, though.
36 /// \warning Remember to relocate all spans in `spans` to new location
37 /// in `ownedMemory` after data have been copied!
38 RunContext(const RunContext&) = delete;
39 /// Move a RunContext. All spans pointing to data retrieved from the original remain valid.
40 RunContext(RunContext&&) = default;
42 RooSpan<const double> getBatch(const RooAbsReal* owner) const;
43 /// Retrieve a batch of data corresponding to the element passed as `owner`.
44 RooSpan<const double> operator[](const RooAbsReal* owner) const { return getBatch(owner); }
46 RooSpan<double> makeBatch(const RooAbsReal* owner, std::size_t size);
47
48 /// Clear all computation results without freeing memory.
49 void clear() { spans.clear(); rangeName = nullptr; }
50
51 /// Once an object has computed its value(s), the span pointing to the results is registered here.
52 std::unordered_map<const RooAbsReal*, RooSpan<const double>> spans;
53 /// Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
54 std::unordered_map<const RooAbsReal*, std::vector<double>> ownedMemory;
55 const char* rangeName{nullptr}; /// If evaluation should only occur in a range, the range name can be passed here.
56 std::vector<double> logProbabilities; /// Possibility to register log probabilities.
57};
58
59}
60
61#endif
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
RooArgProxy is the abstract interface for RooAbsArg proxy classes.
Definition RooArgProxy.h:24
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
A simple container to hold a batch of data values.
Definition RooSpan.h:34
Namespace for dispatching RooFit computations to various backends.
This struct enables passing computation data around between elements of a computation graph.
Definition RunContext.h:31
std::vector< double > logProbabilities
If evaluation should only occur in a range, the range name can be passed here.
Definition RunContext.h:56
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.
Definition RunContext.h:52
void clear()
Clear all computation results without freeing memory.
Definition RunContext.h:49
RooSpan< double > getWritableBatch(const RooAbsReal *owner)
Check if there is a writable span of data corresponding to the object passed as owner.
RunContext(RunContext &&)=default
Move a RunContext. All spans pointing to data retrieved from the original remain valid.
RunContext(const RunContext &)=delete
Deleted because copying the owned memory is expensive.
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.
Definition RunContext.h:54
RooSpan< const double > getBatch(const RooArgProxy &proxy) const
RooSpan< const double > operator[](const RooAbsReal *owner) const
Retrieve a batch of data corresponding to the element passed as owner.
Definition RunContext.h:44
RooSpan< double > makeBatch(const RooAbsReal *owner, std::size_t size)
Create a writable batch.
RunContext()
Create an empty RunContext that doesn't have access to any computation results.
Definition RunContext.h:33