Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RActionImpl.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT_RDF_DETAIL_RACTIONIMPL
10#define ROOT_RDF_DETAIL_RACTIONIMPL
11
12#include <ROOT/RDF/RSampleInfo.hxx> // SampleCallback_t
13
14#include <memory> // std::unique_ptr
15#include <stdexcept> // std::logic_error
16#include <utility> // std::declval
17
18namespace ROOT {
19namespace Detail {
20namespace RDF {
21
22class RMergeableValueBase;
23
24/// Base class for action helpers, see RInterface::Book() for more information.
25template <typename Helper>
26class R__CLING_PTRCHECK(off) RActionImpl {
27public:
28 virtual ~RActionImpl() = default;
29 // call Helper::FinalizeTask if present, do nothing otherwise
30 template <typename T = Helper>
31 auto CallFinalizeTask(unsigned int slot) -> decltype(std::declval<T>().FinalizeTask(slot))
32 {
33 static_cast<Helper *>(this)->FinalizeTask(slot);
34 }
35
36 template <typename... Args>
37 void CallFinalizeTask(unsigned int, Args...) {}
38
39 template <typename H = Helper>
40 auto CallPartialUpdate(unsigned int slot) -> decltype(std::declval<H>().PartialUpdate(slot), (void *)(nullptr))
41 {
42 return &static_cast<Helper *>(this)->PartialUpdate(slot);
43 }
44
45 template <typename... Args>
46 [[noreturn]] void *CallPartialUpdate(...)
47 {
48 throw std::logic_error("This action does not support callbacks!");
49 }
50
51 template <typename T = Helper>
52 auto CallMakeNew(void *typeErasedResSharedPtr) -> decltype(std::declval<T>().MakeNew(typeErasedResSharedPtr))
53 {
54 return static_cast<Helper *>(this)->MakeNew(typeErasedResSharedPtr);
55 }
56
57 template <typename... Args>
58 [[noreturn]] Helper CallMakeNew(void *, Args...)
59 {
60 const auto &actionName = static_cast<Helper *>(this)->GetActionName();
61 throw std::logic_error("The MakeNew method is not implemented for this action helper (" + actionName +
62 "). Cannot Vary its result.");
63 }
64
65 // Helper functions for RMergeableValue
66 virtual std::unique_ptr<RMergeableValueBase> GetMergeableValue() const
67 {
68 throw std::logic_error("`GetMergeableValue` is not implemented for this type of action.");
69 }
70
71 /// Override this method to register a callback that is executed before the processing a new data sample starts.
72 /// The callback will be invoked in the same conditions as with DefinePerSample().
74};
75
76} // namespace RDF
77} // namespace Detail
78} // namespace ROOT
79
80#endif // ROOT_RDF_DETAIL_RACTIONIMPL
81
Base class for action helpers, see RInterface::Book() for more information.
Helper CallMakeNew(void *, Args...)
auto CallFinalizeTask(unsigned int slot) -> decltype(std::declval< T >().FinalizeTask(slot))
virtual ~RActionImpl()=default
auto CallMakeNew(void *typeErasedResSharedPtr) -> decltype(std::declval< T >().MakeNew(typeErasedResSharedPtr))
virtual ROOT::RDF::SampleCallback_t GetSampleCallback()
Override this method to register a callback that is executed before the processing a new data sample ...
auto CallPartialUpdate(unsigned int slot) -> decltype(std::declval< H >().PartialUpdate(slot),(void *)(nullptr))
virtual std::unique_ptr< RMergeableValueBase > GetMergeableValue() const
void CallFinalizeTask(unsigned int, Args...)
std::function< void(unsigned int, const ROOT::RDF::RSampleInfo &)> SampleCallback_t
The type of a data-block callback, registered with an RDataFrame computation graph via e....
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...