40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Woverloaded-virtual"
42#pragma GCC diagnostic ignored "-Wshadow"
46#pragma GCC diagnostic pop
61#include <unordered_map>
62#include <unordered_set>
92 ColumnNames_t fVarNames;
96std::pair<ColumnNames_t, ColumnNames_t>
100 lexertk::generator
tokens;
103 const auto msg =
"Failed to tokenize expression:\n" +
expr +
"\n\nMake sure it is valid C++.";
104 throw std::runtime_error(
msg);
107 std::unordered_set<std::string>
usedCols;
112 const auto kSymbol = lexertk::token::e_symbol;
113 for (
auto i = 0
u; i <
nTokens; ++i) {
163 dot.Substitute(out,
"\\.",
"g");
164 return std::string(std::move(out));
175 replacer.Substitute(out, col.data(),
"g");
200 R
"REGEX(#(?!(ifdef|ifndef|if|else|elif|endif|pragma|define|undef|include|line))([a-zA-Z_][a-zA-Z0-9_]*)(?=(?:[^"]*"[^"]*")*[^"]*$))REGEX");
215 for (
auto i = 0
u; i <
varNames.size(); ++i)
216 varNames[i] =
"var" + std::to_string(i);
224 [](
const std::string &
a,
const std::string &
b) { return a.size() > b.size(); });
287 std::stringstream
ss;
289 for (
auto i = 0
u; i < vars.size(); ++i) {
303 ss.seekp(-2,
ss.cur);
325 const auto funcName =
exprIt->second;
334 "_ret_t = typename ROOT::TypeTraits::CallableTraits<decltype(" +
funcBaseName +
348 const auto dt =
gROOT->GetType((funcName +
"_ret_t").c_str());
350 const auto type =
dt->GetFullTypeName();
365 "RDataFrame::Jit: cannot just-in-time compile a \"" +
actionTypeNameBase +
"\" action using helper type \"" +
367 "\". This typically happens in a custom `Fill` or `Book` invocation where the types of the input columns have "
368 "not been specified as template parameters and the ROOT interpreter has no knowledge of this type of action "
369 "helper. Please add template parameters for the types of the input columns to avoid jitting this action (i.e. "
370 "`df.Fill<float>(..., {\"x\"})`, where `float` is the type of `x`) or declare the action helper type to the "
371 "interpreter, e.g. via gInterpreter->Declare.";
389 [&](
const std::string &
name) {
390 if (name[0] ==
'#') {
391 filteredColumns.emplace_back(name);
399 std::string
msg =
"Column name(s) {";
402 msg[
msg.size() - 2] =
'}';
403 msg +=
"will be ignored. Please go through a valid Alias to " +
action +
" an array size column";
404 throw std::runtime_error(
msg);
410std::string ResolveAlias(
const std::string &col,
const std::map<std::string, std::string> &
aliasMap)
417 if (col.size() > 1 && col[0] ==
'#')
418 return "R_rdf_sizeof_" + col.substr(1);
432 auto isALetter = [](
char c) {
return (
c >=
'A' &&
c <=
'Z') || (
c >=
'a' &&
c <=
'z'); };
438 auto isANumber = [](
char c) {
return c >=
'0' &&
c <=
'9'; };
440 for (
const char c : var)
445 const auto objName =
where ==
"Define" ?
"column" :
"variation";
446 const auto error =
"RDataFrame::" +
where +
": cannot define " +
objName +
" \"" + std::string(var) +
447 "\". Not a valid C++ variable name.";
448 throw std::runtime_error(error);
488 text =
": there is no column available to match.";
492 throw std::runtime_error(
text);
505 "\", already exists in this branch of the computation graph.";
507 error =
"A column with that name has already been Define'd. Use Redefine to force redefinition.";
513 "A branch with that name is already present in the input TTree/TChain. Use Redefine to force redefinition.";
516 "A column with that name is already present in the input data source. Use Redefine to force redefinition.";
518 if (!error.empty()) {
519 error =
"RDataFrame::" +
where +
": cannot define column \"" + std::string(
definedColView) +
"\". " + error;
520 throw std::runtime_error(error);
532 "\", already exists. Aliases cannot be Redefined or Varied.";
545 error =
"No column with that name was found in the dataset. Use Define to create a new column.";
548 if (!error.empty()) {
549 if (
where ==
"DefaultValueFor")
550 error =
"RDataFrame::" +
where +
": cannot provide default values for column \"" +
553 error =
"RDataFrame::" +
where +
": cannot redefine or vary column \"" + std::string(
definedColView) +
"\". " +
555 throw std::runtime_error(error);
565 if (
where ==
"Redefine") {
566 const std::string error =
"RDataFrame::" +
where +
": cannot redefine column \"" +
definedCol +
567 "\". The column depends on one or more systematic variations and re-defining varied "
568 "columns is not supported.";
569 throw std::runtime_error(error);
570 }
else if (
where ==
"DefaultValueFor") {
571 const std::string error =
"RDataFrame::" +
where +
": cannot provide a default value for column \"" +
573 "\". The column depends on one or more systematic variations and it should not be "
574 "possible to have missing values in varied columns.";
575 throw std::runtime_error(error);
577 const std::string error =
578 "RDataFrame::" +
where +
": this operation cannot work with columns that depend on systematic variations.";
579 throw std::runtime_error(error);
587 std::string
err_msg =
"The number of template parameters specified is ";
591 err_msg +=
" columns have been specified.";
592 throw std::runtime_error(
err_msg);
603 throw std::runtime_error(
605 " required but none were provided and the default list has size " + std::to_string(
defaultNames.
size()));
612 " required but " + std::to_string(names.size()) + (names.size() == 1 ?
" was" :
" were") +
614 for (
const auto &
name : names)
617 throw std::runtime_error(
msg);
642std::vector<std::string> GetFilterNames(
const std::shared_ptr<RLoopManager> &
loopManager)
653 if (std::string_view::npos !=
lastSlash) {
669std::shared_ptr<RDFDetail::RJittedFilter>
673 const auto &
dsColumns =
ds ?
ds->GetColumnNames() : ColumnNames_t{};
681 std::runtime_error(
"Filter: the following expression does not evaluate to bool:\n" + std::string(expression));
688 const auto jittedFilter = std::make_shared<RDFDetail::RJittedFilter>(
689 (*prevNodeOnHeap)->GetLoopManagerUnchecked(),
name,
695 filterInvocation <<
"ROOT::Internal::RDF::JitFilterHelper(" << funcName <<
", new const char*["
706 <<
"reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedFilter>*>("
708 <<
"reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>(" <<
prevNodeAddr <<
"),"
709 <<
"reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" <<
definesOnHeapAddr <<
")"
719std::shared_ptr<RJittedDefine>
BookDefineJit(std::string_view
name, std::string_view expression, RLoopManager &
lm,
724 auto *
const lm.GetTree();
725 const auto &
dsColumns =
ds ?
ds->GetColumnNames() : ColumnNames_t{};
738 defineInvocation <<
"ROOT::Internal::RDF::JitDefineHelper<ROOT::Internal::RDF::DefineTypes::RDefineTag>(" << funcName
739 <<
", new const char*[" <<
parsedExpr.fUsedCols.size() <<
"]{";
750 <<
"\", reinterpret_cast<ROOT::Detail::RDF::RLoopManager*>(" <<
PrettyPrintAddr(&
lm)
751 <<
"), reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedDefine>*>("
753 <<
"), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" <<
definesAddr
754 <<
"), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
766 const auto funcName =
DeclareFunction(std::string(expression), {
"rdfslot_",
"rdfsampleinfo_"},
767 {
"unsigned int",
"const ROOT::RDF::RSampleInfo"});
775 defineInvocation <<
"ROOT::Internal::RDF::JitDefineHelper<ROOT::Internal::RDF::DefineTypes::RDefinePerSampleTag>("
776 << funcName <<
", nullptr, 0, ";
782 <<
"), reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedDefine>*>("
784 <<
"), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" <<
definesAddr
785 <<
"), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
793std::shared_ptr<RJittedVariation>
795 const std::vector<std::string> &
variationTags, std::string_view expression, RLoopManager &
lm,
799 auto *
const lm.GetTree();
800 const auto &
dsColumns =
ds ?
ds->GetColumnNames() : ColumnNames_t{};
808 if (
type.rfind(
"ROOT::VecOps::RVec", 0) != 0) {
812 throw std::runtime_error(
813 "Jitted Vary expressions must return an RVec object. The following expression returns a " +
type +
830 << funcName <<
", new const char*[" <<
parsedExpr.fUsedCols.size() <<
"]{";
848 <<
"\", reinterpret_cast<ROOT::Detail::RDF::RLoopManager*>(" <<
PrettyPrintAddr(&
lm)
849 <<
"), reinterpret_cast<std::weak_ptr<ROOT::Internal::RDF::RJittedVariation>*>("
851 <<
"), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" <<
colRegisterAddr
852 <<
"), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
861std::string
JitBuildAction(
const ColumnNames_t &
cols, std::shared_ptr<RDFDetail::RNodeBase> *prevNode,
869 std::string
exceptionText =
"An error occurred while inferring the action type of the operation.";
893 createAction_str <<
">(reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
895 for (
auto i = 0
u; i <
cols.size(); ++i) {
902 <<
"), reinterpret_cast<std::weak_ptr<ROOT::Internal::RDF::RJittedAction>*>("
904 <<
"), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" <<
definesAddr <<
"));";
910 for (
const auto &s :
strings) {
917std::shared_ptr<RNodeBase>
UpcastNode(std::shared_ptr<RNodeBase> ptr)
927ColumnNames_t GetValidatedColumnNames(RLoopManager &
lm,
const unsigned int nColumns,
const ColumnNames_t &
columns,
938 ds ?
ds->GetColumnNames() : ColumnNames_t{});
946 const auto &
colsToIgnore =
lm.GetSuppressErrorsForMissingBranches();
951 std::string
errMsg = std::string(
"Unknown column") + (
unknownColumns.size() > 1 ?
"s: " :
": ");
955 throw std::runtime_error(
errMsg);
963 TTree *tree, RDataSource *
ds,
const std::string &context,
969 if (
colType.rfind(
"CLING_UNKNOWN_TYPE", 0) == 0) {
971 "The type of custom column \"" +
c +
"\" (" +
colType.substr(19) +
972 ") is not known to the interpreter, but a just-in-time-compiled " + context +
973 " call requires this column. Make sure to create and load ROOT dictionaries for this column's class.";
974 throw std::runtime_error(
msg);
999 for (
auto &col :
cols) {
1001 const auto msg =
"Error: column \"" + col +
1002 "\" was passed to Snapshot twice. This is not supported: only one of the columns would be "
1003 "readable with RDataFrame.";
1004 throw std::logic_error(
msg);
1011std::pair<std::vector<std::string>, std::vector<std::string>>
1025 for (std::size_t i = 0
u; i <
nCols; ++i) {
1030 auto *colName.c_str());
1034 auto *
leaves =
b->GetListOfLeaves();
1057 [&
uniqueCols](
const std::string &
colName) { return !uniqueCols.insert(colName).second; }),
1066 [](
const std::string &
colName) { return colName.find(
'.') == std::string::npos; });
1070 if (colName.find(
'.') == std::string::npos)
1072 const auto parentFieldName = colName.substr(0, colName.find_first_of(
'.'));
1073 return std::find(parentFields.cbegin(), parentFields.cend(), parentFieldName) !=
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char text
R__EXTERN TVirtualMutex * gROOTMutex
#define R__LOCKGUARD(mutex)
A binder for user-defined columns, variations and aliases.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
const_iterator begin() const
const_iterator end() const
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.
A TTree represents a columnar dataset.
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)
std::string PrettyPrintAddr(const void *const addr)
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *, RDataSource *, RDefineBase *, bool vector2RVec=true)
Return a string containing the type of the given branch.
std::vector< T > Union(const std::vector< T > &v1, const std::vector< T > &v2)
Return a vector with all elements of v1 and v2 and duplicates removed.
bool IsInternalColumn(std::string_view colName)
Whether custom column with name colName is an "internal" column such as rdfentry_ or rdfslot_.
void InterpreterDeclare(const std::string &code)
Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors.
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...
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
BVH_ALWAYS_INLINE T dot(const Vec< T, N > &a, const Vec< T, N > &b)