template<typename T>
class ROOT::Detail::RDF::RResultPtr< T >
Smart pointer for the return type of actions.
A wrapper around the result of RDataFrame actions able to trigger calculations lazily.
- Template Parameters
-
| T | Type of the action result |
A wrapper around a shared_ptr which allows to access the result of RDataFrame actions. The underlying object can be accessed by dereferencing the RResultPtr:
histo->Draw();
Smart pointer for the return type of actions.
Upon invocation of the arrow operator or dereferencing (operator*), the loop on the events and calculations of all scheduled actions are executed if needed. It is possible to iterate on the result proxy if the proxied object is a collection.
for (auto& myItem : myResultProxy) { ... };
If iteration is not supported by the type of the proxied object, a compilation error is thrown.
When shared ownership to the result is desired, a copy of the underlying shared_ptr can be obtained:
std::shared_ptr<TH1D> ProduceResult(const char *columnname) {
auto ht = rdf.Histo1D(*
h, columname);
return ht.GetSharedPtr();
}
Note that this will run the event loop. If this is not desired, the RResultPtr can be copied.
Definition at line 131 of file RResultPtr.hxx.
|
| | RResultPtr ()=default |
| | RResultPtr (const RResultPtr &)=default |
| template<typename T2, std::enable_if_t< std::is_constructible< std::shared_ptr< T >, std::shared_ptr< T2 > >::value, int > = 0> |
| | RResultPtr (const RResultPtr< T2 > &r) |
| | Convert a RResultPtr<T2> to a RResultPtr<T>.
|
| | RResultPtr (RResultPtr &&)=default |
| RIterationHelper< T >::Iterator_t | begin () |
| | Return an iterator to the beginning of the contained object if this makes sense, throw a compilation error otherwise.
|
| RIterationHelper< T >::Iterator_t | end () |
| | Return an iterator to the end of the contained object if this makes sense, throw a compilation error otherwise.
|
| T * | GetPtr () |
| | Get the pointer to the encapsulated object.
|
| std::shared_ptr< T > | GetSharedPtr () |
| | Produce the encapsulated result, and return a shared pointer to it.
|
| const T & | GetValue () |
| | Get a const reference to the encapsulated object.
|
| bool | IsReady () const |
| | Check whether the result has already been computed.
|
| RResultPtr< T > & | OnPartialResult (ULong64_t everyNEvents, std::function< void(T &)> callback) |
| | Register a callback that RDataFrame will execute "everyNEvents" on a partial result.
|
| RResultPtr< T > & | OnPartialResultSlot (ULong64_t everyNEvents, std::function< void(unsigned int, T &)> callback) |
| | Register a callback that RDataFrame will execute in each worker thread concurrently on that thread's partial result.
|
| | operator bool () const |
| T & | operator* () |
| | Get a reference to the encapsulated object.
|
| T * | operator-> () |
| | Get a pointer to the encapsulated object.
|
| RResultPtr & | operator= (const RResultPtr &)=default |
| RResultPtr & | operator= (RResultPtr &&)=default |
|
| template<typename T1> |
| class | RResultPtr |
| template<class T1, class T2> |
| bool | operator!= (const RResultPtr< T1 > &lhs, const RResultPtr< T2 > &rhs) |
| template<class T1> |
| bool | operator!= (const RResultPtr< T1 > &lhs, std::nullptr_t rhs) |
| template<class T1> |
| bool | operator!= (std::nullptr_t lhs, const RResultPtr< T1 > &rhs) |
| template<class T1, class T2> |
| bool | operator== (const RResultPtr< T1 > &lhs, const RResultPtr< T2 > &rhs) |
| template<class T1> |
| bool | operator== (const RResultPtr< T1 > &lhs, std::nullptr_t rhs) |
| template<class T1> |
| bool | operator== (std::nullptr_t lhs, const RResultPtr< T1 > &rhs) |
| std::unique_ptr< RDFDetail::RMergeableValue< T > > | RDFDetail::GetMergeableValue (RResultPtr< T > &rptr) |
| template<typename T1> |
| RResultPtr< T1 > | RDFDetail::MakeResultPtr (const std::shared_ptr< T1 > &, ::ROOT::Detail::RDF::RLoopManager &, std::shared_ptr< RDFInternal::RActionBase >) |
| ROOT::Internal::RDF::SnapshotPtr_t | ROOT::Internal::RDF::CloneResultAndAction (const ROOT::Internal::RDF::SnapshotPtr_t &inptr, const std::string &outputFileName) |
| RResultPtr< T > | ROOT::Internal::RDF::CloneResultAndAction (const RResultPtr< T > &inptr) |
| class | ROOT::Internal::RDF::GraphDrawing::GraphCreatorHelper |
| template<typename T1> |
| ROOT::RDF::Experimental::RResultMap< T1 > | ROOT::RDF::Experimental::VariationsFor (RResultPtr< T1 > resPtr) |
| class | RResultHandle |
Register a callback that RDataFrame will execute "everyNEvents" on a partial result.
- Parameters
-
| [in] | everyNEvents | Frequency at which the callback will be called, as a number of events processed |
| [in] | callback | a callable with signature void(Value_t&) where Value_t is the type of the value contained in this RResultPtr |
- Returns
- this RResultPtr, to allow chaining of OnPartialResultSlot with other calls
The callback must be a callable (lambda, function, functor class...) that takes a reference to the result type as argument and returns nothing. RDataFrame will invoke registered callbacks passing partial action results as arguments to them (e.g. a histogram filled with a part of the selected events, a counter incremented only up to a certain point, a mean over a subset of the events and so forth).
Callbacks can be used e.g. to inspect partial results of the analysis while the event loop is running. For example one can draw an up-to-date version of a result histogram every 100 entries like this:
auto h = tdf.Histo1D(
"x");
h.OnPartialResult(100, [&
c](
TH1D &h_) {
c.cd(); h_.
Draw();
c.Update(); });
1-D histogram with a double per channel (see TH1 documentation)
void Draw(Option_t *option="") override
Draw this histogram with options.
A value of 0 for everyNEvents indicates the callback must be executed only once, before running the event loop. A conveniece definition kOnce is provided to make this fact more expressive in user code (see snippet below). Multiple callbacks can be registered with the same RResultPtr (i.e. results of RDataFrame actions) and will be executed sequentially. Callbacks are executed in the order they were registered. The type of the value contained in a RResultPtr is also available as RResultPtr<T>::Value_t, e.g.
auto h = tdf.Histo1D(
"x");
When implicit multi-threading is enabled, the callback:
- will never be executed by multiple threads concurrently: it needs not be thread-safe. For example the snippet above that draws the partial histogram on a canvas works seamlessly in multi-thread event loops.
- will be executed by the first worker that arrives at the callback, and then only be executed when the same result is updated. For example, if dataframe uses N internal copies of a result, it will always be the ith < N object that is passed into the callback.
- will always be executed "everyNEvents": the partial result passed into the callback will have accumulated N more events, irrespective of the progress that other worker threads make.
- might be executed by a different worker thread at different times: the value of std::this_thread::get_id() might change between calls.
To register a callback that is called by each worker thread (concurrently) every N events one can use OnPartialResultSlot().
Definition at line 332 of file RResultPtr.hxx.