47 :
TMPWorker(), fFileNames(), fTreeName(), fTree(nullptr), fFile(nullptr), fEntryList(nullptr), fFirstEntry(0),
48 fTreeCache(0), fTreeCacheIsLearning(
kFALSE), fUseTreeCache(
kTRUE), fCacheSize(-1)
55 :
TMPWorker(nWorkers, maxEntries), fFileNames(fileNames), fTreeName(treeName), fTree(nullptr), fFile(nullptr),
56 fEntryList(entries), fFirstEntry(firstEntry), fTreeCache(0), fTreeCacheIsLearning(
kFALSE), fUseTreeCache(
kTRUE),
64 :
TMPWorker(nWorkers, maxEntries), fTree(
tree), fFile(nullptr), fEntryList(entries), fFirstEntry(firstEntry),
65 fTreeCache(0), fTreeCacheIsLearning(
kFALSE), fUseTreeCache(
kTRUE), fCacheSize(-1)
105 if (fp ==
nullptr || fp->
IsZombie()) {
106 std::stringstream ss;
107 ss <<
"could not open file " << fileName;
108 std::string errmsg = ss.str();
137 if (
tree ==
nullptr) {
138 std::stringstream ss;
139 ss <<
"cannot find tree with name " <<
fTreeName <<
" in file " << fp->
GetName();
140 std::string errmsg = ss.str();
169 Warning(
"SetupTreeCache",
"default tree does not have a file attached: corruption? Tree cache untouched");
173 tree->SetCacheSize(0);
218 std::string reply =
"S" + std::to_string(
GetNWorker());
219 reply +=
": unknown code received: " + std::to_string(code);
246 if (
LoadTree(code, msg, start, finish, &enl, errmsg) != 0) {
258 for (
Long64_t entry = start; entry < finish; ++entry) {
287 std::string mgroot =
"[S" + std::to_string(
GetNWorker()) +
"]: ";
292 mgroot +=
"MPCode::kProcTree: ";
295 if(
fTree ==
nullptr) {
296 errmsg = mgroot + std::string(
"tree undefined!");
301 nProcessed = ReadBuffer<UInt_t>(msg.second.get());
309 start = rangeN * nBunch;
311 finish = (rangeN+1)*nBunch;
323 errmsg = mgroot + std::string(
"unable to retrieve tree from open file ") +
340 mgroot +=
"MPCode::kProcRange: ";
342 nProcessed = ReadBuffer<UInt_t>(msg.second.get());
346 mgroot +=
"MPCode::kProcFile: ";
348 fileN = ReadBuffer<UInt_t>(msg.second.get());
350 errmsg +=
"MPCode undefined!";
358 if (
fFile ==
nullptr) {
360 errmsg = mgroot + std::string(
"unable to open file ") +
fFileNames[fileN];
368 if (
tree ==
nullptr) {
370 errmsg = mgroot + std::string(
"unable to retrieve tree from open file ") +
fFileNames[fileN];
375 setupcache = (
tree !=
fTree) ?
true :
false;
388 start = rangeN * nBunch;
390 finish = (rangeN+1)*nBunch;
395 finish =
tree->GetEntries();
413 start = rangeN * nBunch;
415 finish = (rangeN + 1) * nBunch;
420 finish = (*enl)->GetN();
434 Info(
"LoadTree",
"%s %d %d file: %s %lld %lld", mgroot.c_str(), nProcessed, fileN,
fFile->
GetName(), start,
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
int MPSend(TSocket *s, unsigned code)
Send a message with the specified code on the specified socket.
unsigned long long ULong64_t
void Info(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
TList * GetListOfKeys() const override
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A List of entry numbers in a TTree or TChain.
virtual TEntryList * GetEntryList(const char *treename, const char *filename, Option_t *opt="")
Return the entry list, corresponding to treename and filename By default, the filename is first tried...
virtual Long64_t GetEntry(Int_t index)
Return the number of the entry #index of this TEntryList in the TTree or TChain See also Next().
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
virtual void SetCacheRead(TFileCacheRead *cache, TObject *tree=0, ECacheAction action=kDisconnect)
Set a pointer to the read cache.
TFileCacheRead * GetCacheRead(const TObject *tree=nullptr) const
Return a pointer to the current read cache.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual const char * GetClassName() const
void SendResult()
Selector processing SendResult and Process overload.
TSelector & fSelector
pointer to the selector to be used to process the tree. It is null if we are not using a TSelector.
void Process(UInt_t code, MPCodeBufPair &msg)
Selector specialization.
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.
TTree * fTree
pointer to the tree to be processed. It is only used if the tree is directly passed to TProcessExecut...
TFile * fFile
last open file
void Setup()
Auxilliary method for common initializations.
ULong64_t EvalMaxEntries(ULong64_t maxEntries)
Max entries evaluation.
TTree * RetrieveTree(TFile *fp)
Retrieve a tree from an open file.
TEntryList * fEntryList
entrylist
TMPWorkerTree()
Class constructors.
Bool_t fUseTreeCache
Control usage of the tree cache.
std::vector< std::string > fFileNames
the files to be processed by all workers
Bool_t fTreeCacheIsLearning
Whether cache is in learning phase.
TFile * OpenFile(const std::string &fileName)
Handle file opening.
virtual void SendResult()
void Init(int fd, UInt_t workerN)
Init overload definign max entries.
virtual void Process(UInt_t, MPCodeBufPair &)
Long64_t fCacheSize
Cache size.
std::string fTreeName
the name of the tree to be processed
void CloseFile()
Handle file closing.
void SetupTreeCache(TTree *tree)
Tree cache handling.
TTreeCache * fTreeCache
instance of the tree cache for the tree
void HandleInput(MPCodeBufPair &msg)
Execute instructions received from a MP client.
This class works in conjuction with TMPClient, reacting to messages received from it as specified by ...
void SendError(const std::string &errmsg, unsigned int code=MPCode::kError)
Error sender.
unsigned GetNWorker() const
ULong64_t fMaxNEntries
the maximum number of entries to be processed by this worker
ULong64_t fProcessedEntries
the number of entries processed by this worker so far
virtual void Init(int fd, unsigned workerN)
This method is called by children processes right after forking.
unsigned fNWorkers
the number of workers spawned
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Init(TTree *)
virtual Bool_t Process(Long64_t)
virtual void SlaveBegin(TTree *)
virtual TList * GetOutputList() const
virtual Bool_t Notify()
This method must be overridden to handle object notification.
virtual void SlaveTerminate()
A cache to speed-up the reading of ROOT datasets.
virtual void UpdateBranches(TTree *tree)
Update pointer to current Tree and recompute pointers to the branches in the cache.
virtual Bool_t IsLearning() const
virtual void ResetCache()
This will simply clear the cache.
A TTree represents a columnar dataset.
TFile * GetCurrentFile() const
Return pointer to the current file.
virtual Long64_t GetEntries() const
This class represents a WWW compatible URL.
const char * GetFile() const
@ kSendResult
Ask for a kFuncResult/kProcResult.
@ kProcFile
Tell a TMPWorkerTree which tree to process. The object sent is a TreeInfo.
@ kIdling
We are ready for the next task.
@ kProcRange
Tell a TMPWorkerTree which tree and entries range to process. The object sent is a TreeRangeInfo.
@ kProcTree
Tell a TMPWorkerTree to process the tree that was passed to it at construction time.
@ kProcError
Tell the client there was an error while processing.
@ kProcResult
The message contains the result of the processing of a TTree.