47 :
TMPWorker(), fFileNames(), fTreeName(), fTree(nullptr), fFile(nullptr), fEntryList(nullptr), fFirstEntry(0),
48 fTreeCache(nullptr), fTreeCacheIsLearning(false), fUseTreeCache(true), fCacheSize(-1)
55 :
TMPWorker(nWorkers, maxEntries), fFileNames(fileNames), fTreeName(treeName), fTree(nullptr), fFile(nullptr),
56 fEntryList(entries), fFirstEntry(firstEntry), fTreeCache(nullptr), fTreeCacheIsLearning(false), fUseTreeCache(true),
64 :
TMPWorker(nWorkers, maxEntries), fTree(tree), fFile(nullptr), fEntryList(entries), fFirstEntry(firstEntry),
65 fTreeCache(nullptr), fTreeCacheIsLearning(false), fUseTreeCache(true), 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();
123 TTree *tree =
nullptr;
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();
154 TFile *curfile = tree->GetCurrentFile();
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);
248 if (
LoadTree(code, msg, start, finish, &enl, errmsg) != 0) {
260 for (
Long64_t entry = start; entry < finish; ++entry) {
288 bool setupcache =
true;
290 std::string mgroot =
"[S" + std::to_string(
GetNWorker()) +
"]: ";
292 TTree *tree =
nullptr;
295 mgroot +=
"MPCode::kProcTree: ";
298 if(
fTree ==
nullptr) {
299 errmsg = mgroot + std::string(
"tree undefined!");
304 nProcessed = ReadBuffer<UInt_t>(msg.second.get());
312 start = rangeN * nBunch;
313 if (start >= nEntries) {
314 start = finish = nEntries;
317 finish = (rangeN+1)*nBunch;
330 errmsg = mgroot + std::string(
"unable to retrieve tree from open file ") +
347 mgroot +=
"MPCode::kProcRange: ";
349 nProcessed = ReadBuffer<UInt_t>(msg.second.get());
353 mgroot +=
"MPCode::kProcFile: ";
355 fileN = ReadBuffer<UInt_t>(msg.second.get());
357 errmsg +=
"MPCode undefined!";
365 if (
fFile ==
nullptr) {
367 errmsg = mgroot + std::string(
"unable to open file ") +
fFileNames[fileN];
375 if (tree ==
nullptr) {
377 errmsg = mgroot + std::string(
"unable to retrieve tree from open file ") +
fFileNames[fileN];
382 setupcache = (tree !=
fTree) ?
true :
false;
391 Long64_t nEntries = tree->GetEntries();
395 start = rangeN * nBunch;
396 if (start >= nEntries)
397 start = finish = nEntries;
399 finish = (rangeN+1)*nBunch;
404 finish = tree->GetEntries();
422 start = rangeN * nBunch;
423 if (start >= nEntries) {
424 start = finish = nEntries;
426 finish = (rangeN + 1) * nBunch;
431 finish = (*enl)->GetN();
445 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,...)
Use this function for informational messages.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
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(Long64_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 an on-disk file, usually with extension .root, that stores objects in a file-system-li...
virtual void SetCacheRead(TFileCacheRead *cache, TObject *tree=nullptr, ECacheAction action=kDisconnect)
Set a pointer to the read cache.
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.
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() override
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) override
Selector specialization.
Int_t LoadTree(UInt_t code, MPCodeBufPair &msg, Long64_t &start, Long64_t &finish, TEntryList **enl, std::string &errmsg)
Load the required 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
~TMPWorkerTree() override
void Init(int fd, UInt_t workerN) override
Init overload defining max entries.
void HandleInput(MPCodeBufPair &msg) override
Execute instructions received from a MP client.
void Setup()
Auxiliary method for common initialization.
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 fUseTreeCache
Control usage of the tree cache.
std::vector< std::string > fFileNames
the files to be processed by all workers
TFile * OpenFile(const std::string &fileName)
Handle file opening.
virtual void SendResult()
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
bool fTreeCacheIsLearning
Whether cache is in learning phase.
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
const char * GetName() const override
Returns name of object.
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Init(TTree *)
virtual bool Process(Long64_t)
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
virtual void SlaveBegin(TTree *)
bool Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
virtual TList * GetOutputList() const
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.
bool IsLearning() const override
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.