Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TMPWorkerExecutor< F, T, R > Class Template Reference

template<class F, class T = void, class R = void>
class TMPWorkerExecutor< F, T, R >

This class works together with TProcessExecutor to allow the execution of functions in server processes.

Depending on the exact task that the worker is required to execute, a different version of the class can be called.

TMPWorkerExecutor<F, T, R>

The most general case, used by TProcessExecutor::MapReduce(F func, T& args, R redfunc). This worker is build with:

  • a function of signature F (the one to be executed)
  • a collection of arguments of type T on which to apply the function
  • a reduce function with signature R to be used to squash many returned values together.

Partial specializations

A few partial specializations are provided for less general cases:

  • TMPWorkerExecutor<F, T, void> handles the case of a function that takes one argument and does not perform reduce operations (TProcessExecutor::Map(F func, T& args)).
  • TMPWorkerExecutor<F, void, R> handles the case of a function that takes no arguments, to be executed a specified amount of times, which returned values are squashed together (reduced) (TProcessExecutor::Map(F func, unsigned nTimes, R redfunc))
  • TMPWorkerExecutor<F, void, void> handles the case of a function that takes no arguments and whose arguments are not "reduced" (TProcessExecutor::Map(F func, unsigned nTimes))

Since all the important data are passed to TMPWorkerExecutor at construction time, the kind of messages that client and workers have to exchange are usually very simple.

Definition at line 78 of file TMPWorkerExecutor.h.

Public Member Functions

 TMPWorkerExecutor (F func, const std::vector< T > &args, R redfunc)
 ~TMPWorkerExecutor ()
unsigned GetNWorker () const
pid_t GetPid ()
TSocketGetSocket ()
void HandleInput (MPCodeBufPair &msg)
 Handle a message with an EMPCode.
virtual void Init (int fd, unsigned workerN)
 This method is called by children processes right after forking.
void Run ()

Protected Member Functions

void SendError (const std::string &errmsg, unsigned int code=MPCode::kError)
 Error sender.

Protected Attributes

std::string fId
 identifier string in the form W<nwrk>|P<proc id>
ULong64_t fMaxNEntries
 the maximum number of entries to be processed by this worker
unsigned fNWorkers
 the number of workers spawned
ULong64_t fProcessedEntries
 the number of entries processed by this worker so far

Private Attributes

std::vector< T > fArgs
 a vector containing the arguments that must be passed to fFunc
bool fCanReduce
 true if fReducedResult can be reduced with a new result, false until we have produced one result
F fFunc
 the function to be executed
unsigned fNWorker
 the ordinal number of this worker (0 to nWorkers-1)
pid_t fPid
 the PID of the process in which this worker is running
R fRedFunc
 the reduce function
decltype(fFunc(fArgs.front())) fReducedResult
 the result of the execution
std::unique_ptr< TSocketfS
 This worker's socket. The unique_ptr makes sure resources are released.

#include <TMPWorkerExecutor.h>

Inheritance diagram for TMPWorkerExecutor< F, T, R >:
TMPWorker

Constructor & Destructor Documentation

◆ TMPWorkerExecutor()

template<class F, class T = void, class R = void>
TMPWorkerExecutor< F, T, R >::TMPWorkerExecutor ( F func,
const std::vector< T > & args,
R redfunc )
inline

Definition at line 83 of file TMPWorkerExecutor.h.

◆ ~TMPWorkerExecutor()

template<class F, class T = void, class R = void>
TMPWorkerExecutor< F, T, R >::~TMPWorkerExecutor ( )
inline

Definition at line 87 of file TMPWorkerExecutor.h.

Member Function Documentation

◆ GetNWorker()

unsigned TMPWorker::GetNWorker ( ) const
inlineinherited

Definition at line 41 of file TMPWorker.h.

◆ GetPid()

pid_t TMPWorker::GetPid ( )
inlineinherited

Definition at line 40 of file TMPWorker.h.

◆ GetSocket()

TSocket * TMPWorker::GetSocket ( )
inlineinherited

Definition at line 39 of file TMPWorker.h.

◆ HandleInput()

template<class F, class T = void, class R = void>
void TMPWorkerExecutor< F, T, R >::HandleInput ( MPCodeBufPair & msg)
inlinevirtual

Handle a message with an EMPCode.

This method is called upon receiving a message with a code >= 1000 (i.e. EMPCode). It handles the most generic types of messages.
Classes inheriting from TMPWorker should implement their own HandleInput function, that should be able to handle codes specific to that application.
The appropriate version of the HandleInput method (TMPWorker's or the overriding version) is automatically called depending on the message code.

Reimplemented from TMPWorker.

Definition at line 89 of file TMPWorkerExecutor.h.

◆ Init()

void TMPWorker::Init ( int fd,
unsigned workerN )
virtualinherited

This method is called by children processes right after forking.

Initialization of worker properties that must be delayed until after forking must be done here.
For example, Init saves the pid into fPid, and adds the TMPWorker to the main eventloop (as a TFileHandler).
Make sure this operations are performed also by overriding implementations, e.g. by calling TMPWorker::Init explicitly.

Definition at line 52 of file TMPWorker.cxx.

◆ Run()

void TMPWorker::Run ( )
inherited

Definition at line 61 of file TMPWorker.cxx.

◆ SendError()

void TMPWorker::SendError ( const std::string & errmsg,
unsigned int code = MPCode::kError )
protectedinherited

Error sender.

Definition at line 112 of file TMPWorker.cxx.

Member Data Documentation

◆ fArgs

template<class F, class T = void, class R = void>
std::vector<T> TMPWorkerExecutor< F, T, R >::fArgs
private

a vector containing the arguments that must be passed to fFunc

Definition at line 120 of file TMPWorkerExecutor.h.

◆ fCanReduce

template<class F, class T = void, class R = void>
bool TMPWorkerExecutor< F, T, R >::fCanReduce
private

true if fReducedResult can be reduced with a new result, false until we have produced one result

Definition at line 123 of file TMPWorkerExecutor.h.

◆ fFunc

template<class F, class T = void, class R = void>
F TMPWorkerExecutor< F, T, R >::fFunc
private

the function to be executed

Definition at line 119 of file TMPWorkerExecutor.h.

◆ fId

std::string TMPWorker::fId
protectedinherited

identifier string in the form W<nwrk>|P<proc id>

Definition at line 44 of file TMPWorker.h.

◆ fMaxNEntries

ULong64_t TMPWorker::fMaxNEntries
protectedinherited

the maximum number of entries to be processed by this worker

Definition at line 46 of file TMPWorker.h.

◆ fNWorker

unsigned TMPWorker::fNWorker
privateinherited

the ordinal number of this worker (0 to nWorkers-1)

Definition at line 56 of file TMPWorker.h.

◆ fNWorkers

unsigned TMPWorker::fNWorkers
protectedinherited

the number of workers spawned

Definition at line 45 of file TMPWorker.h.

◆ fPid

pid_t TMPWorker::fPid
privateinherited

the PID of the process in which this worker is running

Definition at line 55 of file TMPWorker.h.

◆ fProcessedEntries

ULong64_t TMPWorker::fProcessedEntries
protectedinherited

the number of entries processed by this worker so far

Definition at line 47 of file TMPWorker.h.

◆ fRedFunc

template<class F, class T = void, class R = void>
R TMPWorkerExecutor< F, T, R >::fRedFunc
private

the reduce function

Definition at line 121 of file TMPWorkerExecutor.h.

◆ fReducedResult

template<class F, class T = void, class R = void>
decltype(fFunc(fArgs.front())) TMPWorkerExecutor< F, T, R >::fReducedResult
private

the result of the execution

Definition at line 122 of file TMPWorkerExecutor.h.

◆ fS

std::unique_ptr<TSocket> TMPWorker::fS
privateinherited

This worker's socket. The unique_ptr makes sure resources are released.

Definition at line 54 of file TMPWorker.h.


The documentation for this class was generated from the following file: