Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMPWorker.h
Go to the documentation of this file.
1/* @(#)root/multiproc:$Id$ */
2// Author: Enrico Guiraud July 2015
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TMPWorker
13#define ROOT_TMPWorker
14
15#include "MPCode.h"
16#include "MPSendRecv.h" //MPCodeBufPair
17#include "PoolUtils.h"
18#include "TSysEvtHandler.h" //TFileHandler
19
20#include <memory> //unique_ptr
21#include <string>
22#include <sstream>
23#include <unistd.h> //pid_t
24
25class TMPWorker {
26public:
28 fProcessedEntries(0), fS(), fPid(0), fNWorker(0) { }
29 TMPWorker(unsigned nWorkers, ULong64_t maxEntries)
30 : fNWorkers(nWorkers), fMaxNEntries(maxEntries),
31 fProcessedEntries(0), fS(), fPid(0), fNWorker(0) { }
32 virtual ~TMPWorker() { }
33 //it doesn't make sense to copy a TMPWorker (each one has a uniq_ptr to its socket)
34 TMPWorker(const TMPWorker &) = delete;
35 TMPWorker &operator=(const TMPWorker &) = delete;
36
37 virtual void Init(int fd, unsigned workerN);
38 void Run();
39 TSocket *GetSocket() { return fS.get(); }
40 pid_t GetPid() { return fPid; }
41 unsigned GetNWorker() const { return fNWorker; }
42
43protected:
44 std::string fId; ///< identifier string in the form `W<nwrk>|P<proc id>`
45 unsigned fNWorkers; ///< the number of workers spawned
46 ULong64_t fMaxNEntries; ///< the maximum number of entries to be processed by this worker
47 ULong64_t fProcessedEntries; ///< the number of entries processed by this worker so far
48
49 void SendError(const std::string& errmsg, unsigned int code = MPCode::kError);
50
51private:
52 virtual void HandleInput(MPCodeBufPair &msg);
53
54 std::unique_ptr<TSocket> fS; ///< This worker's socket. The unique_ptr makes sure resources are released.
55 pid_t fPid; ///< the PID of the process in which this worker is running
56 unsigned fNWorker; ///< the ordinal number of this worker (0 to nWorkers-1)
57};
58
59#endif
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
Definition MPSendRecv.h:32
unsigned long long ULong64_t
Definition RtypesCore.h:70
This class works in conjuction with TMPClient, reacting to messages received from it as specified by ...
Definition TMPWorker.h:25
void SendError(const std::string &errmsg, unsigned int code=MPCode::kError)
Error sender.
unsigned GetNWorker() const
Definition TMPWorker.h:41
std::string fId
identifier string in the form W<nwrk>|P<proc id>
Definition TMPWorker.h:44
pid_t GetPid()
Definition TMPWorker.h:40
ULong64_t fMaxNEntries
the maximum number of entries to be processed by this worker
Definition TMPWorker.h:46
ULong64_t fProcessedEntries
the number of entries processed by this worker so far
Definition TMPWorker.h:47
TSocket * GetSocket()
Definition TMPWorker.h:39
unsigned fNWorker
the ordinal number of this worker (0 to nWorkers-1)
Definition TMPWorker.h:56
virtual void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
Definition TMPWorker.cxx:86
void Run()
Definition TMPWorker.cxx:61
pid_t fPid
the PID of the process in which this worker is running
Definition TMPWorker.h:55
virtual ~TMPWorker()
Definition TMPWorker.h:32
std::unique_ptr< TSocket > fS
This worker's socket. The unique_ptr makes sure resources are released.
Definition TMPWorker.h:54
TMPWorker(unsigned nWorkers, ULong64_t maxEntries)
Definition TMPWorker.h:29
virtual void Init(int fd, unsigned workerN)
This method is called by children processes right after forking.
Definition TMPWorker.cxx:52
TMPWorker(const TMPWorker &)=delete
unsigned fNWorkers
the number of workers spawned
Definition TMPWorker.h:45
TMPWorker & operator=(const TMPWorker &)=delete
@ kError
Error message.
Definition MPCode.h:47