11 #ifndef ROOT_TRESULTPROXY 12 #define ROOT_TRESULTPROXY 23 namespace Experimental {
39 std::pair<TResultProxy<T>, std::shared_ptr<ROOT::Internal::TDF::TActionBase *>>
40 MakeResultProxy(
const std::shared_ptr<T> &
r,
const std::shared_ptr<TLoopManager> &df);
44 namespace Experimental {
72 using SPT_t = std::shared_ptr<T>;
73 using SPTLM_t = std::shared_ptr<TDFDetail::TLoopManager>;
74 using WPTLM_t = std::weak_ptr<TDFDetail::TLoopManager>;
82 friend std::pair<TResultProxy<W>, std::shared_ptr<TDFInternal::TActionBase *>>
86 template <typename V, bool isCont = TTraits::IsContainer<V>::value>
87 struct TIterationHelper {
88 using Iterator_t =
void;
89 void GetBegin(
const V &) { static_assert(
sizeof(V) == 0,
"It does not make sense to ask begin for this class."); }
90 void GetEnd(
const V &) { static_assert(
sizeof(V) == 0,
"It does not make sense to ask end for this class."); }
94 struct TIterationHelper<V, true> {
95 using Iterator_t = decltype(std::begin(std::declval<V>()));
96 static Iterator_t GetBegin(
const V &
v) {
return std::begin(v); };
97 static Iterator_t GetEnd(
const V &
v) {
return std::end(v); };
124 return fObjPtr.get();
129 : fReadiness(readiness), fImplWeakPtr(loopManager), fObjPtr(objPtr),
130 fActionPtrPtr(new (
TDFInternal::TActionBase *)(actionPtr))
134 std::shared_ptr<TDFInternal::TActionBase *>
GetActionPtrPtr()
const {
return fActionPtrPtr; }
159 typename TIterationHelper<T>::Iterator_t
begin()
163 return TIterationHelper<T>::GetBegin(*fObjPtr);
168 typename TIterationHelper<T>::Iterator_t
end()
172 return TIterationHelper<T>::GetEnd(*fObjPtr);
217 auto lm = fImplWeakPtr.lock();
219 throw std::runtime_error(
"The main TDataFrame is not reachable: did it go out of scope?");
220 const auto nSlots = lm->GetNSlots();
221 auto actionPtrPtr = fActionPtrPtr.get();
222 auto c = [nSlots, actionPtrPtr, callback](
unsigned int slot) {
223 if (slot != nSlots - 1)
225 auto partialResult =
static_cast<Value_t*
>((*actionPtrPtr)->PartialUpdate(slot));
226 callback(*partialResult);
228 lm->RegisterCallback(everyNEvents, std::move(c));
263 auto lm = fImplWeakPtr.lock();
265 throw std::runtime_error(
"The main TDataFrame is not reachable: did it go out of scope?");
266 auto actionPtrPtr = fActionPtrPtr.get();
267 auto c = [actionPtrPtr, callback](
unsigned int slot) {
268 auto partialResult =
static_cast<Value_t*
>((*actionPtrPtr)->PartialUpdate(slot));
269 callback(slot, *partialResult);
271 lm->RegisterCallback(everyNEvents, std::move(c));
276 template <
typename T>
279 auto df = fImplWeakPtr.lock();
281 throw std::runtime_error(
"The main TDataFrame is not reachable: did it go out of scope?");
292 template <
typename T>
296 auto readiness = std::make_shared<bool>(
false);
304 template <
typename T>
305 std::pair<TResultProxy<T>, std::shared_ptr<TDFInternal::TActionBase *>>
308 auto readiness = std::make_shared<bool>(
false);
311 return std::make_pair(resPtr, resPtr.GetActionPtrPtr());
317 #endif // ROOT_TRESULTPROXY
const T & GetValue()
Get a const reference to the encapsulated object.
const SPT_t fObjPtr
Shared pointer encapsulating the wrapped result.
Namespace for new ROOT classes and functions.
std::shared_ptr< TDFDetail::TLoopManager > SPTLM_t
T Value_t
Convenience alias to simplify access to proxied type.
std::shared_ptr< TDFInternal::TActionBase * > GetActionPtrPtr() const
T * Get()
Get the pointer to the encapsulated result.
TResultProxy< T > & OnPartialResult(ULong64_t everyNEvents, std::function< void(T &)> callback)
Register a callback that TDataFrame will execute "everyNEvents" on a partial result.
std::weak_ptr< TDFDetail::TLoopManager > WPTLM_t
WPTLM_t fImplWeakPtr
Points to the TLoopManager at the root of the functional graph.
TResultProxy< T > & OnPartialResultSlot(ULong64_t everyNEvents, std::function< void(unsigned int, T &)> callback)
Register a callback that TDataFrame will execute in each worker thread concurrently on that thread's ...
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Smart pointer for the return type of actions.
TIterationHelper< T >::Iterator_t begin()
Return an iterator to the beginning of the contained object if this makes sense, throw a compilation ...
const std::shared_ptr< TDFInternal::TActionBase * > fActionPtrPtr
Shared_ptr to a pointer to the TDF action that produces this result.
std::shared_ptr< T > SPT_t
std::pair< TResultProxy< T >, std::shared_ptr< TDFInternal::TActionBase * > > MakeResultProxy(const std::shared_ptr< T > &r, const std::shared_ptr< TLoopManager > &df)
Create a TResultProxy and return it together with its pointer to TAction This overload is invoked by ...
unsigned long long ULong64_t
ROOT type_traits extensions.
TResultProxy(const SPT_t &objPtr, const ShrdPtrBool_t &readiness, const SPTLM_t &loopManager, TDFInternal::TActionBase *actionPtr=nullptr)
T * operator->()
Get a pointer to the encapsulated object.
std::shared_ptr< bool > ShrdPtrBool_t
void TriggerRun()
Triggers the event loop in the TLoopManager instance to which it's associated via the fImplWeakPtr...
T & operator*()
Get a pointer to the encapsulated object.
typedef void((*Func_t)())
TIterationHelper< T >::Iterator_t end()
Return an iterator to the end of the contained object if this makes sense, throw a compilation error ...