12 #ifndef ROOT_TPoolWorker
13 #define ROOT_TPoolWorker
39 template<
class F,
class T =
void,
class R =
void>
46 TMPWorker(), fFunc(func), fArgs(
std::move(args)), fRedFunc(redfunc),
53 unsigned code = msg.first;
55 std::string reply =
"S" + std::to_string(
GetNWorker());
58 msg.second->ReadUInt(n);
60 const auto &res =
fFunc(fArgs[n]);
73 reply +=
": unknown code received: " + std::to_string(code);
91 TMPWorker(), fFunc(func), fRedFunc(redfunc),
98 unsigned code = msg.first;
100 std::string reply =
"S" + std::to_string(
GetNWorker());
103 const auto &res =
fFunc();
116 reply +=
": unknown code received: " + std::to_string(code);
131 TPoolWorker(F func,
const std::vector<T> &args) : TMPWorker(), fFunc(func), fArgs(
std::move(args)) {}
135 unsigned code = msg.first;
137 std::string reply =
"S" + std::to_string(
GetNWorker());
140 msg.second->ReadUInt(n);
143 reply +=
": unknown code received: " + std::to_string(code);
161 class TPoolWorker<F, void, void> :
public TMPWorker {
167 unsigned code = msg.first;
169 std::string myId =
"S" + std::to_string(
GetPid());
The message contains the result of a function execution.
void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
F fFunc
the function to be executed
Small helper to encapsulate whether to return the value pointed to by the iterator or its address...
R fRedFunc
the reduce function
int MPSend(TSocket *s, unsigned code)
Send a message with the specified code on the specified socket.
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
We are ready for the next task.
unsigned GetNWorker() const
R fRedFunc
the reduce function
decltype(fFunc(fArgs.front())) fReducedResult
the result of the execution
F fFunc
the function to be executed
TMPWorker()
Class constructor.
Execute function with the argument contained in the message.
F fFunc
the function to be executed
std::pair< unsigned, std::unique_ptr< TBufferFile >> MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
TPoolWorker(F func, const std::vector< T > &args)
Execute function without arguments.
void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
Ask for a kFuncResult/kProcResult.
This class works together with TProcPool to allow the execution of functions in server processes...
TPoolWorker(F func, R redfunc)
TPoolWorker(F func, const std::vector< T > &args, R redfunc)
std::vector< T > fArgs
a vector containing the arguments that must be passed to fFunc
std::vector< T > fArgs
a vector containing the arguments that must be passed to fFunc
void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.