199 const std::set<std::string> &suppressErrorsForMissingBranches)
208 ::Error(
"TTreeReader::TTreeReader",
"TTree is NULL!");
236 std::string msg =
"No TTree called ";
238 msg +=
" was found in the selected TDirectory.";
239 Error(
"TTreeReader",
"%s", msg.c_str());
249 for (std::deque<ROOT::Internal::TTreeReaderValueBase *>::const_iterator i =
fValues.begin(),
e =
fValues.end();
251 (*i)->MarkTreeReaderUnavailable();
281 Error(
"Initialize",
"We are not processing a TChain but the TEntryList contains sublists. Please "
282 "provide a simple TEntryList with no sublists instead.");
288 fDirector = std::make_unique<ROOT::Internal::TBranchProxyDirector>(
fTree, -1);
293 if (
fTree->GetTree()) {
334 "The current tree in the TChain %s has changed (e.g. by TTree::Process) "
335 "even though TTreeReader::SetEntry() was called, which switched the tree "
336 "again. Did you mean to call TTreeReader::SetLocalEntry()?",
346 "The TTree / TChain has an associated TEntryList. "
347 "TTreeReader ignores TEntryLists unless you construct the TTreeReader passing a TEntryList.");
353 Error(
"SetEntryBase()",
"There was an error while notifying the proxies.");
360 value->NotifyNewTree(
fTree->GetTree());
377 for (
size_t i = 0; i <
fValues.size(); ++i) {
397 if (suppressErrorsForThisBranch ||
415 const auto curFile =
fTree->GetCurrentFile();
416 if (curFile &&
fTree->GetTree()->GetReadCache(curFile,
true)) {
423 if (value->GetProxy())
424 fTree->AddBranchToCache(value->GetProxy()->GetBranchName(),
true);
426 fTree->StopCacheLearningPhase();
451 const std::string mainTreeName =
454 const auto *friendsList =
fTree->GetListOfFriends();
455 if (!friendsList || friendsList->GetEntries() == 0)
467 const auto *frTree = fp->GetDirector()->GetTree();
477 auto *frTreeFromMain = frEl->
GetTree();
492 if (
fEntry >= frTreeFromMain->GetEntriesFast())
496 const std::string frTreeName =
dynamic_cast<const TChain *
>(frTree)
499 std::string msg =
"Last entry available from main tree '" + mainTreeName +
"' was " + std::to_string(
fEntry - 1) +
500 " but friend tree '" + frTreeName +
"' has more entries beyond the end of the main tree.";
501 Warning(
"SetEntryBase()",
"%s", msg.c_str());
534 Error(
"SetEntriesRange()",
"Start entry (%lld) must be lower than the available entries (%lld).", beginEntry,
540 if (endEntry > beginEntry)
547 if (beginEntry - 1 < 0)
571 const auto curFile =
fTree->GetCurrentFile();
574 auto curTree =
fTree->GetTree();
577 auto tc = curTree->GetReadCache(curFile,
true);
580 tc->DropBranch(
"*",
true);
595 return fTree->GetEntriesFast();
614 auto res =
fTree->GetEntries();
620 return fTree->GetEntriesFast();
653 entryAfterList =
fEntryList->GetEntryAndTree(entry, treenum);
654 entryAfterList +=
static_cast<TChain *
>(
fTree)->GetTreeOffset()[treenum];
671 if (loadResult < 0) {
682 value->NotifyNewTree(
fTree->GetTree());
685 Warning(
"SetEntryBase()",
"There was an issue opening the last file associated to the TChain "
691 if (loadResult == -2) {
695 value->NotifyNewTree(
fTree->GetTree());
701 Error(
"SetEntryBase()",
702 "The beginning entry specified via SetEntriesRange (%lld) is equal to or beyond the "
703 "total number of entries in the dataset (%lld). Make sure to specify a "
704 "beginning entry lower than the number of available entries.",
713 if (loadResult == -1) {
719 if (loadResult == -4) {
725 value->NotifyNewTree(
fTree->GetTree());
732 if (loadResult == -6) {
737 value->NotifyNewTree(
fTree->GetTree());
750 Warning(
"SetEntryBase()",
"Unexpected error '%lld' in %s::LoadTree", loadResult,
784 if (fp->GetReadEntry() >= 0)
788 const auto *frTree = fp->GetDirector()->GetTree();
791 const std::string frTreeName =
dynamic_cast<const TChain *
>(frTree)
796 if (!fp->HasIndex()) {
797 std::string msg =
"Cannot read entry " + std::to_string(entry) +
" from friend tree '" + frTreeName +
798 "'. The friend tree has less entries than the main tree. Make sure all trees "
799 "of the dataset have the same number of entries.";
800 throw std::runtime_error{msg};
854 TTree *tree =
nullptr;
867 Error(
"RegisterValueReader",
868 "Error registering reader for %s: TTreeReaderValue/Array objects must be created before the call to Next() "
869 "/ SetEntry() / SetLocalEntry(), or after TTreeReader::Restart()!",
882 std::deque<ROOT::Internal::TTreeReaderValueBase *>::iterator iReader =
884 if (iReader ==
fValues.end()) {
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Base class of TTreeReaderValue.
@ kSetupMissingBranch
The specified branch cannot be found.
ESetupStatus GetSetupStatus() const
Return this TTreeReaderValue's setup status.
Detail::TBranchProxy * GetProxy() const
virtual const char * GetDerivedTypeName() const =0
TString fBranchName
Name of the branch to read data from.
const char * GetBranchName() const
virtual void CreateProxy()
Create the proxy object for our branch.
A chain is a collection of files containing TTree objects.
Describe directory structure in memory.
void GetObject(const char *namecycle, T *&ptr)
Get an object with proper type checking.
A TFriendElement TF describes a TTree object TF in a file.
virtual TTree * GetTree()
Return pointer to friend TTree.
const char * GetName() const override
Returns name of object.
Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
const char * Data() const
TTreeReader()
Default constructor. Call SetTree to connect to a TTree.
ELoadTreeStatus fLoadTreeStatus
Indicator on how LoadTree was called 'last' time.
Long64_t GetEntries() const
Returns the number of entries of the TEntryList if one is provided, else of the TTree / TChain,...
std::deque< ROOT::Internal::TTreeReaderValueBase * > fValues
readers that use our director
EEntryStatus fEntryStatus
status of most recent read request
void SetTree(TTree *tree, TEntryList *entryList=nullptr)
Set (or update) the which tree to read from.
~TTreeReader() override
Tell all value readers that the tree reader does not exist anymore.
TNotifyLink< TTreeReader > fNotify
TTree and TChain will notify this object upon LoadTree, leading to a call to TTreeReader::Notify().
bool fProxiesSet
True if the proxies have been set, false otherwise.
@ kEntryNotFound
the tree entry number does not exist
@ kIndexedFriendNoMatch
A friend with TTreeIndex doesn't have an entry for this index.
@ kEntryUnknownError
LoadTree return less than -6, likely a 'newer' error code.
@ kEntryDictionaryError
problem reading dictionary info from tree
@ kMissingBranchWhenSwitchingTree
A branch was not found when switching to the next TTree in the chain.
@ kEntryBeyondEnd
last entry loop has reached its end
@ kEntryChainFileError
problem in opening a chain's file
@ kEntryNoTree
the tree does not exist
@ kEntryValid
data read okay
bool fSetEntryBaseCallingLoadTree
True if during the LoadTree execution triggered by SetEntryBase.
bool RegisterValueReader(ROOT::Internal::TTreeReaderValueBase *reader)
Add a value reader for this tree.
TTree * fTree
tree that's read
bool fWarnAboutLongerFriends
std::set< std::string > fMissingProxies
EEntryStatus SetEntriesRange(Long64_t beginEntry, Long64_t endEntry)
Set the range of entries to be loaded by Next(); end will not be loaded.
EEntryStatus SetEntryBase(Long64_t entry, bool local)
Load an entry into the tree, return the status of the read.
void WarnIfFriendsHaveMoreEntries()
@ kInternalLoadTree
Notify/LoadTree was last called from SetEntryBase.
@ kMissingBranchFromTree
Missing expected branch when loading new tree.
@ kNoTree
default state, no TTree is connected (formerly 'Zombie' state)
@ kExternalLoadTree
User code called LoadTree directly.
@ kLoadTreeNone
Notify has not been called yet.
void Initialize()
Initialization of the director.
void Restart()
Restart a Next() loop from entry 0 (of TEntryList index 0 of fEntryList is set).
TEntryList * fEntryList
entry list to be used
Long64_t fEntry
Current (non-local) entry of fTree or of fEntryList if set.
bool Notify() override
Notify director and values of a change in tree.
Long64_t fBeginEntry
This allows us to propagate the range to the TTreeCache.
void DeregisterValueReader(ROOT::Internal::TTreeReaderValueBase *reader)
Remove a value reader for this tree.
@ kBitIsExternalTree
we do not own the tree
@ kBitHaveWarnedAboutEntryListAttachedToTTree
the tree had a TEntryList and we have warned about that
@ kBitIsChain
our tree is a chain
bool SetProxies()
Tell readers we now have a tree.
std::set< std::string > fSuppressErrorsForMissingBranches
ROOT::Internal::TFriendProxy & AddFriendProxy(std::size_t friendIdx)
std::vector< std::unique_ptr< ROOT::Internal::TFriendProxy > > fFriendProxies
Proxies to friend trees, created in TTreeReader[Value,Array]CreateProxy.
std::unique_ptr< ROOT::Internal::TBranchProxyDirector > fDirector
proxying director
Long64_t fEndEntry
The end of the entry loop.
EEntryStatus SetEntry(Long64_t entry)
Set the next entry (or index of the TEntryList if that is set).
static constexpr const char *const fgEntryStatusText[kEntryUnknownError+1]
Long64_t GetCurrentEntry() const
Returns the index of the current entry being read.
A TTree represents a columnar dataset.
virtual Long64_t LoadTree(Long64_t entry)
Set current entry.
virtual Long64_t GetEntriesFast() const
Return a number greater or equal to the total number of entries in the dataset.
TClass * IsA() const override
static constexpr Long64_t kMaxEntries
Used as the max value for any TTree range operation.
std::vector< std::string > GetTreeFullPaths(const TTree &tree)
Retrieve the full path(s) to a TTree or the trees in a TChain.