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 +
">";
142 throw std::runtime_error(
"Could not deduce type of leaf " + colName);
151 throw std::runtime_error(
"TTree leaf " + colName +
152 " has both a leaf count and a static length. This is not supported.");
167 auto *leaf = t.
GetLeaf(colName.c_str());
172 const auto dotPos = colName.find_last_of(
'.');
173 const auto hasDot = dotPos != std::string::npos;
175 const auto branchName = colName.substr(0, dotPos);
176 const auto leafName = colName.substr(dotPos + 1);
177 leaf = t.
GetLeaf(branchName.c_str(), leafName.c_str());
184 auto branch = t.
GetBranch(colName.c_str());
188 static const TClassRef tbranchelement(
"TBranchElement");
189 if (branch->InheritsFrom(tbranchelement)) {
191 if (
auto currentClass = be->GetCurrentClass())
192 return currentClass->
GetName();
196 auto mother = be->GetMother();
197 if (mother && mother->InheritsFrom(tbranchelement) && mother != be) {
199 auto beMomClass = beMom->
GetClass();
200 if (beMomClass && 0 == std::strcmp(
"TClonesArray", beMomClass->GetName()))
201 return be->GetTypeName();
203 return be->GetClassName();
205 }
else if (branch->IsA() == TBranch::Class() && branch->GetListOfLeaves()->GetEntries() == 1) {
208 leaf =
static_cast<TLeaf *
>(branch->GetListOfLeaves()->UncheckedAt(0));
214 return std::string();
228 if (ds && ds->HasColumn(colName))
229 colType = ds->GetTypeName(colName);
231 if (colType.empty() &&
tree) {
234 std::vector<std::string> split;
237 auto &valueType = split[1];
242 if (colType.empty() && define) {
247 throw std::runtime_error(
"Column \"" + colName +
248 "\" is not in a dataset and is not a custom column been defined.");
257 if (
b ==
"Char_t" ||
b ==
"char")
259 if (
b ==
"UChar_t" ||
b ==
"unsigned char")
261 if (
b ==
"Short_t" ||
b ==
"short" ||
b ==
"short int")
263 if (
b ==
"UShort_t" ||
b ==
"unsigned short" ||
b ==
"unsigned short int")
265 if (
b ==
"Int_t" ||
b ==
"int")
267 if (
b ==
"UInt_t" ||
b ==
"unsigned" ||
b ==
"unsigned int")
269 if (
b ==
"Float_t" ||
b ==
"float")
271 if (
b ==
"Double_t" ||
b ==
"double")
273 if (
b ==
"Long64_t" ||
b ==
"long long" ||
b ==
"long long int")
275 if (
b ==
"ULong64_t" ||
b ==
"unsigned long long" ||
b ==
"unsigned long long int")
277 if (
b ==
"Long_t" ||
b ==
"long" ||
b ==
"long int")
279 if (
b ==
"ULong_t" ||
b ==
"unsigned long" ||
b ==
"unsigned long int")
281 if (
b ==
"Bool_t" ||
b ==
"bool")
288 unsigned int nSlots = 1;
301 auto newColNames = columnNames;
302 for (
auto &col : newColNames) {
303 const auto dotPos = col.find(
'.');
304 if (dotPos != std::string::npos && dotPos != col.size() - 1 && dotPos != 0u) {
306 std::replace(col.begin(), col.end(),
'.',
'_');
307 if (std::find(columnNames.begin(), columnNames.end(), col) != columnNames.end())
308 throw std::runtime_error(
"Column " + oldName +
" would be written as " + col +
309 " but this column already exists. Please use Alias to select a new name for " +
311 Info(
"Snapshot",
"Column %s will be saved as %s", oldName.c_str(), col.c_str());
320 R__LOG_DEBUG(10, RDFLogChannel()) <<
"Declaring the following code to cling:\n\n" << code <<
'\n';
324 "\nRDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of "
325 "the crash\n All RDF objects that have not run an event loop yet should be considered in an invalid state.\n";
326 throw std::runtime_error(msg);
332 R__LOG_DEBUG(10, RDFLogChannel()) <<
"Jitting and executing the following code:\n\n" << code <<
'\n';
335 auto res =
gInterpreter->Calc(code.c_str(), &errorCode);
337 std::string msg =
"\nAn error occurred during just-in-time compilation";
338 if (!context.empty())
339 msg +=
" in " + context;
340 msg +=
". The lines above might indicate the cause of the crash\nAll RDF objects that have not run their event "
341 "loop yet should be considered in an invalid state.\n";
342 throw std::runtime_error(msg);
349 const auto str = colName.data();
350 const auto goodPrefix = colName.size() > 3 &&
351 (
'r' == str[0] ||
't' == str[0]) &&
352 0 == strncmp(
"df", str + 1, 2);
353 return goodPrefix &&
'_' == colName.back();
#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.
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..
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 *tree, RDataSource *ds, RDefineBase *define, bool vector2rvec)
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...
std::string GetBranchOrLeafTypeName(TTree &t, const std::string &colName)
Return the typename of object colName stored in t, if any.
bool IsInternalColumn(std::string_view colName)
Long64_t InterpreterCalc(const std::string &code, const std::string &context)
void InterpreterDeclare(const std::string &code)
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.