Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:48

0001 /*************************************************************************
0002  * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers.               *
0003  * All rights reserved.                                                  *
0004  *                                                                       *
0005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0007  *************************************************************************/
0008 
0009 #ifndef ROOT_RDF_DETAIL_RACTIONIMPL
0010 #define ROOT_RDF_DETAIL_RACTIONIMPL
0011 
0012 #include <ROOT/RDF/RSampleInfo.hxx> // SampleCallback_t
0013 
0014 #include <memory> // std::unique_ptr
0015 #include <stdexcept> // std::logic_error
0016 #include <utility> // std::declval
0017 
0018 namespace ROOT::Internal::RDF {
0019 template <typename T>
0020 class HasMakeNew {
0021    template <typename C, typename = decltype(std::declval<C>().MakeNew((void *)(nullptr), std::string_view{}))>
0022    static std::true_type Test(int);
0023    template <typename C>
0024    static std::false_type Test(...);
0025 
0026 public:
0027    static constexpr bool value = decltype(Test<T>(0))::value;
0028 };
0029 } // namespace ROOT::Internal::RDF
0030 
0031 namespace ROOT {
0032 namespace Detail {
0033 namespace RDF {
0034 
0035 class RMergeableValueBase;
0036 
0037 /// Base class for action helpers, see RInterface::Book() for more information.
0038 template <typename Helper>
0039 class R__CLING_PTRCHECK(off) RActionImpl {
0040 public:
0041    virtual ~RActionImpl() = default;
0042    // call Helper::FinalizeTask if present, do nothing otherwise
0043    template <typename T = Helper>
0044    auto CallFinalizeTask(unsigned int slot) -> decltype(std::declval<T>().FinalizeTask(slot))
0045    {
0046       static_cast<Helper *>(this)->FinalizeTask(slot);
0047    }
0048 
0049    template <typename... Args>
0050    void CallFinalizeTask(unsigned int, Args...) {}
0051 
0052    template <typename H = Helper>
0053    auto CallPartialUpdate(unsigned int slot) -> decltype(std::declval<H>().PartialUpdate(slot), (void *)(nullptr))
0054    {
0055       return &static_cast<Helper *>(this)->PartialUpdate(slot);
0056    }
0057 
0058    template <typename... Args>
0059    [[noreturn]] void *CallPartialUpdate(...)
0060    {
0061       throw std::logic_error("This action does not support callbacks!");
0062    }
0063 
0064    Helper CallMakeNew(void *typeErasedResSharedPtr, std::string_view variation = "nominal")
0065    {
0066       if constexpr (ROOT::Internal::RDF::HasMakeNew<Helper>::value)
0067          return static_cast<Helper *>(this)->MakeNew(typeErasedResSharedPtr, variation);
0068       else {
0069          // Avoid unused parameter warning with GCC
0070          (void)typeErasedResSharedPtr;
0071          (void)variation;
0072          const auto &actionName = static_cast<Helper *>(this)->GetActionName();
0073          throw std::logic_error("The MakeNew method is not implemented for this action helper (" + actionName +
0074                                 "). Cannot Vary its result.");
0075       }
0076    }
0077 
0078    // Helper functions for RMergeableValue
0079    virtual std::unique_ptr<RMergeableValueBase> GetMergeableValue() const
0080    {
0081       throw std::logic_error("`GetMergeableValue` is not implemented for this type of action.");
0082    }
0083 
0084    /// Override this method to register a callback that is executed before the processing a new data sample starts.
0085    /// The callback will be invoked in the same conditions as with DefinePerSample().
0086    virtual ROOT::RDF::SampleCallback_t GetSampleCallback() { return {}; }
0087 };
0088 
0089 } // namespace RDF
0090 } // namespace Detail
0091 } // namespace ROOT
0092 
0093 #endif // ROOT_RDF_DETAIL_RACTIONIMPL
0094