Logo ROOT  
Reference Guide
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_ROOFITCORE_INC_BATCHRUNCONTEXT_H_
18 #define ROOFIT_ROOFITCORE_INC_BATCHRUNCONTEXT_H_
19 
20 #include "RooSpan.h"
21 
22 #include <unordered_map>
23 #include <vector>
24 
25 class RooArgSet;
26 class RooAbsReal;
27 class RooArgProxy;
28 
29 namespace BatchHelpers {
30 
31 /// Data that has to be passed around when evaluating functions / PDFs.
32 struct RunContext {
33  RunContext() { }
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  RunContext(RunContext&&) = default;
40  RooSpan<const double> getBatch(const RooArgProxy& proxy) const;
41  RooSpan<const double> getBatch(const RooAbsReal* owner) const;
42  /// Retrieve a batch of data corresponding to the element passed as `owner`.
43  RooSpan<const double> operator[](const RooAbsReal* owner) const { return getBatch(owner); }
45  RooSpan<double> makeBatch(const RooAbsReal* owner, std::size_t size);
46 
47  /// Clear all computation results without freeing memory.
48  void clear() { spans.clear(); rangeName = nullptr; }
49 
50  /// Once an object has computed its value(s), the span pointing to the results is registered here.
51  std::unordered_map<const RooAbsReal*, RooSpan<const double>> spans;
52  /// Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
53  std::unordered_map<const RooAbsReal*, std::vector<double>> ownedMemory;
54  const char* rangeName{nullptr}; /// If evaluation should only occur in a range, the range name can be passed here.
55  std::vector<double> logProbabilities; /// Possibility to register log probabilities.
56 };
57 
58 }
59 
60 #endif
BatchHelpers::RunContext::getWritableBatch
RooSpan< double > getWritableBatch(const RooAbsReal *owner)
Check if there is a writable span of data corresponding to the object passed as owner.
Definition: RunContext.cxx:42
BatchHelpers::RunContext::RunContext
RunContext()
Definition: RunContext.h:33
BatchHelpers::RunContext::ownedMemory
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:53
BatchHelpers::RunContext::RunContext
RunContext(RunContext &&)=default
BatchHelpers::RunContext::operator[]
RooSpan< const double > operator[](const RooAbsReal *owner) const
Retrieve a batch of data corresponding to the element passed as owner.
Definition: RunContext.h:43
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
BatchHelpers::RunContext::getBatch
RooSpan< const double > getBatch(const RooArgProxy &proxy) const
Check if there is a span of data corresponding to the variable in this proxy.
Definition: RunContext.cxx:25
BatchHelpers::RunContext::makeBatch
RooSpan< double > makeBatch(const RooAbsReal *owner, std::size_t size)
Create a writable batch.
Definition: RunContext.cxx:63
BatchHelpers::RunContext
Data that has to be passed around when evaluating functions / PDFs.
Definition: RunContext.h:32
BatchHelpers
Definition: RooFitComputeInterface.h:9
RooArgProxy
RooArgProxy is the abstract interface for RooAbsArg proxy classes.
Definition: RooArgProxy.h:24
BatchHelpers::RunContext::rangeName
const char * rangeName
Definition: RunContext.h:54
BatchHelpers::RunContext::RunContext
RunContext(const RunContext &)=delete
Deleted because copying the owned memory is expensive.
BatchHelpers::RunContext::spans
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:51
BatchHelpers::RunContext::logProbabilities
std::vector< double > logProbabilities
If evaluation should only occur in a range, the range name can be passed here.
Definition: RunContext.h:55
RooSpan.h
BatchHelpers::RunContext::clear
void clear()
Clear all computation results without freeing memory.
Definition: RunContext.h:48
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29