12 #ifndef ROOT_TMPWorkerTree 13 #define ROOT_TMPWorkerTree 29 #include <type_traits> 83 :
TMPWorkerTree(fileNames, entries, treeName, nWorkers, maxEntries, firstEntry), fProcFunc(procFunc),
84 fReducedResult(), fCanReduce(false)
89 :
TMPWorkerTree(tree, entries, nWorkers, maxEntries, firstEntry), fProcFunc(procFunc), fReducedResult(),
100 typename std::result_of<F(std::reference_wrapper<TTreeReader>)>::
type fReducedResult;
108 :
TMPWorkerTree(fileNames, entries, treeName, nWorkers, maxEntries, firstEntry), fSelector(selector),
114 :
TMPWorkerTree(tree, entries, nWorkers, maxEntries, firstEntry), fSelector(selector), fCallBegin(true)
124 bool fCallBegin =
true;
135 template <class T, typename std::enable_if<std::is_pointer<T>::value && std::is_constructible<TObject *, T>::value &&
136 !std::is_constructible<TCollection *, T>::value>
::type * =
nullptr>
139 auto th1p =
dynamic_cast<TH1*
>(res);
140 if(th1p !=
nullptr) {
144 auto ttreep =
dynamic_cast<TTree*
>(res);
145 if(ttreep !=
nullptr) {
149 auto tentrylist =
dynamic_cast<TEntryList*
>(res);
150 if(tentrylist !=
nullptr) {
154 auto teventlist =
dynamic_cast<TEventList*
>(res);
155 if(teventlist !=
nullptr) {
163 template <class T, typename std::enable_if<std::is_pointer<T>::value &&
164 std::is_constructible<TCollection *, T>::value>
::type * =
nullptr>
170 while ((obj = nxo())) {
193 std::string reply, errmsg, sn =
"[S" + std::to_string(
GetNWorker()) +
"]: ";
194 if (
LoadTree(code, msg, start, finish, &enl, errmsg) != 0) {
205 reply = sn +
"could not set TTreeReader to range " + std::to_string(start) +
" " + std::to_string(finish - 1);
211 auto res = fProcFunc(reader);
220 PoolUtils::ReduceObjects<TObject *> redfunc;
221 fReducedResult =
static_cast<decltype(fReducedResult)
>(redfunc({res, fReducedResult}));
224 fReducedResult = res;
void CloseFile()
Handle file closing.
TMPWorkerTreeSel(TSelector &selector, TTree *tree, TEntryList *entries, UInt_t nWorkers, ULong64_t maxEntries, ULong64_t firstEntry)
TMPWorkerTreeFunc(F procFunc, TTree *tree, TEntryList *entries, UInt_t nWorkers, ULong64_t maxEntries, ULong64_t firstEntry)
void Setup()
Auxilliary method for common initializations.
TFile * OpenFile(const std::string &fileName)
Handle file opening.
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
std::string fTreeName
the name of the tree to be processed
void DetachRes(T res)
Auxilliary templated functions If the user lambda returns a TH1F*, TTree*, TEventList*, we incur in the problem of that object being automatically owned by the current open file.
A specialized TFileCacheRead object for a TTree.
TSelector & fSelector
pointer to the selector to be used to process the tree. It is null if we are not using a TSelector...
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
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.
TMPWorkerTree()
Class constructors.
TMPWorkerTreeSel(TSelector &selector, const std::vector< std::string > &fileNames, TEntryList *entries, const std::string &treeName, UInt_t nWorkers, ULong64_t maxEntries, ULong64_t firstEntry)
ULong64_t fProcessedEntries
the number of entries processed by this worker so far
TTree * fTree
pointer to the tree to be processed. It is only used if the tree is directly passed to TProcessExecut...
TTreeCache * fTreeCache
instance of the tree cache for the tree
Int_t LoadTree(UInt_t code, MPCodeBufPair &msg, Long64_t &start, Long64_t &finish, TEntryList **enl, std::string &errmsg)
Load the requierd tree and evaluate the processing range.
virtual void SetDirectory(TDirectory *dir)
Add reference to directory dir. dir can be 0.
This class works in conjuction with TTreeProcessorMP, reacting to messages received from it as specif...
unsigned GetNWorker() const
bool fCanReduce
true if fReducedResult can be reduced with a new result, false until we have produced one result ...
TMPWorkerTree & operator=(const TMPWorkerTree &)=delete
virtual void SendResult()
virtual ~TMPWorkerTreeFunc()
TTree * RetrieveTree(TFile *fp)
Retrieve a tree from an open file.
void Process(UInt_t code, MPCodeBufPair &msg)
Bool_t fTreeCacheIsLearning
Whether cache is in learning phase.
The message contains the result of the processing of a TTree.
ULong64_t fMaxNEntries
the maximum number of entries to be processed by this worker
virtual void SetDirectory(TDirectory *dir)
Remove reference to this EventList from current directory and add reference to new directory dir...
EEntryStatus SetEntriesRange(Long64_t beginEntry, Long64_t endEntry)
Sets the entry that Next() will stop iteration on.
ULong64_t EvalMaxEntries(ULong64_t maxEntries)
Max entries evaluation.
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
virtual void Process(UInt_t, MPCodeBufPair &)
void SetupTreeCache(TTree *tree)
Tree cache handling.
virtual ~TMPWorkerTreeSel()
void Init(int fd, UInt_t workerN)
Init overload definign max entries.
A TEventList object is a list of selected events (entries) in a TTree.
TMPWorkerTreeFunc(F procFunc, const std::vector< std::string > &fileNames, TEntryList *entries, const std::string &treeName, UInt_t nWorkers, ULong64_t maxEntries, ULong64_t firstEntry)
virtual void SetDirectory(TDirectory *dir)
Change the tree's directory.
unsigned long long ULong64_t
Bool_t fUseTreeCache
Control usage of the tree cache.
TEntryList * fEntryList
entrylist
Templated derivation of TMPWorkerTree handlign generic function tree processing.
Long64_t fCacheSize
Cache size.
std::vector< std::string > fFileNames
the files to be processed by all workers
Templated derivation of TMPWorkerTree handlign selector tree processing.
Mother of all ROOT objects.
void HandleInput(MPCodeBufPair &msg)
Execute instructions received from a MP client.
F fProcFunc
copy the function to be executed
A TTree object has a header with a name and a title.
void SendResult()
Generic function processing SendResult and Process overload.
Tell the client there was an error while processing.
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
ULong64_t fFirstEntry
first entry to br processed
A List of entry numbers in a TTree or TChain.
We are ready for the next task.
TFile * fFile
last open file