Logo ROOT   6.14/05
Reference Guide
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 <type_traits> //std::result_of
24 #include <unistd.h> //pid_t
25 
26 class TMPWorker {
27  /// \cond
28  ClassDef(TMPWorker, 0);
29  /// \endcond
30 public:
32  fProcessedEntries(0), fS(), fPid(0), fNWorker(0) { }
33  TMPWorker(unsigned nWorkers, ULong64_t maxEntries)
34  : fNWorkers(nWorkers), fMaxNEntries(maxEntries),
35  fProcessedEntries(0), fS(), fPid(0), fNWorker(0) { }
36  virtual ~TMPWorker() { }
37  //it doesn't make sense to copy a TMPWorker (each one has a uniq_ptr to its socket)
38  TMPWorker(const TMPWorker &) = delete;
39  TMPWorker &operator=(const TMPWorker &) = delete;
40 
41  virtual void Init(int fd, unsigned workerN);
42  void Run();
43  TSocket *GetSocket() { return fS.get(); }
44  pid_t GetPid() { return fPid; }
45  unsigned GetNWorker() const { return fNWorker; }
46 
47 protected:
48  std::string fId; ///< identifier string in the form W<nwrk>|P<proc id>
49  unsigned fNWorkers; ///< the number of workers spawned
50  ULong64_t fMaxNEntries; ///< the maximum number of entries to be processed by this worker
51  ULong64_t fProcessedEntries; ///< the number of entries processed by this worker so far
52 
53  void SendError(const std::string& errmsg, unsigned int code = MPCode::kError);
54 
55 private:
56  virtual void HandleInput(MPCodeBufPair &msg);
57 
58  std::unique_ptr<TSocket> fS; ///< This worker's socket. The unique_ptr makes sure resources are released.
59  pid_t fPid; ///< the PID of the process in which this worker is running
60  unsigned fNWorker; ///< the ordinal number of this worker (0 to nWorkers-1)
61 };
62 
63 #endif
pid_t GetPid()
Definition: TMPWorker.h:44
virtual void HandleInput(MPCodeBufPair &msg)
Handle a message with an EMPCode.
Definition: TMPWorker.cxx:89
pid_t fPid
the PID of the process in which this worker is running
Definition: TMPWorker.h:59
unsigned fNWorker
the ordinal number of this worker (0 to nWorkers-1)
Definition: TMPWorker.h:60
This class works in conjuction with TMPClient, reacting to messages received from it as specified by ...
Definition: TMPWorker.h:26
Error message.
Definition: MPCode.h:47
ULong64_t fProcessedEntries
the number of entries processed by this worker so far
Definition: TMPWorker.h:51
void SendError(const std::string &errmsg, unsigned int code=MPCode::kError)
Error sender.
Definition: TMPWorker.cxx:115
unsigned GetNWorker() const
Definition: TMPWorker.h:45
#define ClassDef(name, id)
Definition: Rtypes.h:320
ULong64_t fMaxNEntries
the maximum number of entries to be processed by this worker
Definition: TMPWorker.h:50
std::unique_ptr< TSocket > fS
This worker&#39;s socket. The unique_ptr makes sure resources are released.
Definition: TMPWorker.h:58
TMPWorker(unsigned nWorkers, ULong64_t maxEntries)
Definition: TMPWorker.h:33
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:31
TMPWorker()
Definition: TMPWorker.h:31
unsigned fNWorkers
the number of workers spawned
Definition: TMPWorker.h:49
TSocket * GetSocket()
Definition: TMPWorker.h:43
TMPWorker & operator=(const TMPWorker &)=delete
void Run()
Definition: TMPWorker.cxx:64
unsigned long long ULong64_t
Definition: RtypesCore.h:70
std::string fId
identifier string in the form W<nwrk>|P<proc id>="">
Definition: TMPWorker.h:48
virtual void Init(int fd, unsigned workerN)
This method is called by children processes right after forking.
Definition: TMPWorker.cxx:55
virtual ~TMPWorker()
Definition: TMPWorker.h:36