25#include <unordered_set>
44 const auto treeName = tree->GetName();
45 const auto isTChain =
dynamic_cast<TChain *
>(tree) ?
true :
false;
46 const auto treeType = isTChain ?
"TChain" :
"TTree";
47 const auto isInMemory = !isTChain && !tree->GetCurrentFile() ?
true :
false;
49 const auto hasFriends = friendInfo.fFriendNames.empty() ? false :
true;
51 ss <<
"Dataframe from " << treeType;
53 ss <<
" " << treeName;
59 const auto numFiles = files.size();
61 ss <<
" in file " << files[0];
64 for (
auto i = 0u;
i < numFiles;
i++) {
65 ss <<
" " << files[
i];
72 const auto numFriends = friendInfo.fFriendNames.size();
73 if (numFriends == 1) {
74 ss <<
"\nwith friend\n";
76 ss <<
"\nwith friends\n";
78 for (
auto i = 0u;
i < numFriends;
i++) {
79 const auto nameAlias = friendInfo.fFriendNames[
i];
80 const auto files = friendInfo.fFriendFileNames[
i];
81 const auto numFiles = files.size();
82 const auto subnames = friendInfo.fFriendChainSubNames[
i];
83 ss <<
" " << nameAlias.first;
84 if (nameAlias.first != nameAlias.second)
85 ss <<
" (" << nameAlias.second <<
")";
88 ss <<
" " << files[0];
93 for (
auto j = 0u; j < numFiles; j++) {
94 ss <<
" " << subnames[j] <<
" " << files[j];
99 if (
i < numFriends - 1)
107 const auto datasourceLabel =
fDataSource->GetLabel();
108 return "Dataframe from datasource " + datasourceLabel;
114 return "Empty dataframe filling 1 row";
116 return "Empty dataframe filling " + std::to_string(
n) +
" rows";
129 fDataSource(lm.GetDataSource()),
130 fColRegister(colRegister)
150 std::unordered_set<std::string> allColumns;
152 auto addIfNotInternal = [&allColumns](std::string_view colName) {
154 allColumns.emplace(colName);
157 auto definedColumns =
fColRegister.GenerateColumnNames();
159 std::for_each(definedColumns.begin(), definedColumns.end(), addIfNotInternal);
164 allColumns.emplace(bName);
168 for (
const auto &s :
fDataSource->GetColumnNames()) {
169 if (s.rfind(
"R_rdf_sizeof", 0) != 0)
170 allColumns.emplace(s);
175 std::sort(ret.begin(), ret.end());
196 RDFDetail::RDefineBase *define =
fColRegister.GetDefine(col);
198 const bool convertVector2RVec =
true;
200 fLoopManager->GetDataSource(), define, convertVector2RVec);
237 std::set<std::string> definedColumnNamesSet;
239 definedColumnNamesSet.insert(
name);
242 const std::vector<std::string> metadataProperties = {
"Columns in total",
"Columns from defines",
"Event loops run",
244 const std::vector<std::string> metadataValues = {std::to_string(columnNames.size()),
245 std::to_string(definedColumnNamesSet.size()),
252 const auto columnWidthValues =
253 std::max(std::max_element(metadataValues.begin(), metadataValues.end())->size(),
static_cast<std::size_t
>(5u));
254 std::stringstream ss;
255 ss << std::left << std::setw(columnWidthProperties) <<
"Property" << std::setw(columnWidthValues) <<
"Value\n"
256 << std::setw(columnWidthProperties) <<
"--------" << std::setw(columnWidthValues) <<
"-----\n";
260 for (
auto i = 0u;
i < metadataProperties.size();
i++) {
261 ss << std::left << std::setw(columnWidthProperties) << metadataProperties[
i] << std::right
262 << std::setw(columnWidthValues) << metadataValues[
i] <<
'\n';
270 ss << std::left << std::setw(columnWidthNames) <<
"Column" << std::setw(columnWidthTypes) <<
"Type"
272 << std::setw(columnWidthNames) <<
"------" << std::setw(columnWidthTypes) <<
"----"
276 const auto nCols = columnNames.size();
277 for (
auto i = 0u;
i < nCols;
i++) {
278 auto origin =
"Dataset";
279 if (definedColumnNamesSet.find(columnNames[
i]) != definedColumnNamesSet.end())
281 ss << std::left << std::setw(columnWidthNames) << columnNames[
i] << std::setw(columnWidthTypes) << columnTypes[
i]
309 for (
const auto &column : columns) {
311 definedColumns.emplace_back(column);
314 return definedColumns;
354 const auto &branchNames =
fLoopManager->GetBranchNames();
355 const auto branchNamesEnd = branchNames.end();
356 if (branchNamesEnd != std::find(branchNames.begin(), branchNamesEnd, columnName))
404 std::vector<std::string> types;
406 for (
auto column : columnList) {
415 std::string error(callerName);
416 error +=
" was called with ImplicitMT enabled, but multi-thread is not supported.";
417 throw std::runtime_error(error);
424 const std::string entryColName =
"rdfentry_";
425 const std::string entryColType =
"ULong64_t";
426 auto entryColGen = [](
unsigned int,
ULong64_t entry) {
return entry; };
427 using NewColEntry_t = RDFDetail::RDefine<
decltype(entryColGen), RDFDetail::ExtraArgsForDefine::SlotAndEntry>;
429 auto entryColumn = std::make_shared<NewColEntry_t>(entryColName, entryColType, std::move(entryColGen),
434 const std::string slotColName =
"rdfslot_";
435 const std::string slotColType =
"unsigned int";
436 auto slotColGen = [](
unsigned int slot) {
return slot; };
437 using NewColSlot_t = RDFDetail::RDefine<
decltype(slotColGen), RDFDetail::ExtraArgsForDefine::Slot>;
439 auto slotColumn = std::make_shared<NewColSlot_t>(slotColName, slotColType, std::move(slotColGen),
ColumnNames_t{},
true
Register systematic variations for multiple existing columns using auto-generated tags.
RDFDetail::RLoopManager RLoopManager
unsigned long long ULong64_t
The head node of a RDF computation graph.
A binder for user-defined columns, variations and aliases.
A DFDescription contains useful information about a given RDataFrame computation graph.
RVariationsDescription GetVariations() const
Return a descriptor for the systematic variations registered in this branch of the computation graph.
std::string GetColumnType(std::string_view column)
Return the type of a given column as a string.
RDFDescription Describe()
Return information about the dataframe.
ColumnNames_t GetColumnTypeNamesList(const ColumnNames_t &columnList)
std::shared_ptr< ROOT::Detail::RDF::RLoopManager > fLoopManager
< The RLoopManager at the root of this computation graph. Never null.
unsigned int GetNRuns() const
Gets the number of event loops run.
RDataSource * fDataSource
Non-owning pointer to a data-source object. Null if no data-source. RLoopManager has ownership of the...
ColumnNames_t GetDefinedColumnNames()
Returns the names of the defined columns.
void CheckIMTDisabled(std::string_view callerName)
unsigned int GetNSlots() const
Gets the number of data processing slots.
RInterfaceBase(std::shared_ptr< RDFDetail::RLoopManager > lm)
bool HasColumn(std::string_view columnName)
Checks if a column is present in the dataset.
std::string DescribeDataset() const
ColumnNames_t GetColumnNames()
Returns the names of the available columns.
RDFInternal::RColumnRegister fColRegister
Contains the columns defined up to this node.
A descriptor for the systematic variations known to a given RDataFrame node.
A chain is a collection of files containing TTree objects.
std::vector< std::string > GetFileNamesFromTree(const TTree &tree)
Get and store the file names associated with the input tree.
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
std::vector< std::string > GetBranchNames(TTree &t, bool allowDuplicates=true)
Get all the branches names, including the ones of the friend trees.
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *, RDataSource *, RDefineBase *, bool vector2rvec=true)
Return a string containing the type of the given branch.
unsigned int GetColumnWidth(const std::vector< std::string > &names, const unsigned int minColumnSpace=8u)
Get optimal column width for printing a table given the names and the desired minimal space between c...
bool IsInternalColumn(std::string_view colName)
Whether custom column with name colName is an "internal" column such as rdfentry_ or rdfslot_.
ROOT::TreeUtils::RFriendInfo GetFriendInfo(const TTree &tree, bool retrieveEntries=false)
std::vector< std::string > ColumnNames_t
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.