11 #include "RConfigure.h" 30 TIgnoreErrorLevelRAII::TIgnoreErrorLevelRAII(
int errorIgnoreLevel)
34 TIgnoreErrorLevelRAII::~TIgnoreErrorLevelRAII()
46 return *c->GetTypeInfo();
47 }
else if (name ==
"char" || name ==
"Char_t")
49 else if (name ==
"unsigned char" || name ==
"UChar_t")
50 return typeid(
unsigned char);
51 else if (name ==
"int" || name ==
"Int_t")
53 else if (name ==
"unsigned int" || name ==
"UInt_t")
54 return typeid(
unsigned int);
55 else if (name ==
"short" || name ==
"Short_t")
57 else if (name ==
"unsigned short" || name ==
"UShort_t")
58 return typeid(
unsigned short);
59 else if (name ==
"long" || name ==
"Long_t")
61 else if (name ==
"unsigned long" || name ==
"ULong_t")
62 return typeid(
unsigned long);
63 else if (name ==
"double" || name ==
"Double_t")
64 return typeid(double);
65 else if (name ==
"float" || name ==
"Float_t")
67 else if (name ==
"long long" || name ==
"long long int" || name ==
"Long64_t")
69 else if (name ==
"unsigned long long" || name ==
"unsigned long long int" || name ==
"ULong64_t")
71 else if (name ==
"bool" || name ==
"Bool_t")
74 std::string msg(
"Cannot extract type_info of type ");
77 throw std::runtime_error(msg);
89 }
else if (
id ==
typeid(
char))
91 else if (
id ==
typeid(
unsigned char))
92 return "unsigned char";
93 else if (
id ==
typeid(
int))
95 else if (
id ==
typeid(
unsigned int))
96 return "unsigned int";
97 else if (
id ==
typeid(
short))
99 else if (
id ==
typeid(
unsigned short))
100 return "unsigned short";
101 else if (
id ==
typeid(
long))
103 else if (
id ==
typeid(
unsigned long))
104 return "unsigned long";
105 else if (
id ==
typeid(
double))
107 else if (
id ==
typeid(
float))
113 else if (
id ==
typeid(
bool))
132 branch = tree->GetBranch(colName.c_str());
135 static const TClassRef tbranchelRef(
"TBranchElement");
142 const auto nLeaves = listOfLeaves->
GetEntries();
144 throw std::runtime_error(
"TTree branch " + colName +
" has " + std::to_string(nLeaves) +
145 " leaves. Only one leaf per branch is supported.");
146 TLeaf *
l =
static_cast<TLeaf *
>(listOfLeaves->UncheckedAt(0));
148 if (branchType.empty()) {
149 throw std::runtime_error(
"could not deduce type of branch " + std::string(colName));
152 return "ROOT::Experimental::TDF::TArrayBranch<" + branchType +
">";
155 return "ROOT::Experimental::TDF::TArrayBranch<" + branchType +
">";
161 throw std::runtime_error(
"TTree branch " + colName +
162 " has both a leaf count and a static length. This is not supported.");
165 }
else if (tmpBranch) {
169 if (typeName.empty()) {
170 std::string msg(
"Cannot deduce type of temporary column ");
172 msg +=
". The typename is ";
175 throw std::runtime_error(msg);
179 throw std::runtime_error(
"Column \"" + colName +
"\" is not in a file and has not been defined.");
205 if (b ==
"ULong64_t")
224 unsigned int nSlots = 1;
235 std::set<TTree *> &analysedTrees)
238 if (!analysedTrees.insert(&t).second) {
242 auto branches = t.GetListOfBranches();
245 auto name = branchObj->GetName();
246 if (bNamesReg.insert(
name).second) {
247 bNames.emplace_back(
name);
252 auto friendTrees = t.GetListOfFriends();
257 for (
auto friendTreeObj : *friendTrees) {
267 std::set<std::string> bNamesSet;
268 ColumnNames_t bNames;
269 std::set<TTree *> analysedTrees;
275 const ColumnNames_t &dataSourceColumns)
277 const std::string definedColStr(definedCol);
278 if (treePtr !=
nullptr) {
280 const auto branch = treePtr->GetBranch(definedColStr.c_str());
281 if (branch !=
nullptr) {
282 const auto msg =
"branch \"" + definedColStr +
"\" already present in TTree";
283 throw std::runtime_error(msg);
287 if (std::find(customCols.begin(), customCols.end(), definedCol) != customCols.end()) {
288 const auto msg =
"Redefinition of column \"" + definedColStr +
"\"";
289 throw std::runtime_error(msg);
292 if (!dataSourceColumns.empty()) {
293 if (std::find(dataSourceColumns.begin(), dataSourceColumns.end(), definedCol) != dataSourceColumns.end()) {
294 const auto msg =
"Redefinition of column \"" + definedColStr +
"\" already present in the data-source";
295 throw std::runtime_error(msg);
302 if (nTemplateParams != nColumnNames) {
303 std::string err_msg =
"The number of template parameters specified for the snapshot is ";
304 err_msg += std::to_string(nTemplateParams);
305 err_msg +=
" while ";
306 err_msg += std::to_string(nColumnNames);
307 err_msg +=
" columns have been specified.";
308 throw std::runtime_error(err_msg);
314 SelectColumns(
unsigned int nRequiredNames,
const ColumnNames_t &names,
const ColumnNames_t &defaultNames)
318 if (defaultNames.size() < nRequiredNames)
319 throw std::runtime_error(
320 std::to_string(nRequiredNames) +
" column name" + (nRequiredNames == 1 ?
" is" :
"s are") +
321 " required but none were provided and the default list has size " + std::to_string(defaultNames.size()));
323 return ColumnNames_t(defaultNames.begin(), defaultNames.begin() + nRequiredNames);
326 if (names.size() != nRequiredNames) {
327 auto msg = std::to_string(nRequiredNames) +
" column name" + (nRequiredNames == 1 ?
" is" :
"s are") +
328 " required but " + std::to_string(names.size()) + (names.size() == 1 ?
" was" :
" were") +
330 for (
const auto &
name : names)
331 msg +=
" \"" +
name +
"\",";
333 throw std::runtime_error(msg);
340 const ColumnNames_t &dataSourceColumns)
342 ColumnNames_t unknownColumns;
343 for (
auto &column : requiredCols) {
344 const auto isTreeBranch = (tree !=
nullptr && tree->GetBranch(column.c_str()) !=
nullptr);
347 const auto isCustomColumn = std::find(definedCols.begin(), definedCols.end(), column) != definedCols.end();
350 const auto isDataSourceColumn =
351 std::find(dataSourceColumns.begin(), dataSourceColumns.end(), column) != dataSourceColumns.end();
352 if (isDataSourceColumn)
354 unknownColumns.emplace_back(column);
356 return unknownColumns;
361 return 0 == colName.find(
"tdf") &&
'_' == colName.back();
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...
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
UInt_t GetImplicitMTPoolSize()
Returns the size of the pool used for implicit multi-threading.
const std::type_info & TypeName2TypeID(const std::string &name)
Return the type_info associated to a name.
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
R__EXTERN Int_t gErrorIgnoreLevel
basic_string_view< char > string_view
Namespace for new ROOT classes and functions.
ColumnNames_t FindUnknownColumns(const ColumnNames_t &requiredCols, TTree *tree, const ColumnNames_t &definedCols, const ColumnNames_t &dataSourceColumns)
TTree()
Default constructor and I/O constructor.
virtual const char * GetTypeName() const
void CheckCustomColumn(std::string_view definedCol, TTree *treePtr, const ColumnNames_t &customCols, const ColumnNames_t &dataSourceColumns)
const char * ToConstCharPtr(const std::string &s)
bool IsInternalColumn(std::string_view colName)
const ColumnNames_t SelectColumns(unsigned int nRequiredNames, const ColumnNames_t &names, const ColumnNames_t &defaultNames)
Choose between local column names or default column names, throw in case of errors.
TDataSource defines an API that TDataFrame can use to read arbitrary data formats.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual TLeaf * GetLeafCount() const
virtual std::string GetTypeName(std::string_view) const =0
Type of a column as a string, e.g.
virtual Int_t GetLenStatic() const
A Branch for the case of an object.
virtual const std::type_info & GetTypeId() const =0
unsigned long long ULong64_t
void GetBranchNamesImpl(TTree &t, std::set< std::string > &bNamesReg, ColumnNames_t &bNames, std::set< TTree *> &analysedTrees)
static constexpr double s
TObjArray * GetListOfLeaves()
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.
TClassRef is used to implement a permanent reference to a TClass object.
void CheckSnapshot(unsigned int nTemplateParams, unsigned int nColumnNames)
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *tree, TCustomColumnBase *tmpBranch, TDataSource *ds)
Return a string containing the type of the given branch.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
A TFriendElement TF describes a TTree object TF in a file.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Int_t GetEntries() const
Return the number of objects in array (i.e.
virtual bool HasColumn(std::string_view) const =0
Checks if the dataset has a certain column.
A TTree is a list of TBranches.
ColumnNames_t GetBranchNames(TTree &t)
Get all the branches names, including the ones of the friend trees.