Logo ROOT  
Reference Guide
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.
Definition: RActionImpl.hxx:26
Helper CallMakeNew(void *, Args...)
Definition: RActionImpl.hxx:58
auto CallFinalizeTask(unsigned int slot) -> decltype(std::declval< T >().FinalizeTask(slot))
Definition: RActionImpl.hxx:31
virtual ~RActionImpl()=default
auto CallMakeNew(void *typeErasedResSharedPtr) -> decltype(std::declval< T >().MakeNew(typeErasedResSharedPtr))
Definition: RActionImpl.hxx:52
virtual ROOT::RDF::SampleCallback_t GetSampleCallback()
Override this method to register a callback that is executed before the processing a new data sample ...
Definition: RActionImpl.hxx:73
auto CallPartialUpdate(unsigned int slot) -> decltype(std::declval< H >().PartialUpdate(slot),(void *)(nullptr))
Definition: RActionImpl.hxx:40
virtual std::unique_ptr< RMergeableValueBase > GetMergeableValue() const
Definition: RActionImpl.hxx:66
void CallFinalizeTask(unsigned int, Args...)
Definition: RActionImpl.hxx:37
std::function< void(unsigned int, const ROOT::RDF::RSampleInfo &)> SampleCallback_t
The type of a data-block callback, registered with a RDataFrame computation graph via e....
Definition: RSampleInfo.hxx:84
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.