12#ifndef ROOT_TExecutorCRTP
13#define ROOT_TExecutorCRTP
19#include <initializer_list>
111 template<
class F,
class... T>
112 using noReferenceCond =
typename std::enable_if<
"Function can't return a reference" && !(std::is_reference<
typename std::result_of<
F(T...)>
::type>::value)>
::type;
116 template<
class F,
class Cond = noReferenceCond<F>>
117 auto Map(
F func,
unsigned nTimes) -> std::vector<
typename std::result_of<
F()>
::type>;
118 template<
class F,
class INTEGER,
class Cond = noReferenceCond<F, INTEGER>>
120 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
121 auto Map(
F func, std::initializer_list<T> args) -> std::vector<
typename std::result_of<
F(T)>
::type>;
122 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
123 auto Map(
F func, std::vector<T> &args) -> std::vector<
typename std::result_of<
F(T)>
::type>;
124 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
125 auto Map(
F func,
const std::vector<T> &args) -> std::vector<
typename std::result_of<
F(T)>
::type>;
130 template<
class F,
class R,
class Cond = noReferenceCond<F>>
132 template<
class F,
class INTEGER,
class R,
class Cond = noReferenceCond<F, INTEGER>>
134 template<
class F,
class T,
class R,
class Cond = noReferenceCond<F, T>>
135 auto MapReduce(
F func, std::initializer_list<T> args,
R redfunc) ->
typename std::result_of<
F(T)>
::type;
136 template<
class F,
class T,
class R,
class Cond = noReferenceCond<F, T>>
137 auto MapReduce(
F func,
const std::vector<T> &args,
R redfunc) ->
typename std::result_of<
F(T)>
::type;
138 template<
class F,
class T,
class R,
class Cond = noReferenceCond<F, T>>
140 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
142 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
145 template<
class T> T*
Reduce(
const std::vector<T*> &mergeObjs);
146 template<
class T,
class R>
auto Reduce(
const std::vector<T> &objs,
R redfunc) ->
decltype(redfunc(objs));
152 return *
static_cast<SubC*
>(
this);
156 template<
class F,
class Cond = noReferenceCond<F>>
157 auto MapImpl(
F func,
unsigned nTimes) -> std::vector<
typename std::result_of<
F()>
::type> =
delete;
159 template<
class F,
class INTEGER,
class Cond = noReferenceCond<F, INTEGER>>
162 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
163 auto MapImpl(
F func, std::vector<T> &args) -> std::vector<
typename std::result_of<
F(T)>
::type> =
delete;
165 template<
class F,
class T,
class Cond = noReferenceCond<F, T>>
166 auto MapImpl(
F func,
const std::vector<T> &args) -> std::vector<
typename std::result_of<
F(T)>
::type> =
delete;
178template<
class SubC>
template<
class F,
class Cond>
181 return Derived().MapImpl(func, nTimes);
190template<
class SubC>
template<
class F,
class INTEGER,
class Cond>
193 return Derived().MapImpl(func, args);
202template<
class SubC>
template<
class F,
class T,
class Cond>
205 std::vector<T> vargs(std::move(args));
206 const auto &reslist = Map(func, vargs);
216template<
class SubC>
template<
class F,
class T,
class Cond>
219 return Derived().MapImpl(func, args);
229template<
class SubC>
template<
class F,
class T,
class Cond>
232 return Derived().MapImpl(func, args);
243template<
class SubC>
template<
class F,
class R,
class Cond>
246 return Reduce(Map(func, nTimes), redfunc);
256template<
class SubC>
template<
class F,
class INTEGER,
class R,
class Cond>
259 return Reduce(Map(func, args), redfunc);
269template<
class SubC>
template<
class F,
class T,
class R,
class Cond>
272 std::vector<T> vargs(std::move(args));
273 return Reduce(Map(func, vargs), redfunc);
283template<
class SubC>
template<
class F,
class T,
class R,
class Cond>
286 return Reduce(Map(func, args), redfunc);
295template<
class SubC>
template<
class F,
class T,
class R,
class Cond>
298 return Reduce(Map(func, args), redfunc);
307template<
class SubC>
template<
class F,
class T,
class Cond>
310 return Reduce(Map(func, args));
320template<
class SubC>
template<
class F,
class T,
class Cond>
323 return Reduce(Map(func, args));
331template<
class SubC>
template<
class T>
336 Error(
"TExecutorCRTP<SubC>::Reduce",
"could not find merge method for the TObject\n. Aborting operation.");
341 for(
unsigned i =1; i<mergeObjs.size(); i++){
345 auto retHist =
dynamic_cast<T*
>((mergeObjs.front())->Clone());
346 if (retHist) retHist->Merge(&
l);
357template<
class SubC>
template<
class T,
class R>
361 static_assert(std::is_same<
decltype(redfunc(objs)), T>::value,
"redfunc does not have the correct signature");
362 return redfunc(objs);
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
This class defines an interface to execute the same task multiple times, possibly in parallel and wit...
auto MapReduce(F func, const std::vector< T > &args, R redfunc) -> typename std::result_of< F(T)>::type
Execute a function over the elements of an immutable vector (Map) and accumulate the results into a s...
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Execute a function without arguments several times.
auto MapReduce(F func, std::vector< T > &args, R redfunc) -> typename std::result_of< F(T)>::type
Execute a function over the elements of a vector (Map) and accumulate the results into a single value...
auto Map(F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >
Execute a function over the elements of a vector.
auto MapReduce(F func, std::initializer_list< T > args, R redfunc) -> typename std::result_of< F(T)>::type
Execute a function over the elements of an initializer_list (Map) and accumulate the results into a s...
auto Map(F func, std::initializer_list< T > args) -> std::vector< typename std::result_of< F(T)>::type >
Execute a function over the elements of an initializer_list.
auto MapImpl(F func, std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >=delete
Implementation of the Map method, left to the derived classes.
auto MapImpl(F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type >=delete
Implementation of the Map method, left to the derived classes.
T * MapReduce(F func, const std::vector< T * > &args)
Execute a function over the TObject-inheriting elements of an immutable vector (Map) and merge the ob...
auto MapReduce(F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type
Execute a function without arguments several times (Map) and accumulate the results into a single val...
auto Map(F func, const std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >
Execute a function over the elements of an immutable vector.
auto Map(F func, ROOT::TSeq< INTEGER > args) -> std::vector< typename std::result_of< F(INTEGER)>::type >
Execute a function over a sequence of indexes.
typename std::enable_if<"Function can't return a reference" &&!(std::is_reference< typename std::result_of< F(T...)>::type >::value)>::type noReferenceCond
type definition in used in templated functions for not allowing mapping functions that return referen...
TExecutorCRTP(const TExecutorCRTP &)=delete
auto MapImpl(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >=delete
Implementation of the Map method, left to the derived classes.
T * Reduce(const std::vector< T * > &mergeObjs)
"Reduce" an std::vector into a single object by using the object's Merge method.
T * MapReduce(F func, std::vector< T * > &args)
Execute a function over the TObject-inheriting elements of a vector (Map) and merge the objects into ...
auto MapImpl(F func, const std::vector< T > &args) -> std::vector< typename std::result_of< F(T)>::type >=delete
Implementation of the Map method, left to the derived classes.
auto Reduce(const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
"Reduce" an std::vector into a single object by passing a function as the second argument defining th...
TExecutorCRTP & operator=(const TExecutorCRTP &)=delete
auto MapReduce(F func, ROOT::TSeq< INTEGER > args, R redfunc) -> typename std::result_of< F(INTEGER)>::type
Execute a function over a sequence of indexes (Map) and accumulate the results into a single value (R...
A pseudo container class which is a generator of indices.
virtual void Add(TObject *obj)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Long64_t(* MergeFunc_t)(void *, TCollection *, TFileMergeInfo *)