11 #ifndef ROOT_RRESULTPTR 12 #define ROOT_RRESULTPTR 38 std::pair<RResultPtr<T>, std::shared_ptr<ROOT::Internal::RDF::RActionBase *>>
39 MakeResultPtr(
const std::shared_ptr<T> &
r,
const std::shared_ptr<RLoopManager> &df);
71 using SPT_t = std::shared_ptr<T>;
72 using SPTLM_t = std::shared_ptr<RDFDetail::RLoopManager>;
73 using WPTLM_t = std::weak_ptr<RDFDetail::RLoopManager>;
77 template <
typename T1>
80 template <
typename T1>
81 friend std::pair<RResultPtr<T1>, std::shared_ptr<RDFInternal::RActionBase *>>
83 template <
class T1,
class T2>
85 template <
class T1,
class T2>
97 template <typename V, bool hasBeginEnd = TTraits::HasBeginAndEnd<V>::value>
98 struct TIterationHelper {
99 using Iterator_t =
void;
100 void GetBegin(
const V &) { static_assert(
sizeof(V) == 0,
"It does not make sense to ask begin for this class."); }
101 void GetEnd(
const V &) { static_assert(
sizeof(V) == 0,
"It does not make sense to ask end for this class."); }
104 template <
typename V>
105 struct TIterationHelper<V, true> {
106 using Iterator_t = decltype(std::begin(std::declval<V>()));
107 static Iterator_t GetBegin(
const V &
v) {
return std::begin(v); };
108 static Iterator_t GetEnd(
const V &
v) {
return std::end(v); };
135 return fObjPtr.get();
140 : fReadiness(readiness), fImplWeakPtr(loopManager), fObjPtr(objPtr),
141 fActionPtrPtr(new (
RDFInternal::RActionBase *)(actionPtr))
145 std::shared_ptr<RDFInternal::RActionBase *>
GetActionPtrPtr()
const {
return fActionPtrPtr; }
156 explicit operator bool()
const {
return bool(fObjPtr); }
177 typename TIterationHelper<T>::Iterator_t
begin()
181 return TIterationHelper<T>::GetBegin(*fObjPtr);
186 typename TIterationHelper<T>::Iterator_t
end()
190 return TIterationHelper<T>::GetEnd(*fObjPtr);
237 auto lm = fImplWeakPtr.lock();
239 throw std::runtime_error(
"The main RDataFrame is not reachable: did it go out of scope?");
240 const auto nSlots = lm->GetNSlots();
241 auto actionPtrPtr = fActionPtrPtr.get();
242 auto c = [nSlots, actionPtrPtr, callback](
unsigned int slot) {
243 if (slot != nSlots - 1)
245 auto partialResult =
static_cast<Value_t *
>((*actionPtrPtr)->PartialUpdate(slot));
246 callback(*partialResult);
248 lm->RegisterCallback(everyNEvents, std::move(
c));
285 auto lm = fImplWeakPtr.lock();
287 throw std::runtime_error(
"The main RDataFrame is not reachable: did it go out of scope?");
288 auto actionPtrPtr = fActionPtrPtr.get();
289 auto c = [actionPtrPtr, callback](
unsigned int slot) {
290 auto partialResult =
static_cast<Value_t *
>((*actionPtrPtr)->PartialUpdate(slot));
291 callback(slot, *partialResult);
293 lm->RegisterCallback(everyNEvents, std::move(
c));
298 template <
typename T>
301 auto df = fImplWeakPtr.lock();
303 throw std::runtime_error(
"The main RDataFrame is not reachable: did it go out of scope?");
308 template <
class T1,
class T2>
314 template <
class T1,
class T2>
351 template <
typename T>
355 auto readiness = std::make_shared<bool>(
false);
363 template <
typename T>
364 std::pair<RResultPtr<T>, std::shared_ptr<RDFInternal::RActionBase *>>
365 MakeResultPtr(
const std::shared_ptr<T> &
r,
const std::shared_ptr<RLoopManager> &df)
367 auto readiness = std::make_shared<bool>(
false);
370 return std::make_pair(resPtr, resPtr.GetActionPtrPtr());
376 #endif // ROOT_TRESULTPROXY T * Get()
Get the pointer to the encapsulated 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 ...
Smart pointer for the return type of actions.
Namespace for new ROOT classes and functions.
std::shared_ptr< RDFDetail::RLoopManager > SPTLM_t
RResultPtr(const SPT_t &objPtr, const ShrdPtrBool_t &readiness, const SPTLM_t &loopManager, RDFInternal::RActionBase *actionPtr=nullptr)
void TriggerRun()
Triggers the event loop in the RLoopManager instance to which it's associated via the fImplWeakPtr...
std::shared_ptr< RDFInternal::RActionBase * > fActionPtrPtr
Shared_ptr to a pointer to the RDF action that produces this result.
SPT_t fObjPtr
Shared pointer encapsulating the wrapped result.
bool operator==(const RResultPtr< T1 > &lhs, const RResultPtr< T2 > &rhs)
T Value_t
Convenience alias to simplify access to proxied type.
RResultPtr< T > & OnPartialResult(ULong64_t everyNEvents, std::function< void(T &)> callback)
Register a callback that RDataFrame will execute "everyNEvents" on a partial result.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
bool operator!=(const RResultPtr< T1 > &lhs, const RResultPtr< T2 > &rhs)
std::weak_ptr< RDFDetail::RLoopManager > WPTLM_t
T * operator->()
Get a pointer to the encapsulated object.
std::shared_ptr< T > SPT_t
std::pair< RResultPtr< T >, std::shared_ptr< RDFInternal::RActionBase * > > MakeResultPtr(const std::shared_ptr< T > &r, const std::shared_ptr< RLoopManager > &df)
Create a RResultPtr and return it together with its pointer to RAction This overload is invoked by ji...
TIterationHelper< T >::Iterator_t end()
Return an iterator to the end of the contained object if this makes sense, throw a compilation error ...
WPTLM_t fImplWeakPtr
Points to the RLoopManager at the root of the functional graph.
unsigned long long ULong64_t
ROOT type_traits extensions.
std::shared_ptr< bool > ShrdPtrBool_t
Binding & operator=(OUT(*fun)(void))
typedef void((*Func_t)())
T & operator*()
Get a pointer to the encapsulated object.
T * GetPtr()
Get the pointer to the encapsulated object.
const T & GetValue()
Get a const reference to the encapsulated object.
std::shared_ptr< RDFInternal::RActionBase * > GetActionPtrPtr() const
TIterationHelper< T >::Iterator_t begin()
Return an iterator to the beginning of the contained object if this makes sense, throw a compilation ...