12 #ifndef ROOT_TTreeProcessorMT 13 #define ROOT_TTreeProcessorMT 68 if (fTreeName.empty()) {
71 const char *className = key->GetClassName();
72 if (strcmp(className,
"TTree") == 0) {
73 fTreeName = key->GetName();
77 if (fTreeName.empty()) {
78 auto msg =
"Cannot find any tree in file " + fFileNames[
fCurrentIdx];
79 throw std::runtime_error(msg);
86 fCurrentTree = (
TTree*)fCurrentFile->
Get(fTreeName.data());
99 TTreeView(std::string_view fn, std::string_view tn) : fTreeName(tn), fCurrentIdx(0)
101 fFileNames.emplace_back(fn);
111 TTreeView(
const std::vector<std::string_view>& fns, std::string_view tn) : fTreeName(tn), fCurrentIdx(0)
113 if (fns.size() > 0) {
115 fFileNames.emplace_back(fn);
119 auto msg =
"The provided list of file names is empty, cannot process tree " +
fTreeName;
120 throw std::runtime_error(msg);
129 static const TClassRef clRefTChain(
"TChain");
130 if (clRefTChain == tree.IsA()) {
133 for (
auto f : *filelist)
134 fFileNames.emplace_back(
f->GetTitle());
138 auto msg =
"The provided chain of files is empty, cannot process tree " +
fTreeName;
139 throw std::runtime_error(msg);
145 fFileNames.emplace_back(f->
GetName());
149 auto msg =
"The specified TTree is not linked to any file, in-memory-only trees are not supported. Cannot process tree " +
fTreeName;
150 throw std::runtime_error(msg);
161 static const TClassRef clRefTChain(
"TChain");
162 if (clRefTChain == tree.IsA()) {
165 size_t nTrees = fFileNames.size();
166 fEntryLists.resize(nTrees);
172 for (
unsigned int treeNum = 0; treeNum < nTrees && currListEntry >= 0; ++treeNum) {
176 Long64_t nextTreeOffset = currTreeOffset + currTreeEntries;
178 while (currListEntry >= 0 && currListEntry < nextTreeOffset) {
179 fEntryLists[treeNum].Enter(currListEntry - currTreeOffset);
180 currListEntry = entries.
Next();
183 currTreeOffset = nextTreeOffset;
187 fEntryLists.emplace_back(entries);
197 fFileNames.emplace_back(fn);
200 fEntryLists.emplace_back(el);
218 if (fEntryLists.size() > 0) {
222 fCurrentEntryList.
Reset();
223 if (fEntryLists[fCurrentIdx].GetN() > 0) {
226 if (entry >= start && entry < end) fCurrentEntryList.
Enter(entry);
227 }
while ((entry = fEntryLists[fCurrentIdx].Next()) >= 0);
230 reader =
new TTreeReader(fCurrentTree, &fCurrentEntryList);
238 return std::unique_ptr<TTreeReader>(
reader);
252 return fFileNames.size();
259 if (i != fCurrentIdx) {
264 fCurrentTree = (
TTree*)f->
Get(fTreeName.data());
266 fCurrentFile.reset(f);
278 TTreeProcessorMT(std::string_view filename, std::string_view treename =
"");
279 TTreeProcessorMT(
const std::vector<std::string_view>& filenames, std::string_view treename =
"");
289 #endif // defined TTreeProcessorMT virtual const char * GetName() const
Returns name of object.
std::string GetName(const std::string &scope_name)
virtual Long64_t Next()
Return the next non-zero entry index (next after fLastIndexQueried) this function is faster than GetE...
TTreeView(const std::vector< std::string_view > &fns, std::string_view tn)
Constructor based on a collection of file names.
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
Namespace for new ROOT classes and functions.
size_t GetNumFiles() const
Get the number of files of this view.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
std::unique_ptr< TTreeReader > GetTreeReader(Long64_t start, Long64_t end)
Get a TTreeReader for the current tree of this view.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Helper class to iterate over cluster of baskets.
void SetCurrent(unsigned int i)
Set the current file and tree of this view.
virtual TClusterIterator GetClusterIterator(Long64_t firstentry)
Return an iterator over the cluster of baskets starting at firstentry.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
virtual Long64_t LoadTree(Long64_t entry)
Find the tree which contains entry, and set it as the current tree.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
std::string fTreeName
Name of the tree.
void Init()
Initialize the file and the tree for this view, first looking for a tree in the file if necessary...
std::unique_ptr< TFile > fCurrentFile
! Current file object of this view.
TEntryList fCurrentEntryList
Entry numbers for the current range being processed.
std::vector< std::string > fFileNames
Names of the files.
TTreeView(const TTreeView &view)
Copy constructor.
std::vector< TEntryList > fEntryLists
Entry numbers to be processed per tree/file.
TTreeView(TTree &tree, TEntryList &entries)
Constructor based on a TTree and a TEntryList.
TFile * GetCurrentFile() const
Return pointer to the current file.
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()...
TTreeView(TTree &tree)
Constructor based on a TTree.
if object destructor must call RecursiveRemove()
TTree::TClusterIterator GetClusterIterator()
Get the cluster iterator for the current tree of this view, starting from entry zero.
Long64_t GetEntries() const
Get the number of entries of the current tree of this view.
please use SetEntriesRange()!")
double func(double *x, double *p)
ROOT::TThreadedObject< ROOT::Internal::TTreeView > treeView
! Threaded object with <file,tree> per thread
virtual Bool_t Enter(Long64_t entry, TTree *tree=0)
Add entry #entry to the list.
virtual Long64_t GetEntries() const
virtual TTree * GetTree() const
TClassRef is used to implement a permanent reference to a TClass object.
TTree * fCurrentTree
! Current tree object of this view.
virtual void Reset()
Reset this list.
virtual TList * GetListOfKeys() const
A chain is a collection of files containing TTree objects.
Int_t GetEntries() const
Return the number of objects in array (i.e.
A TTree object has a header with a name and a title.
A List of entry numbers in a TTree or TChain.
A class to process the entries of a TTree in parallel.
TTreeView(std::string_view fn, std::string_view tn)
Constructor based on a file name.
unsigned int fCurrentIdx
! Index of the current file.