13#ifndef ROOT_TTreeReader
14#define ROOT_TTreeReader
32#include <unordered_map>
110 return !(*
this == lhs);
177 "the tree does not exist",
178 "the tree entry number does not exist",
179 "cannot access chain element",
180 "problem in opening a chain's file",
181 "problem reading dictionary info from tree",
182 "last entry loop has reached its end",
183 "one of the readers was not successfully initialized",
184 "A friend with TTreeIndex doesn't have an entry for this index",
185 "A branch was not found when switching to the next TTree in the chain",
186 "LoadTree return less than -6, likely a 'newer' error code"};
191 const std::vector<std::string> &suppressErrorsForMissingBranches = {});
199 SetTree(keyname,
nullptr, entryList);
273 using NamedProxies_t = std::unordered_map<std::string, std::unique_ptr<ROOT::Internal::TNamedBranchProxy>>;
277 const auto proxyIt =
fProxies.find(branchname);
278 return fProxies.end() != proxyIt ? proxyIt->second.get() :
nullptr;
281 void AddProxy(std::unique_ptr<ROOT::Internal::TNamedBranchProxy>
p)
286 std::string err =
"A proxy with key " + std::string(bpName) +
" was already stored!";
287 throw std::runtime_error(err);
306 std::string key(branchname);
324 std::unique_ptr<ROOT::Internal::TBranchProxyDirector>
fDirector{
nullptr};
327 std::deque<ROOT::Internal::TTreeReaderValueBase*>
fValues;
#define ClassDefOverride(name, id)
winID h TVirtualViewer3D TVirtualGLPainter p
Base class of TTreeReaderArray.
Base class of TTreeReaderValue.
This class is used to 'drive' and hold a serie of TBranchProxy objects which represent and give acces...
This class defines an abstract interface that must be implemented by all classes that contain diction...
Describe directory structure in memory.
A List of entry numbers in a TTree or TChain.
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Concrete implementation of the proxy around a Friend Tree.
A node in a doubly linked list of subscribers to TChain notifications.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Iterate through the entries of a TTree.
const Long64_t * const_pointer
const Long64_t value_type
Iterator_t & operator++()
Increment the iterator (prefix ++i).
Iterator_t()
Default-initialize the iterator as "past the end".
const Long64_t & operator*() const
Long64_t fEntry
Entry number of the tree referenced by this iterator; -1 is invalid.
Iterator_t(TTreeReader &reader, Long64_t entry)
Initialize the iterator with the reader it steers and a tree entry number; -1 is invalid.
const Long64_t & reference
bool operator==(const Iterator_t &lhs) const
Compare two iterators for equality.
TTreeReader * fReader
The reader we select the entries on.
const Long64_t & operator*()
Set the entry number in the reader and return it.
bool IsValid() const
Whether the iterator points to a valid entry.
std::input_iterator_tag iterator_category
bool operator!=(const Iterator_t &lhs) const
Compare two iterators for inequality.
Iterator_t operator++(int)
Increment the iterator (postfix i++).
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
TTreeReader()
Default constructor. Call SetTree to connect to a TTree.
std::vector< std::string > fMissingProxies
ELoadTreeStatus fLoadTreeStatus
Indicator on how LoadTree was called 'last' time.
void SetTree(const char *keyname, TEntryList *entryList=nullptr)
Long64_t GetEntries() const
Returns the number of entries of the TEntryList if one is provided, else of the TTree / TChain,...
EEntryStatus fEntryStatus
status of most recent read request
std::vector< std::string > fSuppressErrorsForMissingBranches
std::unordered_map< std::string, std::unique_ptr< ROOT::Internal::TNamedBranchProxy > > NamedProxies_t
void SetTree(TTree *tree, TEntryList *entryList=nullptr)
Set (or update) the which tree to read from.
std::pair< Long64_t, Long64_t > GetEntriesRange() const
Get the begin and end entry numbers.
~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.
void AddProxy(std::unique_ptr< ROOT::Internal::TNamedBranchProxy > p)
@ 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
@ kEntryChainSetupError
problem in accessing a chain element, e.g. file without the tree
@ kMissingBranchWhenSwitchingTree
A branch was not found when switching to the next TTree in the chain.
@ kEntryNotLoaded
no entry has been loaded yet
@ kEntryBeyondEnd
last entry loop has reached its end
@ kEntryChainFileError
problem in opening a chain's file
@ kEntryNoTree
the tree does not exist
@ kEntryBadReader
One of the readers was not successfully initialized.
@ kEntryValid
data read okay
bool fSetEntryBaseCallingLoadTree
True if during the LoadTree execution triggered by SetEntryBase.
std::deque< ROOT::Internal::TTreeReaderValueBase * > fValues
readers that use our director
bool RegisterValueReader(ROOT::Internal::TTreeReaderValueBase *reader)
Add a value reader for this tree.
TTree * fTree
tree that's read
bool fWarnAboutLongerFriends
Iterator_t end()
Return an iterator beyond the last TTree entry.
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.
std::string GetProxyKey(const char *branchname)
void WarnIfFriendsHaveMoreEntries()
EEntryStatus GetEntryStatus() const
@ 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
@ kBitSetEntryBaseCallingLoadTree
SetEntryBase is in the process of calling TChain/TTree::LoadTree.
@ kBitHaveWarnedAboutEntryListAttachedToTTree
the tree had a TEntryList and we have warned about that
@ kBitIsChain
our tree is a chain
EEntryStatus SetLocalEntry(Long64_t entry)
Set the next local tree entry.
bool SetProxies()
Tell readers we now have a tree.
NamedProxies_t fProxies
attached ROOT::TNamedBranchProxies; owned
ROOT::Internal::TFriendProxy & AddFriendProxy(std::size_t friendIdx)
TEntryList * GetEntryList() const
std::vector< std::unique_ptr< ROOT::Internal::TFriendProxy > > fFriendProxies
Proxies to friend trees, created in TTreeReader[Value,Array]::CreateProxy.
Iterator_t begin()
Return an iterator to the 0th TTree entry.
std::unique_ptr< ROOT::Internal::TBranchProxyDirector > fDirector
proxying director
TTreeReader(const char *keyname, TEntryList *entryList=nullptr)
bool Next()
Move to the next entry (or index of the TEntryList if that is set).
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]
ROOT::Internal::TNamedBranchProxy * FindProxy(const char *branchname) const
Long64_t GetCurrentEntry() const
Returns the index of the current entry being read.
A TTree represents a columnar dataset.
virtual Long64_t GetEntriesFast() const
Return a number greater or equal to the total number of entries in the dataset.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...