12 #ifndef ROOT_TPoolProcessor 13 #define ROOT_TPoolProcessor 30 #include <type_traits> 39 template<class T, typename std::enable_if<std::is_pointer<T>::value && std::is_constructible<TObject*, T>::value>
::type* =
nullptr>
42 auto th1p =
dynamic_cast<TH1*
>(res);
48 auto ttreep =
dynamic_cast<TTree*
>(res);
49 if(ttreep !=
nullptr) {
54 auto tentrylist =
dynamic_cast<TEntryList*
>(res);
55 if(tentrylist !=
nullptr) {
60 auto teventlist =
dynamic_cast<TEventList*
>(res);
61 if(teventlist !=
nullptr) {
73 TPoolProcessor(
F procFunc,
const std::vector<std::string>& fileNames,
const std::string& treeName,
unsigned nWorkers,
ULong64_t maxEntries);
78 void Init(
int fd,
unsigned workerN);
92 const std::string& treeName,
unsigned nWorkers,
ULong64_t maxEntries)
93 :
TMPWorker(fileNames, treeName, nWorkers, maxEntries),
108 unsigned code = msg.first;
120 std::string reply =
"S" + std::to_string(
GetNWorker());
121 reply +=
": unknown code received: " + std::to_string(code);
141 unsigned nProcessed = 0;
145 Error(
"TPoolProcessor::Process",
"[S]: Process:kProcTree fTree undefined!\n");
149 nProcessed = ReadBuffer<unsigned>(msg.second.get());
154 fileN = ReadBuffer<unsigned>(msg.second.get());
157 std::unique_ptr<TFile> fp;
176 if(tree ==
nullptr) {
196 unsigned rangeN = nProcessed %
fNWorkers;
197 start = rangeN*nBunch;
199 finish = (rangeN+1)*nBunch;
217 std::string reply =
"S" + std::to_string(
GetNWorker());
218 reply +=
": could not set TTreeReader to range " + std::to_string(start) +
" " + std::to_string(finish);
230 fProcessedEntries += finish - start;
233 PoolUtils::ReduceObjects<TObject *> redfunc;
virtual const char * GetName() const
Returns name of object.
std::result_of< F(std::reference_wrapper< TTreeReader >)>::type fReducedResult
the results of the executions of fProcFunc merged together
bool fCanReduce
true if fReducedResult can be reduced with a new result, false until we have produced one result ...
Tell a TPoolProcessor to process the tree that was passed to it at construction time.
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
Tell a TPoolProcessor which tree and entries range to process. The object sent is a TreeRangeInfo...
TFile * OpenFile(const std::string &fileName)
Handle file opening.
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
This class works in conjuction with TMPClient, reacting to messages received from it as specified by ...
int MPSend(TSocket *s, unsigned code)
Send a message with the specified code on the specified socket.
ULong64_t fProcessedEntries
the number of entries processed by this worker so far
Tell a TPoolProcessor which tree to process. The object sent is a TreeInfo.
We are ready for the next task.
virtual void SetDirectory(TDirectory *dir)
Add reference to directory dir. dir can be 0.
unsigned GetNWorker() const
void Process(unsigned code, MPCodeBufPair &msg)
TTree * fTree
pointer to the tree to be processed. It is only used if the tree is directly passed to TProcessExecut...
ULong64_t EvalMaxEntries(ULong64_t maxEntries)
ULong64_t fMaxNEntries
the maximum number of entries to be processed by this worker
void Error(const char *location, const char *msgfmt,...)
void HandleInput(MPCodeBufPair &msg)
Execute instructions received from a TPool client.
F fProcFunc
the function to be executed
void SetupTreeCache(TTree *tree)
Tree cache handling.
EEntryStatus SetEntriesRange(Long64_t beginEntry, Long64_t endEntry)
Set the range of entries to be processed.
virtual void SetDirectory(TDirectory *dir)
Remove reference to this EventList from current directory and add reference to new directory dir...
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
unsigned fNWorkers
the number of workers spawned
TFile * GetCurrentFile() const
Return pointer to the current file.
TPoolProcessor(F procFunc, const std::vector< std::string > &fileNames, const std::string &treeName, unsigned nWorkers, ULong64_t maxEntries)
A TEventList object is a list of selected events (entries) in a TTree.
The message contains the result of the processing of a TTree.
Tell the client there was an error while processing.
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
Ask for a kFuncResult/kProcResult.
unsigned long long ULong64_t
virtual Long64_t GetEntries() const
std::vector< std::string > fFileNames
the files to be processed by all workers
virtual void Init(int fd, unsigned workerN)
This method is called by children processes right after forking.
void Init(int fd, unsigned workerN)
This method is called by children processes right after forking.
A TTree object has a header with a name and a title.
A List of entry numbers in a TTree or TChain.
TTree * RetrieveTree(TFile *fp)
Retrieve a tree from an open file.