33 default:
return false;
37std::tuple<bool, std::string, ROOT::Internal::RDF::RTreeUntypedArrayColumnReader::ECollectionType>
38GetCollectionInfo(
const std::string &typeName)
40 const auto beginType = typeName.substr(0, typeName.find_first_of(
'<') + 1);
43 if (
auto pos =
beginType.find(
"RVec<"); pos != std::string::npos) {
44 const auto begin = typeName.find_first_of(
'<', pos) + 1;
45 const auto end = typeName.find_last_of(
'>');
46 const auto innerTypeName = typeName.substr(begin, end - begin);
54 if (
auto pos =
beginType.find(
"array<"); pos != std::string::npos) {
55 const auto begin = typeName.find_first_of(
'<', pos) + 1;
56 const auto end = typeName.find_last_of(
'>');
57 const auto arrTemplArgs = typeName.substr(begin, end - begin);
115 if (!prefix.empty() && prefix.back() ==
'.')
121 for (
auto sb : *
b->GetListOfBranches()) {
163 std::string err(
"GetBranchNames: error in opening the tree ");
165 throw std::runtime_error(err);
196 throw std::runtime_error(
"GetBranchNames: unsupported branch type");
198 if (
be->GetType() == 3 ||
be->GetType() == 4)
224 if (
alias !=
nullptr)
238 std::vector<std::string>
bNames;
260 for (std::size_t i = 0
ul; i < fFriends.size(); i++) {
266 if (fBranchNamesWithDuplicates.empty())
268 if (fBranchNamesWithoutDuplicates.empty())
270 if (fTopLevelBranchNames.empty())
276 assert(tree &&
"No tree passed to the constructor of RTTreeDS!");
277 Setup(std::move(tree));
282 assert(tree &&
"No tree passed to the constructor of RTTreeDS!");
289 throw std::runtime_error(
"RDataFrame: invalid TDirectory when constructing the data source.");
294 throw std::runtime_error(
"RDataFrame: TTree dataset '" + std::string(
treeName) +
"' cannot be found in '" +
295 dirPtr->GetName() +
"'.");
304 if (
auto ch =
dynamic_cast<TChain *
>(fTree.get()); ch && !fNoCleanupNotifier) {
305 fNoCleanupNotifier = std::make_unique<ROOT::Internal::TreeUtils::RNoCleanupNotifier>();
306 fNoCleanupNotifier->RegisterChain(*ch);
317 Setup(std::move(chain));
323 if (
auto ch =
dynamic_cast<TChain *
>(fTree.get()); ch && !fNoCleanupNotifier) {
324 fNoCleanupNotifier = std::make_unique<ROOT::Internal::TreeUtils::RNoCleanupNotifier>();
325 fNoCleanupNotifier->RegisterChain(*ch);
334 chain->Add(
f.c_str());
336 Setup(std::move(chain));
343 if (
auto ch =
dynamic_cast<TChain *
>(fTree.get()); ch && !fNoCleanupNotifier) {
344 fNoCleanupNotifier = std::make_unique<ROOT::Internal::TreeUtils::RNoCleanupNotifier>();
345 fNoCleanupNotifier->RegisterChain(*ch);
361 unsigned int,
const std::unordered_map<std::string, ROOT::RDF::Experimental::RSample *> &
sampleMap)
const
364 auto *tree = fTreeReader->GetTree()->GetTree();
370 auto *file = tree->GetCurrentFile();
371 const std::string
fname = file !=
nullptr ? file->GetName() :
"#inmemorytree#";
373 std::pair<Long64_t, Long64_t>
range = fTreeReader->GetEntriesRange();
375 if (
range.second == -1) {
376 range.second = tree->GetEntries();
384 throw std::runtime_error(
"Full sample identifier '" +
id +
"' cannot be found in the available samples.");
397 auto tp{fGlobalEntryRange.has_value()
398 ? std::make_unique<ROOT::TTreeProcessorMT>(*fTree, fNSlots, fGlobalEntryRange.value(),
406 if (fGlobalEntryRange.has_value()) {
407 auto &&[begin, end] = fGlobalEntryRange.value();
411 "RDataFrame stopped processing after %lld entries, whereas an entry range (begin=%lld,end=%lld) was "
412 "requested. Consider adjusting the end value of the entry range to a maximum of %lld.",
423 assert(fTree &&
"The internal TTree is not available, something went wrong.");
424 if (
dynamic_cast<TChain *
>(fTree.get()))
427 return fTree->GetCurrentFile() ? 1 : 0;
432 assert(fTree &&
"The internal TTree is not available, something went wrong.");
433 const auto treeName = fTree->GetName();
434 const auto isTChain =
dynamic_cast<TChain *
>(fTree.get()) ?
true :
false;
439 std::stringstream
ss;
445 ss <<
" (in-memory)";
463 ss <<
"\nwith friend\n";
465 ss <<
"\nwith friends\n";
495std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
509 if (
ti ==
typeid(
void))
510 return std::make_unique<ROOT::Internal::RDF::RTreeOpaqueColumnReader>(*
treeReader, col);
517 return std::make_unique<ROOT::Internal::RDF::RTreeUntypedValueColumnReader>(*
treeReader, col, typeName);
523 if (fTreeReader->GetCurrentEntry() !=
static_cast<Long64_t>(
entry))
524 fTreeReader->SetEntry(
entry);
525 return ValidRead(fTreeReader->GetEntryStatus());
532 std::vector<std::string> split;
545 std::vector<std::string> split;
557 const ULong64_t rangeBegin = fGlobalEntryRange.has_value() ? std::max(0ull, fGlobalEntryRange->first) : 0ull;
559 ? std::min(
static_cast<ULong64_t>(tree.GetEntries()), fGlobalEntryRange->second)
560 :
static_cast<ULong64_t>(tree.GetEntries());
571 if (!
ValidRead(fTreeReader->GetEntryStatus()))
587 assert(fTreeReader &&
"TTreeReader is not available, this should never happen.");
589 assert(
treeOrChain &&
"Could not retrieve TTree from TTreeReader, something went wrong.");
592 if (fTreeReader->GetCurrentEntry() >=
treeOrChain->GetEntriesFast() - 1 ||
593 (fGlobalEntryRange.has_value() &&
594 (
static_cast<ULong64_t>(fTreeReader->GetCurrentEntry()) >= fGlobalEntryRange->first &&
595 static_cast<ULong64_t>(fTreeReader->GetCurrentEntry()) == fGlobalEntryRange->second - 1))) {
602 return GetTChainEntryRange(*chain);
620 fTreeReader = std::make_unique<TTreeReader>(fTree.get(), fTree->GetEntryList(),
true);
621 if (fGlobalEntryRange.has_value() && fGlobalEntryRange->first <= std::numeric_limits<Long64_t>::max() &&
622 fGlobalEntryRange->second <= std::numeric_limits<Long64_t>::max() && fTreeReader &&
623 fTreeReader->SetEntriesRange(fGlobalEntryRange->first, fGlobalEntryRange->second) !=
625 throw std::logic_error(
"Something went wrong in initializing the TTreeReader.");
641 throw std::runtime_error(
"An error was encountered while processing the data. TTreeReader status code is: " +
642 std::to_string(fTreeReader->GetEntryStatus()));
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
The head node of a RDF computation graph.
std::vector< std::pair< ULong64_t, ULong64_t > > GetTTreeEntryRange(TTree &tree)
std::size_t GetNFiles() const final
Returns the number of files from which the dataset is constructed.
std::string DescribeDataset() final
std::unique_ptr< ROOT::Internal::TreeUtils::RNoCleanupNotifier > fNoCleanupNotifier
void Setup(std::shared_ptr< TTree > &&tree, const ROOT::TreeUtils::RFriendInfo *friendInfo=nullptr)
void Initialize() final
Convenience method called before starting an event-loop.
void Finalize() final
Convenience method called after concluding an event-loop.
bool SetEntry(unsigned int, ULong64_t entry) final
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
void InitializeWithOpts(const std::set< std::string > &suppressErrorsForMissingBranches) final
std::vector< std::pair< ULong64_t, ULong64_t > > GetTChainEntryRange(TChain &chain)
RTTreeDS(std::shared_ptr< TTree > tree)
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges() final
Return ranges of entries to distribute to tasks.
std::shared_ptr< TTree > fTree
std::string GetTypeName(std::string_view colName) const final
Type of a column as a string, e.g.
A thread-safe list of N indexes (0 to size - 1).
friend std::string ROOT::Internal::RDF::GetTypeNameWithOpts(const RDataSource &, std::string_view, bool)
friend ROOT::RDF::RSampleInfo ROOT::Internal::RDF::CreateSampleInfo(const ROOT::RDF::RDataSource &, unsigned int, const std::unordered_map< std::string, ROOT::RDF::Experimental::RSample * > &)
friend std::unique_ptr< ROOT::Detail::RDF::RColumnReaderBase > ROOT::Internal::RDF::CreateColumnReader(ROOT::RDF::RDataSource &, unsigned int, std::string_view, const std::type_info &, TTreeReader *)
friend void ROOT::Internal::RDF::ProcessMT(RDataSource &, ROOT::Detail::RDF::RLoopManager &)
friend void ROOT::Internal::RDF::RunFinalChecks(const ROOT::RDF::RDataSource &, bool)
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
const_iterator end() const
A Branch for the case of an object.
A TTree is a list of TBranches.
A chain is a collection of files containing TTree objects.
Describe directory structure in memory.
A List of entry numbers in a TTree or TChain.
A TFriendElement TF describes a TTree object TF in a file.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
const char * GetName() const override
Returns name of object.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
@ kIndexedFriendNoMatch
A friend with TTreeIndex doesn't have an entry for this index.
@ kMissingBranchWhenSwitchingTree
A branch was not found when switching to the next TTree in the chain.
@ kEntryBeyondEnd
last entry loop has reached its end
@ kEntryValid
data read okay
A TTree represents a columnar dataset.
virtual TBranch * FindBranch(const char *name)
Return the branch that correspond to the path 'branchname', which can include the name of the tree or...
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual TObjArray * GetListOfBranches()
virtual TTree * GetTree() const
virtual const char * GetFriendAlias(TTree *) const
If the 'tree' is a friend, this method returns its alias name.
auto MakeAliasedSharedPtr(T *rawPtr)
std::string TypeID2TypeName(const std::type_info &id)
Returns the name of a type starting from its type_info An empty string is returned in case of failure...
ROOT::RDataFrame FromTTree(std::string_view treeName, std::string_view fileNameGlob)
std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
Return the typename of object colName stored in t, if any.
std::vector< std::string > GetTreeFullPaths(const TTree &tree)
std::vector< std::string > GetTopLevelBranchNames(TTree &t)
Get all the top-level branches names, including the ones of the friend trees.
std::unique_ptr< TChain > MakeChainForMT(const std::string &name="", const std::string &title="")
Create a TChain object with options that avoid common causes of thread contention.
std::vector< std::unique_ptr< TChain > > MakeFriends(const ROOT::TreeUtils::RFriendInfo &finfo)
Create friends from the main TTree.
ROOT::TreeUtils::RFriendInfo GetFriendInfo(const TTree &tree, bool retrieveEntries=false)
std::vector< std::string > GetFileNamesFromTree(const TTree &tree)
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
Information about friend trees of a certain TTree or TChain object.