12 #ifndef ROOT_TTreeProcessorMT 13 #define ROOT_TTreeProcessorMT 58 typedef std::pair<std::string, std::string>
NameAlias;
79 const char *className = key->GetClassName();
80 if (strcmp(className,
"TTree") == 0) {
86 auto msg =
"Cannot find any tree in file " +
fFileNames[0];
87 throw std::runtime_error(msg);
99 auto &
name = na.first;
100 auto &alias = na.second;
105 for (
auto &fn : fileNames)
106 frChain->
Add(fn.c_str());
110 fChain->AddFriend(frChain, alias.c_str());
120 auto friends =
tree.GetListOfFriends();
124 for (
auto fr : *friends) {
128 auto realName = frTree->
GetName();
129 auto alias =
tree.GetFriendAlias(frTree);
131 fFriendNames.emplace_back(std::make_pair(realName, std::string(alias)));
133 fFriendNames.emplace_back(std::make_pair(realName,
""));
140 auto f = frTree->GetCurrentFile();
141 fileNames.emplace_back(f->GetName());
143 auto frChain =
static_cast<TChain *
>(frTree);
144 for (
auto f : *(frChain->GetListOfFiles())) {
145 fileNames.emplace_back(f->GetTitle());
172 if (fns.size() > 0) {
178 auto msg =
"The provided list of file names is empty, cannot process tree " +
fTreeName;
179 throw std::runtime_error(msg);
188 static const TClassRef clRefTChain(
"TChain");
189 if (clRefTChain ==
tree.IsA()) {
192 for (
auto f : *filelist)
198 auto msg =
"The provided chain of files is empty, cannot process tree " +
fTreeName;
199 throw std::runtime_error(msg);
210 auto msg =
"The specified TTree is not linked to any file, in-memory-only trees are not supported. Cannot process tree " +
fTreeName;
211 throw std::runtime_error(msg);
223 for (
Long64_t i = 0; i < numEntries; ++i) {
242 for (
auto &
name : ffn) {
243 fileNames.emplace_back(
name);
255 std::unique_ptr<TTreeReader>
reader;
256 std::unique_ptr<TEntryList> elist;
264 if (entry >= start && entry < end)
272 fChain->LoadTree(start - 1);
273 reader->SetEntriesRange(start, end);
276 return std::make_pair(std::move(
reader), std::move(elist));
314 std::vector<ROOT::Internal::TreeViewCluster>
MakeClusters();
327 #endif // defined TTreeProcessorMT virtual const char * GetName() const
Returns name of object.
std::string GetName(const std::string &scope_name)
const std::vector< std::string > & GetFileNames() const
Get the filenames for this view.
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.
virtual Long64_t GetN() const
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
basic_string_view< char > string_view
Namespace for new ROOT classes and functions.
std::pair< std::unique_ptr< TTreeReader >, std::unique_ptr< TEntryList > > TreeReaderEntryListPair
Get a TTreeReader for the current tree of this view.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
A cluster of entries as seen by TTreeView.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
std::pair< std::string, std::string > NameAlias
std::string GetTreeName() const
Get the name of the tree of this view.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
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 TTreeView.
std::vector< std::string > fFileNames
Names of the files.
TTreeView(const TTreeView &view)
Copy constructor.
void StoreFriends(const TTree &tree, bool isTree)
Get and store the names, aliases and file names of the friends of the tree.
TTreeView(TTree &tree, TEntryList &entries)
Constructor based on a TTree and a TEntryList.
void RestoreLoadedEntry()
Restore the tree of the previous loaded entry, if any.
TreeReaderEntryListPair GetTreeReader(Long64_t start, Long64_t end)
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()
std::unique_ptr< TChain > fChain
Chain on which to operate.
void Process(std::function< void(TTreeReader &)> func)
Process the entries of a TTree in parallel.
std::vector< ROOT::Internal::TreeViewCluster > MakeClusters()
Divide input data in clusters, i.e. the workloads to distribute to tasks.
ROOT::TThreadedObject< ROOT::Internal::TTreeView > treeView
! Thread-local TreeViews
virtual Bool_t Enter(Long64_t entry, TTree *tree=0)
Add entry #entry to the list.
std::vector< Long64_t > fLoadedEntries
! Per-task loaded entries (for task interleaving)
void PushLoadedEntry(Long64_t entry)
Push a new loaded entry to the stack.
TClassRef is used to implement a permanent reference to a TClass object.
virtual TList * GetListOfKeys() const
A TFriendElement TF describes a TTree object TF in a file.
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.
TTreeProcessorMT(std::string_view filename, std::string_view treename="")
Constructor based on a file name.
std::vector< NameAlias > fFriendNames
<name,alias> pairs of the friends of the tree/chain
A List of entry numbers in a TTree or TChain.
A class to process the entries of a TTree in parallel.
TEntryList fEntryList
Entry numbers to be processed.
std::vector< std::vector< std::string > > fFriendFileNames
Names of the files where friends are stored.
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
TTreeView(std::string_view fn, std::string_view tn)
Constructor based on a file name.
std::vector< std::unique_ptr< TChain > > fFriends
Friends of the tree/chain.