11#include "RConfigure.h"
44 return *
c->GetTypeInfo();
45 }
else if (
name ==
"char" ||
name ==
"Char_t")
47 else if (
name ==
"unsigned char" ||
name ==
"UChar_t")
48 return typeid(
unsigned char);
49 else if (
name ==
"int" ||
name ==
"Int_t")
51 else if (
name ==
"unsigned int" ||
name ==
"UInt_t")
52 return typeid(
unsigned int);
53 else if (
name ==
"short" ||
name ==
"Short_t")
55 else if (
name ==
"unsigned short" ||
name ==
"UShort_t")
56 return typeid(
unsigned short);
57 else if (
name ==
"long" ||
name ==
"Long_t")
59 else if (
name ==
"unsigned long" ||
name ==
"ULong_t")
60 return typeid(
unsigned long);
61 else if (
name ==
"double" ||
name ==
"Double_t")
62 return typeid(double);
63 else if (
name ==
"float" ||
name ==
"Float_t")
65 else if (
name ==
"long long" ||
name ==
"long long int" ||
name ==
"Long64_t")
67 else if (
name ==
"unsigned long long" ||
name ==
"unsigned long long int" ||
name ==
"ULong64_t")
69 else if (
name ==
"bool" ||
name ==
"Bool_t")
72 std::string msg(
"Cannot extract type_info of type ");
75 throw std::runtime_error(msg);
87 }
else if (
id ==
typeid(
char))
89 else if (
id ==
typeid(
unsigned char))
90 return "unsigned char";
91 else if (
id ==
typeid(
int))
93 else if (
id ==
typeid(
unsigned int))
94 return "unsigned int";
95 else if (
id ==
typeid(
short))
97 else if (
id ==
typeid(
unsigned short))
98 return "unsigned short";
99 else if (
id ==
typeid(
long))
101 else if (
id ==
typeid(
unsigned long))
102 return "unsigned long";
103 else if (
id ==
typeid(
double))
105 else if (
id ==
typeid(
float))
111 else if (
id ==
typeid(
bool))
119 return "ROOT::VecOps::RVec<" + valueType +
">";
126 throw std::runtime_error(
"Could not deduce type of leaf " + colName);
135 throw std::runtime_error(
"TTree leaf " + colName +
136 " has both a leaf count and a static length. This is not supported.");
151 auto leaf = t.
GetLeaf(colName.c_str());
153 const auto dotPos = colName.find_last_of(
'.');
154 const auto hasDot = dotPos != std::string::npos;
156 const auto branchName = colName.substr(0, dotPos);
157 const auto leafName = colName.substr(dotPos + 1);
158 leaf = t.
GetLeaf(branchName.c_str(), leafName.c_str());
165 auto branch = t.
GetBranch(colName.c_str());
168 if (leaves->GetEntries() == 1 && branch->GetListOfBranches()->GetEntries() == 0 &&
178 auto branch = t.
GetBranch(colName.c_str());
180 static const TClassRef tbranchelement(
"TBranchElement");
181 if (branch->InheritsFrom(tbranchelement)) {
183 if (
auto currentClass = be->GetCurrentClass())
184 return currentClass->
GetName();
188 auto mother = be->GetMother();
189 if (mother && mother->InheritsFrom(tbranchelement) && mother != be) {
191 auto beMomClass = beMom->
GetClass();
192 if (beMomClass && 0 == strcmp(
"TClonesArray", beMomClass->GetName()))
193 return be->GetTypeName();
195 return be->GetClassName();
201 return std::string();
211 RDataSource *ds,
bool isCustomColumn,
bool vector2rvec,
unsigned int customColID)
218 if (colType.empty() &&
tree) {
221 std::vector<std::string> split;
224 auto &valueType = split[1];
229 if (colType.empty() && isCustomColumn) {
231 colType =
"__rdf" + std::to_string(namespaceID) +
"::" + colName + std::to_string(customColID) +
"_type";
235 throw std::runtime_error(
"Column \"" + colName +
236 "\" is not in a dataset and is not a custom column been defined.");
245 if (
b ==
"Char_t" ||
b ==
"char")
247 if (
b ==
"UChar_t" ||
b ==
"unsigned char")
249 if (
b ==
"Short_t" ||
b ==
"short" ||
b ==
"short int")
251 if (
b ==
"UShort_t" ||
b ==
"unsigned short" ||
b ==
"unsigned short int")
253 if (
b ==
"Int_t" ||
b ==
"int")
255 if (
b ==
"UInt_t" ||
b ==
"unsigned" ||
b ==
"unsigned int")
257 if (
b ==
"Float_t" ||
b ==
"float")
259 if (
b ==
"Double_t" ||
b ==
"double")
261 if (
b ==
"Long64_t" ||
b ==
"long" ||
b ==
"long int")
263 if (
b ==
"ULong64_t" ||
b ==
"unsigned long" ||
b ==
"unsigned long int")
265 if (
b ==
"Bool_t" ||
b ==
"bool")
272 unsigned int nSlots = 1;
285 auto newColNames = columnNames;
286 for (
auto &col : newColNames) {
287 const auto dotPos = col.find(
'.');
288 if (dotPos != std::string::npos && dotPos != col.size() - 1 && dotPos != 0u) {
290 std::replace(col.begin(), col.end(),
'.',
'_');
291 if (std::find(columnNames.begin(), columnNames.end(), col) != columnNames.end())
292 throw std::runtime_error(
"Column " + oldName +
" would be written as " + col +
293 " but this column already exists. Please use Alias to select a new name for " +
295 Info(
"Snapshot",
"Column %s will be saved as %s", oldName.c_str(), col.c_str());
305 const auto msg =
"\nAn error occurred while jitting. The lines above might indicate the cause of the crash\n";
306 throw std::runtime_error(msg);
313 auto res =
gInterpreter->Calc(code.c_str(), &errorCode);
314 if (errorCode != TInterpreter::EErrorCode::kNoError) {
315 std::string msg =
"\nAn error occurred while jitting";
316 if (!context.empty())
317 msg +=
" in " + context;
318 msg +=
". The lines above might indicate the cause of the crash\n";
319 throw std::runtime_error(msg);
static RooMathCoreReg dummy
unsigned long long ULong64_t
void Info(const char *location, const char *msgfmt,...)
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
virtual bool HasColumn(std::string_view) const =0
Checks if the dataset has a certain column.
virtual std::string GetTypeName(std::string_view) const =0
Type of a column as a string, e.g.
A Branch for the case of an object.
virtual TClass * GetClass() const
TObjArray * GetListOfLeaves()
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 TString GetFullName() const
Return the full name (including the parent's branch names) of the leaf.
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 * 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...
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 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.
Long64_t InterpreterCalc(const std::string &code, const std::string &context)
std::string ColumnName2ColumnTypeName(const std::string &colName, unsigned int namespaceID, TTree *tree, RDataSource *ds, bool isCustomColumn, bool vector2rvec, unsigned int customColID)
Return a string containing the type of the given branch.
void InterpreterDeclare(const std::string &code)
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
UInt_t GetImplicitMTPoolSize()
Returns the size of the pool used for implicit multi-threading.
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.