12 #ifndef ROOT_TTreeProcessorMT 13 #define ROOT_TTreeProcessorMT 58 typedef std::pair<std::string, std::string>
NameAlias;
75 if (fTreeName.empty()) {
77 std::unique_ptr<TFile> f(
TFile::Open(fFileNames[0].c_str()));
80 const char *className = key->GetClassName();
81 if (strcmp(className,
"TTree") == 0) {
82 fTreeName = key->GetName();
86 if (fTreeName.empty()) {
87 auto msg =
"Cannot find any tree in file " + fFileNames[0];
88 throw std::runtime_error(msg);
92 fChain.reset(
new TChain(fTreeName.c_str()));
93 for (
auto &fn : fFileNames) {
94 fChain->
Add(fn.c_str());
99 for (
auto &na : fFriendNames) {
100 auto &
name = na.first;
101 auto &alias = na.second;
105 auto &fileNames = fFriendFileNames[friendNum];
106 for (
auto &fn : fileNames)
107 frChain->
Add(fn.c_str());
110 fFriends.emplace_back(frChain);
111 fChain->
AddFriend(frChain, alias.c_str());
125 for (
auto fr : *friends) {
129 auto realName = frTree->
GetName();
132 fFriendNames.emplace_back(std::make_pair(realName, std::string(alias)));
134 fFriendNames.emplace_back(std::make_pair(realName,
""));
138 fFriendFileNames.emplace_back();
139 auto &fileNames = fFriendFileNames.back();
141 auto f = frTree->GetCurrentFile();
142 fileNames.emplace_back(f->GetName());
144 auto frChain =
static_cast<TChain *
>(frTree);
145 for (
auto f : *(frChain->GetListOfFiles())) {
146 fileNames.emplace_back(f->GetTitle());
161 fFileNames.emplace_back(fn);
173 if (fns.size() > 0) {
175 fFileNames.emplace_back(fn);
179 auto msg =
"The provided list of file names is empty, cannot process tree " + fTreeName;
180 throw std::runtime_error(msg);
189 static const TClassRef clRefTChain(
"TChain");
190 if (clRefTChain == tree.IsA()) {
193 for (
auto f : *filelist)
194 fFileNames.emplace_back(f->GetTitle());
195 StoreFriends(tree,
false);
199 auto msg =
"The provided chain of files is empty, cannot process tree " + fTreeName;
200 throw std::runtime_error(msg);
206 fFileNames.emplace_back(f->
GetName());
207 StoreFriends(tree,
true);
211 auto msg =
"The specified TTree is not linked to any file, in-memory-only trees are not supported. Cannot process tree " + fTreeName;
212 throw std::runtime_error(msg);
224 for (
Long64_t i = 0; i < numEntries; ++i) {
235 fFileNames.emplace_back(fn);
238 fFriendNames.emplace_back(fn);
241 fFriendFileNames.emplace_back();
242 auto &fileNames = fFriendFileNames.back();
243 for (
auto &
name : ffn) {
244 fileNames.emplace_back(
name);
256 std::unique_ptr<TTreeReader>
reader;
257 std::unique_ptr<TEntryList> elist;
258 if (fEntryList.
GetN() > 0) {
265 if (entry >= start && entry < end)
267 }
while ((entry = fEntryList.
Next()) >= 0);
269 reader.reset(
new TTreeReader(fChain.get(), elist.get()));
277 return std::make_pair(std::move(reader), std::move(elist));
302 fLoadedEntries.pop_back();
303 if (fLoadedEntries.size() > 0) {
304 fChain->
LoadTree(fLoadedEntries.back());
315 std::vector<ROOT::Internal::TreeViewCluster> MakeClusters();
328 #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...
virtual TList * GetListOfFriends() const
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
void Init(TClassEdit::TInterpreterLookupHelper *helper)
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)
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 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.
EEntryStatus SetEntriesRange(Long64_t beginEntry, Long64_t endEntry)
Sets the entry that Next() will stop iteration on.
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)
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()
std::unique_ptr< TChain > fChain
Chain on which to operate.
virtual TFriendElement * AddFriend(const char *chainname, const char *dummy="")
Add a TFriendElement to the list of friends of this chain.
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.
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.
virtual const char * GetFriendAlias(TTree *) const
If the 'tree' is a friend, this method returns its alias name.
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.