11#include "RConfigure.h"
54 if (!
c->GetTypeInfo()) {
55 std::string msg(
"Cannot extract type_info of type ");
58 throw std::runtime_error(msg);
60 return *
c->GetTypeInfo();
61 }
else if (
name ==
"char" ||
name ==
"Char_t")
63 else if (
name ==
"unsigned char" ||
name ==
"UChar_t")
64 return typeid(
unsigned char);
65 else if (
name ==
"int" ||
name ==
"Int_t")
67 else if (
name ==
"unsigned int" ||
name ==
"UInt_t")
68 return typeid(
unsigned int);
69 else if (
name ==
"short" ||
name ==
"Short_t")
71 else if (
name ==
"unsigned short" ||
name ==
"UShort_t")
72 return typeid(
unsigned short);
73 else if (
name ==
"long" ||
name ==
"Long_t")
75 else if (
name ==
"unsigned long" ||
name ==
"ULong_t")
76 return typeid(
unsigned long);
77 else if (
name ==
"double" ||
name ==
"Double_t")
79 else if (
name ==
"float" ||
name ==
"Float_t")
81 else if (
name ==
"long long" ||
name ==
"long long int" ||
name ==
"Long64_t")
83 else if (
name ==
"unsigned long long" ||
name ==
"unsigned long long int" ||
name ==
"ULong64_t")
85 else if (
name ==
"bool" ||
name ==
"Bool_t")
88 std::string msg(
"Cannot extract type_info of type ");
91 throw std::runtime_error(msg);
103 }
else if (
id ==
typeid(
char))
105 else if (
id ==
typeid(
unsigned char))
106 return "unsigned char";
107 else if (
id ==
typeid(
int))
109 else if (
id ==
typeid(
unsigned int))
110 return "unsigned int";
111 else if (
id ==
typeid(
short))
113 else if (
id ==
typeid(
unsigned short))
114 return "unsigned short";
115 else if (
id ==
typeid(
long))
117 else if (
id ==
typeid(
unsigned long))
118 return "unsigned long";
119 else if (
id ==
typeid(
double))
121 else if (
id ==
typeid(
float))
127 else if (
id ==
typeid(
bool))
135 return "ROOT::VecOps::RVec<" + valueType +
">";
141 std::string colType = colTypeCStr ==
nullptr ?
"" : colTypeCStr;
143 throw std::runtime_error(
"Could not deduce type of leaf " + colName);
152 throw std::runtime_error(
"TTree leaf " + colName +
153 " has both a leaf count and a static length. This is not supported.");
168 auto *leaf = t.
GetLeaf(colName.c_str());
173 const auto dotPos = colName.find_last_of(
'.');
174 const auto hasDot = dotPos != std::string::npos;
176 const auto branchName = colName.substr(0, dotPos);
177 const auto leafName = colName.substr(dotPos + 1);
178 leaf = t.
GetLeaf(branchName.c_str(), leafName.c_str());
185 auto branch = t.
GetBranch(colName.c_str());
189 static const TClassRef tbranchelement(
"TBranchElement");
190 if (branch->InheritsFrom(tbranchelement)) {
192 if (
auto currentClass = be->GetCurrentClass())
193 return currentClass->
GetName();
197 auto mother = be->GetMother();
198 if (mother && mother->InheritsFrom(tbranchelement) && mother != be) {
200 auto beMomClass = beMom->
GetClass();
201 if (beMomClass && 0 == std::strcmp(
"TClonesArray", beMomClass->GetName()))
202 return be->GetTypeName();
204 return be->GetClassName();
206 }
else if (branch->IsA() == TBranch::Class() && branch->GetListOfLeaves()->GetEntriesUnsafe() == 1) {
209 leaf =
static_cast<TLeaf *
>(branch->GetListOfLeaves()->UncheckedAt(0));
215 return std::string();
232 }
else if (ds && ds->
HasColumn(colName)) {
237 std::vector<std::string> split;
240 auto &valueType = split[1];
246 throw std::runtime_error(
"Column \"" + colName +
247 "\" is not in a dataset and is not a custom column been defined.");
256 if (
b ==
"Char_t" ||
b ==
"char")
258 if (
b ==
"UChar_t" ||
b ==
"unsigned char")
260 if (
b ==
"Short_t" ||
b ==
"short" ||
b ==
"short int")
262 if (
b ==
"UShort_t" ||
b ==
"unsigned short" ||
b ==
"unsigned short int")
264 if (
b ==
"Int_t" ||
b ==
"int")
266 if (
b ==
"UInt_t" ||
b ==
"unsigned" ||
b ==
"unsigned int")
268 if (
b ==
"Float_t" ||
b ==
"float")
270 if (
b ==
"Double_t" ||
b ==
"double")
272 if (
b ==
"Long64_t" ||
b ==
"long long" ||
b ==
"long long int")
274 if (
b ==
"ULong64_t" ||
b ==
"unsigned long long" ||
b ==
"unsigned long long int")
276 if (
b ==
"Long_t" ||
b ==
"long" ||
b ==
"long int")
278 if (
b ==
"ULong_t" ||
b ==
"unsigned long" ||
b ==
"unsigned long int")
280 if (
b ==
"Bool_t" ||
b ==
"bool")
287 unsigned int nSlots = 1;
300 auto newColNames = columnNames;
301 for (
auto &col : newColNames) {
302 const auto dotPos = col.find(
'.');
303 if (dotPos != std::string::npos && dotPos != col.size() - 1 && dotPos != 0u) {
305 std::replace(col.begin(), col.end(),
'.',
'_');
306 if (std::find(columnNames.begin(), columnNames.end(), col) != columnNames.end())
307 throw std::runtime_error(
"Column " + oldName +
" would be written as " + col +
308 " but this column already exists. Please use Alias to select a new name for " +
310 Info(
"Snapshot",
"Column %s will be saved as %s", oldName.c_str(), col.c_str());
323 "\nRDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of "
324 "the crash\n All RDF objects that have not run an event loop yet should be considered in an invalid state.\n";
325 throw std::runtime_error(msg);
335 auto callCalc = [&errorCode, &context](
const std::string &codeSlice) {
338 std::string msg =
"\nAn error occurred during just-in-time compilation";
339 if (!context.empty())
340 msg +=
" in " + context;
342 ". The lines above might indicate the cause of the crash\nAll RDF objects that have not run their event "
343 "loop yet should be considered in an invalid state.\n";
344 throw std::runtime_error(msg);
350 std::size_t substr_start = 0;
351 std::size_t substr_end = 0;
352 while (substr_end != std::string::npos && substr_start != code.size() - 1) {
353 for (std::size_t i = 0u; i < 1000u && substr_end != std::string::npos; ++i) {
354 substr_end = code.find(
'\n', substr_end + 1);
356 const std::string subs = code.substr(substr_start, substr_end - substr_start);
357 substr_start = substr_end;
367 const auto str = colName.data();
368 const auto goodPrefix = colName.size() > 3 &&
369 (
'r' == str[0] ||
't' == str[0]) &&
370 0 == strncmp(
"df", str + 1, 2);
371 return goodPrefix &&
'_' == colName.back();
374unsigned int GetColumnWidth(
const std::vector<std::string>& names,
const unsigned int minColumnSpace)
376 auto columnWidth = 0u;
377 for (
const auto&
name : names) {
378 const auto length =
name.length();
379 if (length > columnWidth)
380 columnWidth = length;
382 columnWidth = (columnWidth / minColumnSpace + 1) * minColumnSpace;
387 const std::string &colName,
const std::string &where)
391 const auto diffTypes = (0 != std::strcmp(colType.name(), requestedType.name()));
392 auto inheritedType = [&]() {
394 return colTClass && colTClass->InheritsFrom(
TClass::GetClass(requestedType));
397 if (diffTypes && !inheritedType()) {
400 std::string errMsg = where +
": type mismatch: column \"" + colName +
"\" is being used as ";
402 errMsg += requestedType.name();
403 errMsg +=
" (extracted from type info)";
407 errMsg +=
" but the Define or Vary node advertises it as ";
408 if (colTypeName.empty()) {
411 errMsg +=
" (extracted from type info)";
413 errMsg += colTypeName;
415 throw std::runtime_error(errMsg);
421 return std::find(
vec.cbegin(),
vec.cend(), str) !=
vec.cend();
#define R__LOG_DEBUG(DEBUGLEVEL,...)
unsigned long long ULong64_t
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
std::string GetTypeName() const
A log configuration for a channel, e.g.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
virtual bool HasColumn(std::string_view colName) const =0
Checks if the dataset has a certain column.
virtual std::string GetTypeName(std::string_view colName) const =0
Type of a column as a string, e.g.
A Branch for the case of an object.
virtual TClass * GetClass() const
TClassRef is used to implement a permanent reference to a TClass object.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetTypeName() const
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
virtual const char * GetName() const
Returns name of object.
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 TLeaf * GetLeaf(const char *branchname, const char *leafname)
Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of fri...
virtual TLeaf * FindLeaf(const char *name)
Find leaf..
ROOT::Experimental::RLogChannel & RDFLogChannel()
std::vector< std::string > ReplaceDotWithUnderscore(const std::vector< std::string > &columnNames)
Replace occurrences of '.
const std::type_info & TypeName2TypeID(const std::string &name)
Return the type_info associated to a name.
std::string ComposeRVecTypeName(const std::string &valueType)
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *, RDataSource *, RDefineBase *, bool vector2rvec=true)
Return a string containing the type of the given branch.
std::string GetLeafTypeName(TLeaf *leaf, const std::string &colName)
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
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...
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)
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...
std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
Return the typename of object colName stored in t, if any.
Long64_t InterpreterCalc(const std::string &code, const std::string &context="")
Jit code in the interpreter with TInterpreter::Calc, throw in case of errors.
bool IsInternalColumn(std::string_view colName)
Whether custom column with name colName is an "internal" column such as rdfentry_ or rdfslot_.
void CheckReaderTypeMatches(const std::type_info &colType, const std::type_info &requestedType, const std::string &colName, const std::string &where)
void InterpreterDeclare(const std::string &code)
Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors.
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.
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
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.