Logo ROOT   6.08/07
Reference Guide
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
TMPWorker Class Reference

This class works in conjuction with TMPClient, reacting to messages received from it as specified by the Notify and HandleInput methods.

When TMPClient::Fork is called, a TMPWorker instance is passed to it which will take control of the ROOT session in the children processes.

After forking, every time a message is sent or broadcast to the workers, TMPWorker::Notify is called and the message is retrieved. Messages exchanged between TMPClient and TMPWorker should be sent with the MPSend() standalone function.
If the code of the message received is above 1000 (i.e. it is an MPCode) the qualified TMPWorker::HandleInput method is called, that takes care of handling the most generic type of messages. Otherwise the unqualified (possibly overridden) version of HandleInput is called, allowing classes that inherit from TMPWorker to manage their own protocol.
An application's worker class should inherit from TMPWorker and implement a HandleInput method that overrides TMPWorker's.

Definition at line 30 of file TMPWorker.h.

Public Member Functions

 TMPWorker ()
 Class constructors. More...
 
 TMPWorker (const std::vector< std::string > &fileNames, const std::string &treeName, unsigned nWorkers, ULong64_t maxEntries)
 
 TMPWorker (TTree *tree, unsigned nWorkers, ULong64_t maxEntries)
 
 TMPWorker (const TMPWorker &)=delete
 
virtual ~TMPWorker ()
 
unsigned GetNWorker () const
 
pid_t GetPid ()
 
TSocketGetSocket ()
 
virtual void Init (int fd, unsigned workerN)
 This method is called by children processes right after forking. More...
 
TMPWorkeroperator= (const TMPWorker &)=delete
 
void Run ()
 

Protected Member Functions

void CloseFile ()
 Handle file closing. More...
 
TFileOpenFile (const std::string &fileName)
 Handle file opening. More...
 
TTreeRetrieveTree (TFile *fp)
 Retrieve a tree from an open file. More...
 
void SendError (const std::string &errmsg, unsigned int code=MPCode::kError)
 Error sender. More...
 
void Setup ()
 Auxilliary method for common initializations. More...
 
void SetupTreeCache (TTree *tree)
 Tree cache handling. More...
 

Protected Attributes

TFilefFile
 last open file More...
 
std::vector< std::string > fFileNames
 the files to be processed by all workers More...
 
std::string fId
 identifier string in the form W<nwrk>|P<proc id>=""> More...
 
ULong64_t fMaxNEntries
 the maximum number of entries to be processed by this worker More...
 
unsigned fNWorkers
 the number of workers spawned More...
 
ULong64_t fProcessedEntries
 the number of entries processed by this worker so far More...
 
TTreefTree
 pointer to the tree to be processed. It is only used if the tree is directly passed to TProcessExecutor::Process as argument More...
 
std::string fTreeName
 the name of the tree to be processed More...
 

Private Member Functions

virtual void HandleInput (MPCodeBufPair &msg)
 Handle a message with an EMPCode. More...
 

Private Attributes

Long64_t fCacheSize
 
unsigned fNWorker
 the ordinal number of this worker (0 to nWorkers-1) More...
 
pid_t fPid
 the PID of the process in which this worker is running More...
 
std::unique_ptr< TSocketfS
 This worker's socket. The unique_ptr makes sure resources are released. More...
 
TTreeCachefTreeCache
 
Bool_t fTreeCacheIsLearning
 
Bool_t fUseTreeCache
 

#include <TMPWorker.h>

Inheritance diagram for TMPWorker:
[legend]

Constructor & Destructor Documentation

◆ TMPWorker() [1/4]

TMPWorker::TMPWorker ( )

Class constructors.

Note that this does not set variables like fPid or fS (worker's socket).
These operations are handled by the Init method, which is called after forking.
This separation is in place because the instantiation of a worker must be done once before forking, while the initialization of the members must be done after forking by each of the children processes.

Definition at line 56 of file TMPWorker.cxx.

◆ TMPWorker() [2/4]

TMPWorker::TMPWorker ( const std::vector< std::string > &  fileNames,
const std::string &  treeName,
unsigned  nWorkers,
ULong64_t  maxEntries 
)

Definition at line 66 of file TMPWorker.cxx.

◆ TMPWorker() [3/4]

TMPWorker::TMPWorker ( TTree tree,
unsigned  nWorkers,
ULong64_t  maxEntries 
)

Definition at line 78 of file TMPWorker.cxx.

◆ ~TMPWorker()

TMPWorker::~TMPWorker ( )
virtual

Definition at line 88 of file TMPWorker.cxx.

◆ TMPWorker() [4/4]

TMPWorker::TMPWorker ( const TMPWorker )
delete

Member Function Documentation

◆ CloseFile()

void TMPWorker::CloseFile ( )
protected

Handle file closing.

Definition at line 172 of file TMPWorker.cxx.

◆ GetNWorker()

unsigned TMPWorker::GetNWorker ( ) const
inline

Definition at line 47 of file TMPWorker.h.

◆ GetPid()

pid_t TMPWorker::GetPid ( )
inline

Definition at line 46 of file TMPWorker.h.

◆ GetSocket()

TSocket* TMPWorker::GetSocket ( )
inline

Definition at line 45 of file TMPWorker.h.

◆ HandleInput()

void TMPWorker::HandleInput ( MPCodeBufPair msg)
privatevirtual

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 in TPoolWorker< F, T, void >, TPoolWorker< F, void, R >, TPoolWorker< F, T, R >, TPoolProcessor< F >, and TPoolPlayer.

Definition at line 145 of file TMPWorker.cxx.

◆ Init()

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

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.

Reimplemented in TPoolProcessor< F >, and TPoolPlayer.

Definition at line 111 of file TMPWorker.cxx.

◆ OpenFile()

TFile * TMPWorker::OpenFile ( const std::string &  fileName)
protected

Handle file opening.

Definition at line 185 of file TMPWorker.cxx.

◆ operator=()

TMPWorker& TMPWorker::operator= ( const TMPWorker )
delete

◆ RetrieveTree()

TTree * TMPWorker::RetrieveTree ( TFile fp)
protected

Retrieve a tree from an open file.

Definition at line 204 of file TMPWorker.cxx.

◆ Run()

void TMPWorker::Run ( )

Definition at line 120 of file TMPWorker.cxx.

◆ SendError()

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

Error sender.

Definition at line 268 of file TMPWorker.cxx.

◆ Setup()

void TMPWorker::Setup ( )
protected

Auxilliary method for common initializations.

Definition at line 96 of file TMPWorker.cxx.

◆ SetupTreeCache()

void TMPWorker::SetupTreeCache ( TTree tree)
protected

Tree cache handling.

Definition at line 236 of file TMPWorker.cxx.

Member Data Documentation

◆ fCacheSize

Long64_t TMPWorker::fCacheSize
private

Definition at line 78 of file TMPWorker.h.

◆ fFile

TFile* TMPWorker::fFile
protected

last open file

Definition at line 54 of file TMPWorker.h.

◆ fFileNames

std::vector<std::string> TMPWorker::fFileNames
protected

the files to be processed by all workers

Definition at line 51 of file TMPWorker.h.

◆ fId

std::string TMPWorker::fId
protected

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

Definition at line 50 of file TMPWorker.h.

◆ fMaxNEntries

ULong64_t TMPWorker::fMaxNEntries
protected

the maximum number of entries to be processed by this worker

Definition at line 56 of file TMPWorker.h.

◆ fNWorker

unsigned TMPWorker::fNWorker
private

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

Definition at line 71 of file TMPWorker.h.

◆ fNWorkers

unsigned TMPWorker::fNWorkers
protected

the number of workers spawned

Definition at line 55 of file TMPWorker.h.

◆ fPid

pid_t TMPWorker::fPid
private

the PID of the process in which this worker is running

Definition at line 70 of file TMPWorker.h.

◆ fProcessedEntries

ULong64_t TMPWorker::fProcessedEntries
protected

the number of entries processed by this worker so far

Definition at line 57 of file TMPWorker.h.

◆ fS

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

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

Definition at line 69 of file TMPWorker.h.

◆ fTree

TTree* TMPWorker::fTree
protected

pointer to the tree to be processed. It is only used if the tree is directly passed to TProcessExecutor::Process as argument

Definition at line 53 of file TMPWorker.h.

◆ fTreeCache

TTreeCache* TMPWorker::fTreeCache
private

Definition at line 75 of file TMPWorker.h.

◆ fTreeCacheIsLearning

Bool_t TMPWorker::fTreeCacheIsLearning
private

Definition at line 76 of file TMPWorker.h.

◆ fTreeName

std::string TMPWorker::fTreeName
protected

the name of the tree to be processed

Definition at line 52 of file TMPWorker.h.

◆ fUseTreeCache

Bool_t TMPWorker::fUseTreeCache
private

Definition at line 77 of file TMPWorker.h.


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