Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RDFInterfaceUtils.cxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 02/2018
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include <ROOT/RDataSource.hxx>
12#include <ROOT/RTTreeDS.hxx>
15#include <ROOT/RDF/RDisplay.hxx>
22#include <ROOT/RDF/Utils.hxx>
23#include <string_view>
24#include <TBranch.h>
25#include <TClass.h>
26#include <TClassEdit.h>
27#include <TDataType.h>
28#include <TError.h>
29#include <TLeaf.h>
30#include <TObjArray.h>
31#include <TPRegexp.h>
32#include <TROOT.h>
33#include <TString.h>
34#include <TTree.h>
35#include <TVirtualMutex.h>
36
37// pragma to disable warnings on Rcpp which have
38// so many noise compiling
39#if defined(__GNUC__)
40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Woverloaded-virtual"
42#pragma GCC diagnostic ignored "-Wshadow"
43#endif
44#include "lexertk.hpp"
45#if defined(__GNUC__)
46#pragma GCC diagnostic pop
47#endif
48
49#include <algorithm>
50#include <cassert>
51#include <cstdlib> // for size_t
52#include <iterator> // for back_insert_iterator
53#include <map>
54#include <memory>
55#include <set>
56#include <sstream>
57#include <stdexcept>
58#include <string>
59#include <type_traits> // for remove_reference<>::type
60#include <typeinfo>
61#include <unordered_map>
62#include <unordered_set>
63#include <utility> // for pair
64#include <vector>
65
66namespace ROOT {
67namespace Detail {
68namespace RDF {
69class RDefineBase;
70} // namespace RDF
71namespace Internal {
72namespace RDF {
73class RJittedAction;
74}
75} // namespace Internal
76} // namespace Detail
77
78} // namespace ROOT
79
80namespace {
83
84/// A string expression such as those passed to Filter and Define, digested to a standardized form
85struct ParsedExpression {
86 /// The string expression with the dummy variable names in fVarNames in place of the original column names
87 std::string fExpr;
88 /// The list of valid column names that were used in the original string expression.
89 /// Duplicates are removed and column aliases (created with Alias calls) are resolved.
90 ColumnNames_t fUsedCols;
91 /// The list of variable names used in fExpr, with same ordering and size as fUsedCols
92 ColumnNames_t fVarNames;
93};
94
95/// Look at expression `expr` and return a pair of (column names used, aliases used)
96std::pair<ColumnNames_t, ColumnNames_t>
97FindUsedColsAndAliases(const std::string &expr, const ColumnNames_t &treeBranchNames,
99{
100 lexertk::generator tokens;
101 const auto tokensOk = tokens.process(expr);
102 if (!tokensOk) {
103 const auto msg = "Failed to tokenize expression:\n" + expr + "\n\nMake sure it is valid C++.";
104 throw std::runtime_error(msg);
105 }
106
107 std::unordered_set<std::string> usedCols;
108 std::unordered_set<std::string> usedAliases;
109
110 // iterate over tokens in expression and fill usedCols and usedAliases
111 const auto nTokens = tokens.size();
112 const auto kSymbol = lexertk::token::e_symbol;
113 for (auto i = 0u; i < nTokens; ++i) {
114 const auto &tok = tokens[i];
115 // lexertk classifies '&' as e_symbol for some reason
116 if (tok.type != kSymbol || tok.value == "&" || tok.value == "|") {
117 // token is not a potential variable name, skip it
118 continue;
119 }
120
121 ColumnNames_t potentialColNames({tok.value});
122
123 // if token is the start of a dot chain (a.b.c...), a.b, a.b.c etc. are also potential column names
124 auto dotChainKeepsGoing = [&](unsigned int _i) {
125 return _i + 2 <= nTokens && tokens[_i + 1].value == "." && tokens[_i + 2].type == kSymbol;
126 };
127 while (dotChainKeepsGoing(i)) {
128 potentialColNames.emplace_back(potentialColNames.back() + "." + tokens[i + 2].value);
129 i += 2; // consume the tokens we looked at
130 }
131
132 // in an expression such as `a.b`, if `a` is a column alias add it to `usedAliases` and
133 // replace the alias with the real column name in `potentialColNames`.
134 const auto maybeAnAlias = potentialColNames[0]; // intentionally a copy as we'll modify potentialColNames later
135 const auto &resolvedAlias = colRegister.ResolveAlias(maybeAnAlias);
136 if (resolvedAlias != maybeAnAlias) { // this is an alias
138 for (auto &s : potentialColNames)
139 s.replace(0, maybeAnAlias.size(), resolvedAlias);
140 }
141
142 // find the longest potential column name that is an actual column name
143 // (potential columns are sorted by length, so we search from the end to find the longest)
144 auto isRDFColumn = [&](const std::string &col) {
145 if (colRegister.IsDefineOrAlias(col) || IsStrInVec(col, treeBranchNames) ||
146 IsStrInVec(col, dataSourceColNames))
147 return true;
148 return false;
149 };
150 const auto longestRDFColMatch = std::find_if(potentialColNames.crbegin(), potentialColNames.crend(), isRDFColumn);
153 }
154
155 return {{usedCols.begin(), usedCols.end()}, {usedAliases.begin(), usedAliases.end()}};
156}
157
158/// Substitute each '.' in a string with '\.'
159std::string EscapeDots(const std::string &s)
160{
161 out(s);
162 TPRegexp dot("\.");
163 dot.Substitute(out, "\.", "g");
164 return std::string(std::move(out));
165}
166
167TString ResolveAliases(const TString &expr, const ColumnNames_t &usedAliases,
169{
170 expr);
171
172 for (const auto &alias : usedAliases) {
173 const auto &col = colRegister.ResolveAlias(alias);
174 TPRegexp replacer("\b" + EscapeDots(alias) + "\b");
175 replacer.Substitute(out, col.data(), "g");
176 }
177
178 return out;
179}
180
181ParsedExpression ParseRDFExpression(std::string_view expr, const ColumnNames_t &treeBranchNames,
183 const ColumnNames_t &dataSourceColNames)
184{
185 // transform `#var` into `R_rdf_sizeof_var`
187 // match #varname at beginning of the sentence or after not-a-word, but exclude preprocessor directives like #ifdef
189 "(^|\W)#(?!(ifdef|ifndef|if|else|elif|endif|pragma|define|undef|include|line))([a-zA-Z_][a-zA-Z0-9_]*)");
190 colSizeReplacer.Substitute(preProcessedExpr, "$1R_rdf_sizeof_$3", "g");
191
192 ColumnNames_t usedCols;
193 ColumnNames_t usedAliases;
194 std::tie(usedCols, usedAliases) =
196
198
199 // when we are done, exprWithVars willl be the same as preProcessedExpr but column names will be substituted with
200 // the dummy variable names in varNames
202
203 ColumnNames_t varNames(usedCols.size());
204 for (auto i = 0u; i < varNames.size(); ++i)
205 varNames[i] = "var" + std::to_string(i);
206
207 // sort the vector usedColsAndAliases by decreasing length of its elements,
208 // so in case of friends we guarantee we never substitute a column name with another column containing it
209 // ex. without sorting when passing "x" and "fr.x", the replacer would output "var0" and "fr.var0",
210 // because it has already substituted "x", hence the "x" in "fr.x" would be recognized as "var0",
211 // whereas the desired behaviour is handling them as "var0" and "var1"
212 std::sort(usedCols.begin(), usedCols.end(),
213 [](const std::string &a, const std::string &b) { return a.size() > b.size(); });
214 for (const auto &col : usedCols) {
215 const auto varIdx = std::distance(usedCols.begin(), std::find(usedCols.begin(), usedCols.end(), col));
216 TPRegexp replacer("\b" + EscapeDots(col) + "\b");
217 replacer.Substitute(exprWithVars, varNames[varIdx], "g");
218 }
219
220 return ParsedExpression{std::string(std::move(exprWithVars)), std::move(usedCols), std::move(varNames)};
221}
222
223/// Return the static global map of Filter/Define functions that have been jitted.
224/// It's used to check whether a given expression has already been jitted, and
225/// to look up its associated variable name if it is.
226/// Keys in the map are the body of the expression, values are the name of the
227/// jitted variable that corresponds to that expression. For example, for:
228/// auto f1(){ return 42; }
229/// key would be "(){ return 42; }" and value would be "f1".
230std::unordered_map<std::string, std::string> &GetJittedExprs() {
231 static std::unordered_map<std::string, std::string> jittedExpressions;
232 return jittedExpressions;
233}
234
235std::string
236BuildFunctionString(const std::string &expr, const ColumnNames_t &vars, const ColumnNames_t &varTypes)
237{
238 assert(vars.size() == varTypes.size());
239
240 TPRegexp re(R"(\breturn\b)");
241 const bool hasReturnStmt = re.MatchB(expr);
242
243 static const std::vector<std::string> fundamentalTypes = {
244 "int",
245 "signed",
246 "signed int",
247 "Int_t",
248 "unsigned",
249 "unsigned int",
250 "UInt_t",
251 "double",
252 "Double_t",
253 "float",
254 "Float_t",
255 "char",
256 "Char_t",
257 "unsigned char",
258 "UChar_t",
259 "bool",
260 "Bool_t",
261 "short",
262 "short int",
263 "Short_t",
264 "long",
265 "long int",
266 "long long int",
267 "Long64_t",
268 "unsigned long",
269 "unsigned long int",
270 "ULong64_t",
271 "std::size_t",
272 "size_t",
273 "Ssiz_t"
274 };
275
276 std::stringstream ss;
277 ss << "(";
278 for (auto i = 0u; i < vars.size(); ++i) {
279 std::string fullType;
280 const auto &type = varTypes[i];
282 // pass it by const value to help detect common mistakes such as if(x = 3)
283 fullType = "const " + type + " ";
284 } else {
285 // We pass by reference to avoid expensive copies
286 // It can't be const reference in general, as users might want/need to call non-const methods on the values
287 fullType = type + "& ";
288 }
289 ss << fullType << vars[i] << ", ";
290 }
291 if (!vars.empty())
292 ss.seekp(-2, ss.cur);
293
294 if (hasReturnStmt)
295 ss << "){";
296 else
297 ss << "){return ";
298 ss << expr << "\n;}";
299
300 return ss.str();
301}
302
303/// Declare a function to the interpreter in namespace R_rdf, return the name of the jitted function.
304/// If the function is already in GetJittedExprs, return the name for the function that has already been jitted.
305std::string DeclareFunction(const std::string &expr, const ColumnNames_t &vars, const ColumnNames_t &varTypes)
306{
308
309 const auto funcCode = BuildFunctionString(expr, vars, varTypes);
310 auto &exprMap = GetJittedExprs();
311 const auto exprIt = exprMap.find(funcCode);
312 if (exprIt != exprMap.end()) {
313 // expression already there
314 const auto funcName = exprIt->second;
315 return funcName;
316 }
317
318 // new expression
319 const auto funcBaseName = "func" + std::to_string(exprMap.size());
320 const auto funcFullName = "R_rdf::" + funcBaseName;
321
322 const auto toDeclare = "namespace R_rdf {\nauto " + funcBaseName + funcCode + "\nusing " + funcBaseName +
323 "_ret_t = typename ROOT::TypeTraits::CallableTraits<decltype(" + funcBaseName +
324 ")>::ret_type;\n}";
326
327 // InterpreterDeclare could throw. If it doesn't, mark the function as already jitted
328 exprMap.insert({funcCode, funcFullName});
329
330 return funcFullName;
331}
332
333/// Each jitted function comes with a func_ret_t type alias for its return type.
334/// Resolve that alias and return the true type as string.
335std::string RetTypeOfFunc(const std::string &funcName)
336{
337 const auto dt = gROOT->GetType((funcName + "_ret_t").c_str());
338 R__ASSERT(dt != nullptr);
339 const auto type = dt->GetFullTypeName();
340 return type;
341}
342
343[[noreturn]] void
344ThrowJitBuildActionHelperTypeError(const std::string &actionTypeNameBase, const std::type_info &helperArgType)
345{
346 int err = 0;
348 std::string actionHelperTypeName = cname;
349 delete[] cname;
350 if (err != 0)
352
353 std::string exceptionText =
354 "RDataFrame::Jit: cannot just-in-time compile a \"" + actionTypeNameBase + "\" action using helper type \"" +
356 "\". This typically happens in a custom `Fill` or `Book` invocation where the types of the input columns have "
357 "not been specified as template parameters and the ROOT interpreter has no knowledge of this type of action "
358 "helper. Please add template parameters for the types of the input columns to avoid jitting this action (i.e. "
359 "`df.Fill<float>(..., {\"x\"})`, where `float` is the type of `x`) or declare the action helper type to the "
360 "interpreter, e.g. via gInterpreter->Declare.";
361
362 throw std::runtime_error(exceptionText);
363}
364
365} // anonymous namespace
366
367namespace ROOT {
368namespace Internal {
369namespace RDF {
370
371/// Take a list of column names, return that list with entries starting by '#' filtered out.
372/// The function throws when filtering out a column this way.
374{
377 std::copy_if(columnNames.begin(), columnNames.end(), std::back_inserter(columnListWithoutSizeColumns),
378 [&](const std::string &name) {
379 if (name[0] == '#') {
380 filteredColumns.emplace_back(name);
381 return false;
382 } else {
383 return true;
384 }
385 });
386
387 if (!filteredColumns.empty()) {
388 std::string msg = "Column name(s) {";
389 for (auto &c : filteredColumns)
390 msg += c + ", ";
391 msg[msg.size() - 2] = '}';
392 msg += "will be ignored. Please go through a valid Alias to " + action + " an array size column";
393 throw std::runtime_error(msg);
394 }
395
397}
398
399std::string ResolveAlias(const std::string &col, const std::map<std::string, std::string> &aliasMap)
400{
401 const auto it = aliasMap.find(col);
402 if (it != aliasMap.end())
403 return it->second;
404
405 // #var is an alias for R_rdf_sizeof_var
406 if (col.size() > 1 && col[0] == '#')
407 return "R_rdf_sizeof_" + col.substr(1);
408
409 return col;
410}
411
412void CheckValidCppVarName(std::string_view var, const std::string &where)
413{
414 bool isValid = true;
415
416 if (var.empty())
417 isValid = false;
418 const char firstChar = var[0];
419
420 // first character must be either a letter or an underscore
421 auto isALetter = [](char c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); };
422 const bool isValidFirstChar = firstChar == '_' || isALetter(firstChar);
423 if (!isValidFirstChar)
424 isValid = false;
425
426 // all characters must be either a letter, an underscore or a number
427 auto isANumber = [](char c) { return c >= '0' && c <= '9'; };
428 auto isValidTok = [&isALetter, &isANumber](char c) { return c == '_' || isALetter(c) || isANumber(c); };
429 for (const char c : var)
430 if (!isValidTok(c))
431 isValid = false;
432
433 if (!isValid) {
434 const auto objName = where == "Define" ? "column" : "variation";
435 const auto error = "RDataFrame::" + where + ": cannot define " + objName + " \"" + std::string(var) +
436 "\". Not a valid C++ variable name.";
437 throw std::runtime_error(error);
438 }
439}
440
441std::string DemangleTypeIdName(const std::type_info &typeInfo)
442{
443 int dummy(0);
445 std::string tname(tn);
446 free(tn);
447 return tname;
448}
449
450ColumnNames_t
451ConvertRegexToColumns(const ColumnNames_t &colNames, std::string_view columnNameRegexp, std::string_view callerName)
452{
453 const auto theRegexSize = columnNameRegexp.size();
454 std::string theRegex(columnNameRegexp);
455
456 const auto isEmptyRegex = 0 == theRegexSize;
457 // This is to avoid cases where branches called b1, b2, b3 are all matched by expression "b"
458 if (theRegexSize > 0 && theRegex[0] != '^')
459 theRegex = "^" + theRegex;
460 if (theRegexSize > 0 && theRegex[theRegexSize - 1] != '$')
461 theRegex = theRegex + "$";
462
464
465 // Since we support gcc48 and it does not provide in its stl std::regex,
466 // we need to use TPRegexp
467 TPRegexp regexp(theRegex);
468 for (auto &&colName : colNames) {
469 if ((isEmptyRegex || regexp.MatchB(colName.c_str())) && !IsInternalColumn(colName)) {
470 selectedColumns.emplace_back(colName);
471 }
472 }
473
474 if (selectedColumns.empty()) {
475 std::string text(callerName);
476 if (columnNameRegexp.empty()) {
477 text = ": there is no column available to match.";
478 } else {
479 text = ": regex \"" + std::string(columnNameRegexp) + "\" did not match any column.";
480 }
481 throw std::runtime_error(text);
482 }
483 return selectedColumns;
484}
485
486/// Throw if column `definedColView` is already there.
487void CheckForRedefinition(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister,
489{
490
491 std::string error{};
492 if (colRegister.IsAlias(definedColView))
493 error = "An alias with that name, pointing to column \"" + std::string(colRegister.ResolveAlias(definedColView)) +
494 "\", already exists in this branch of the computation graph.";
495 else if (colRegister.IsDefineOrAlias(definedColView))
496 error = "A column with that name has already been Define'd. Use Redefine to force redefinition.";
497 // else, check if definedColView is in the list of tree branches. This is a bit better than interrogating the TTree
498 // directly because correct usage of GetBranch, FindBranch, GetLeaf and FindLeaf can be tricky; so let's assume we
499 // got it right when we collected the list of available branches.
500 else if (std::find(treeColumns.begin(), treeColumns.end(), definedColView) != treeColumns.end())
501 error =
502 "A branch with that name is already present in the input TTree/TChain. Use Redefine to force redefinition.";
504 error =
505 "A column with that name is already present in the input data source. Use Redefine to force redefinition.";
506
507 if (!error.empty()) {
508 error = "RDataFrame::" + where + ": cannot define column \"" + std::string(definedColView) + "\". " + error;
509 throw std::runtime_error(error);
510 }
511}
512
513/// Throw if column `definedColView` is _not_ already there.
514void CheckForDefinition(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister,
516{
517 std::string error{};
518
519 if (colRegister.IsAlias(definedColView)) {
520 error = "An alias with that name, pointing to column \"" + std::string(colRegister.ResolveAlias(definedColView)) +
521 "\", already exists. Aliases cannot be Redefined or Varied.";
522 }
523
524 if (error.empty()) {
525 const bool isAlreadyDefined = colRegister.IsDefineOrAlias(definedColView);
526 // check if definedCol is in the list of tree branches. This is a bit better than interrogating the TTree
527 // directly because correct usage of GetBranch, FindBranch, GetLeaf and FindLeaf can be tricky; so let's assume we
528 // got it right when we collected the list of available branches.
529 const bool isABranch = std::find(treeColumns.begin(), treeColumns.end(), definedColView) != treeColumns.end();
530 const bool isADSColumn =
532
534 error = "No column with that name was found in the dataset. Use Define to create a new column.";
535 }
536
537 if (!error.empty()) {
538 if (where == "DefaultValueFor")
539 error = "RDataFrame::" + where + ": cannot provide default values for column \"" +
540 std::string(definedColView) + "\". " + error;
541 else
542 error = "RDataFrame::" + where + ": cannot redefine or vary column \"" + std::string(definedColView) + "\". " +
543 error;
544 throw std::runtime_error(error);
545 }
546}
547
548/// Throw if the column has systematic variations attached.
549void CheckForNoVariations(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister)
550{
551 const std::string definedCol(definedColView);
552 const auto &variationDeps = colRegister.GetVariationDeps(definedCol);
553 if (!variationDeps.empty()) {
554 if (where == "Redefine") {
555 const std::string error = "RDataFrame::" + where + ": cannot redefine column \"" + definedCol +
556 "\". The column depends on one or more systematic variations and re-defining varied "
557 "columns is not supported.";
558 throw std::runtime_error(error);
559 } else if (where == "DefaultValueFor") {
560 const std::string error = "RDataFrame::" + where + ": cannot provide a default value for column \"" +
561 definedCol +
562 "\". The column depends on one or more systematic variations and it should not be "
563 "possible to have missing values in varied columns.";
564 throw std::runtime_error(error);
565 } else {
566 const std::string error =
567 "RDataFrame::" + where + ": this operation cannot work with columns that depend on systematic variations.";
568 throw std::runtime_error(error);
569 }
570 }
571}
572
573void CheckTypesAndPars(unsigned int nTemplateParams, unsigned int nColumnNames)
574{
576 std::string err_msg = "The number of template parameters specified is ";
577 err_msg += std::to_string(nTemplateParams);
578 err_msg += " while ";
579 err_msg += std::to_string(nColumnNames);
580 err_msg += " columns have been specified.";
581 throw std::runtime_error(err_msg);
582 }
583}
584
585/// Choose between local column names or default column names, throw in case of errors.
586const ColumnNames_t
588{
589 if (names.empty()) {
590 // use default column names
591 if (defaultNames.size() < nRequiredNames)
592 throw std::runtime_error(
593 std::to_string(nRequiredNames) + " column name" + (nRequiredNames == 1 ? " is" : "s are") +
594 " required but none were provided and the default list has size " + std::to_string(defaultNames.size()));
595 // return first nRequiredNames default column names
597 } else {
598 // use column names provided by the user to this particular transformation/action
599 if (names.size() != nRequiredNames) {
600 auto msg = std::to_string(nRequiredNames) + " column name" + (nRequiredNames == 1 ? " is" : "s are") +
601 " required but " + std::to_string(names.size()) + (names.size() == 1 ? " was" : " were") +
602 " provided:";
603 for (const auto &name : names)
604 msg += " \"" + name + "\",";
605 msg.back() = '.';
606 throw std::runtime_error(msg);
607 }
608 return names;
609 }
610}
611
614{
616 for (auto &column : requiredCols) {
617 const auto isBranch = std::find(datasetColumns.begin(), datasetColumns.end(), column) != datasetColumns.end();
618 if (isBranch)
619 continue;
620 if (definedCols.IsDefineOrAlias(column))
621 continue;
622 const auto isDataSourceColumn =
625 continue;
626 unknownColumns.emplace_back(column);
627 }
628 return unknownColumns;
629}
630
631std::vector<std::string> GetFilterNames(const std::shared_ptr<RLoopManager> &loopManager)
632{
633 return loopManager->GetFiltersNames();
634}
635
637{
638 // split name into directory and treename if needed
639 std::string_view dirName = "";
640 std::string_view treeName = fullTreeName;
641 const auto lastSlash = fullTreeName.rfind('/');
642 if (std::string_view::npos != lastSlash) {
643 dirName = treeName.substr(0, lastSlash);
644 treeName = treeName.substr(lastSlash + 1, treeName.size());
645 }
646 return {std::string(treeName), std::string(dirName)};
647}
648
649std::string PrettyPrintAddr(const void *const addr)
650{
651 std::stringstream s;
652 // Windows-friendly
654 return s.str();
655}
656
657/// Book the jitting of a Filter call
658std::shared_ptr<RDFDetail::RJittedFilter>
659BookFilterJit(std::shared_ptr<RDFDetail::RNodeBase> *prevNodeOnHeap, std::string_view name, std::string_view expression,
661{
662 const auto &dsColumns = ds ? ds->GetColumnNames() : ColumnNames_t{};
663
664 const auto parsedExpr = ParseRDFExpression(expression, branches, colRegister, dsColumns);
665 const auto exprVarTypes =
666 GetValidatedArgTypes(parsedExpr.fUsedCols, colRegister, tree, ds, "Filter", /*vector2RVec=*/true);
667 const auto funcName = DeclareFunction(parsedExpr.fExpr, parsedExpr.fVarNames, exprVarTypes);
668 const auto type = RetTypeOfFunc(funcName);
669 if (type != "bool")
670 std::runtime_error("Filter: the following expression does not evaluate to bool:\n" + std::string(expression));
671
672 // definesOnHeap is deleted by the jitted call to JitFilterHelper
676
677 const auto jittedFilter = std::make_shared<RDFDetail::RJittedFilter>(
678 (*prevNodeOnHeap)->GetLoopManagerUnchecked(), name,
679 Union(colRegister.GetVariationDeps(parsedExpr.fUsedCols), (*prevNodeOnHeap)->GetVariations()));
680
681 // Produce code snippet that creates the filter and registers it with the corresponding RJittedFilter
682 // Windows requires std::hex << std::showbase << (size_t)pointer to produce notation "0x1234"
683 std::stringstream filterInvocation;
684 filterInvocation << "ROOT::Internal::RDF::JitFilterHelper(" << funcName << ", new const char*["
685 << parsedExpr.fUsedCols.size() << "]{";
686 for (const auto &col : parsedExpr.fUsedCols)
687 filterInvocation << "\"" << col << "\", ";
688 if (!parsedExpr.fUsedCols.empty())
689 filterInvocation.seekp(-2, filterInvocation.cur); // remove the last ",
690 // lifetime of pointees:
691 // - jittedFilter: heap-allocated weak_ptr to the actual jittedFilter that will be deleted by JitFilterHelper
692 // - prevNodeOnHeap: heap-allocated shared_ptr to the actual previous node that will be deleted by JitFilterHelper
693 // - definesOnHeap: heap-allocated, will be deleted by JitFilterHelper
694 filterInvocation << "}, " << parsedExpr.fUsedCols.size() << ", \"" << name << "\", "
695 << "reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedFilter>*>("
697 << "reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>(" << prevNodeAddr << "),"
698 << "reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" << definesOnHeapAddr << ")"
699 << ");\n";
700
701 auto lm = jittedFilter->GetLoopManagerUnchecked();
702 lm->ToJitExec(filterInvocation.str());
703
704 return jittedFilter;
705}
706
707/// Book the jitting of a Define call
708std::shared_ptr<RJittedDefine> BookDefineJit(std::string_view name, std::string_view expression, RLoopManager &lm,
710 const ColumnNames_t &branches,
711 std::shared_ptr<RNodeBase> *upcastNodeOnHeap)
712{
713 auto *const tree = lm.GetTree();
714 const auto &dsColumns = ds ? ds->GetColumnNames() : ColumnNames_t{};
715
716 const auto parsedExpr = ParseRDFExpression(expression, branches, colRegister, dsColumns);
717 const auto exprVarTypes =
718 GetValidatedArgTypes(parsedExpr.fUsedCols, colRegister, tree, ds, "Define", /*vector2RVec=*/true);
719 const auto funcName = DeclareFunction(parsedExpr.fExpr, parsedExpr.fVarNames, exprVarTypes);
720 const auto type = RetTypeOfFunc(funcName);
721
724 auto jittedDefine = std::make_shared<RDFDetail::RJittedDefine>(name, type, lm, colRegister, parsedExpr.fUsedCols);
725
726 std::stringstream defineInvocation;
727 defineInvocation << "ROOT::Internal::RDF::JitDefineHelper<ROOT::Internal::RDF::DefineTypes::RDefineTag>(" << funcName
728 << ", new const char*[" << parsedExpr.fUsedCols.size() << "]{";
729 for (const auto &col : parsedExpr.fUsedCols) {
730 defineInvocation << "\"" << col << "\", ";
731 }
732 if (!parsedExpr.fUsedCols.empty())
733 defineInvocation.seekp(-2, defineInvocation.cur); // remove the last ",
734 // lifetime of pointees:
735 // - lm is the loop manager, and if that goes out of scope jitting does not happen at all (i.e. will always be valid)
736 // - jittedDefine: heap-allocated weak_ptr that will be deleted by JitDefineHelper after usage
737 // - definesAddr: heap-allocated, will be deleted by JitDefineHelper after usage
738 defineInvocation << "}, " << parsedExpr.fUsedCols.size() << ", \"" << name
739 << "\", reinterpret_cast<ROOT::Detail::RDF::RLoopManager*>(" << PrettyPrintAddr(&lm)
740 << "), reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedDefine>*>("
742 << "), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" << definesAddr
743 << "), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
744 << PrettyPrintAddr(upcastNodeOnHeap) << "));\n";
745
746 lm.ToJitExec(defineInvocation.str());
747 return jittedDefine;
748}
749
750/// Book the jitting of a DefinePerSample call
751std::shared_ptr<RJittedDefine> BookDefinePerSampleJit(std::string_view name, std::string_view expression,
753 std::shared_ptr<RNodeBase> *upcastNodeOnHeap)
754{
755 const auto funcName = DeclareFunction(std::string(expression), {"rdfslot_", "rdfsampleinfo_"},
756 {"unsigned int", "const ROOT::RDF::RSampleInfo"});
757 const auto retType = RetTypeOfFunc(funcName);
758
761 auto jittedDefine = std::make_shared<RDFDetail::RJittedDefine>(name, retType, lm, colRegister, ColumnNames_t{});
762
763 std::stringstream defineInvocation;
764 defineInvocation << "ROOT::Internal::RDF::JitDefineHelper<ROOT::Internal::RDF::DefineTypes::RDefinePerSampleTag>("
765 << funcName << ", nullptr, 0, ";
766 // lifetime of pointees:
767 // - lm is the loop manager, and if that goes out of scope jitting does not happen at all (i.e. will always be valid)
768 // - jittedDefine: heap-allocated weak_ptr that will be deleted by JitDefineHelper after usage
769 // - definesAddr: heap-allocated, will be deleted by JitDefineHelper after usage
770 defineInvocation << "\"" << name << "\", reinterpret_cast<ROOT::Detail::RDF::RLoopManager*>(" << PrettyPrintAddr(&lm)
771 << "), reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedDefine>*>("
773 << "), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" << definesAddr
774 << "), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
775 << PrettyPrintAddr(upcastNodeOnHeap) << "));\n";
776
777 lm.ToJitExec(defineInvocation.str());
778 return jittedDefine;
779}
780
781/// Book the jitting of a Vary call
782std::shared_ptr<RJittedVariation>
783BookVariationJit(const std::vector<std::string> &colNames, std::string_view variationName,
784 const std::vector<std::string> &variationTags, std::string_view expression, RLoopManager &lm,
786 std::shared_ptr<RNodeBase> *upcastNodeOnHeap, bool isSingleColumn)
787{
788 auto *const tree = lm.GetTree();
789 const auto &dsColumns = ds ? ds->GetColumnNames() : ColumnNames_t{};
790
791 const auto parsedExpr = ParseRDFExpression(expression, branches, colRegister, dsColumns);
792 const auto exprVarTypes =
793 GetValidatedArgTypes(parsedExpr.fUsedCols, colRegister, tree, ds, "Vary", /*vector2RVec=*/true);
794 const auto funcName = DeclareFunction(parsedExpr.fExpr, parsedExpr.fVarNames, exprVarTypes);
795 const auto type = RetTypeOfFunc(funcName);
796
797 if (type.rfind("ROOT::VecOps::RVec", 0) != 0) {
798 // Avoid leak
799 delete upcastNodeOnHeap;
800 upcastNodeOnHeap = nullptr;
801 throw std::runtime_error(
802 "Jitted Vary expressions must return an RVec object. The following expression returns a " + type +
803 " instead:\n" + parsedExpr.fExpr);
804 }
805
808 auto jittedVariation = std::make_shared<RJittedVariation>(colNames, variationName, variationTags, type, colRegister,
809 lm, parsedExpr.fUsedCols);
810
811 // build invocation to JitVariationHelper
812 // arrays of strings are passed as const char** plus size.
813 // lifetime of pointees:
814 // - lm is the loop manager, and if that goes out of scope jitting does not happen at all (i.e. will always be valid)
815 // - jittedVariation: heap-allocated weak_ptr that will be deleted by JitDefineHelper after usage
816 // - definesAddr: heap-allocated, will be deleted by JitDefineHelper after usage
817 std::stringstream varyInvocation;
818 varyInvocation << "ROOT::Internal::RDF::JitVariationHelper<" << (isSingleColumn ? "true" : "false") << ">("
819 << funcName << ", new const char*[" << parsedExpr.fUsedCols.size() << "]{";
820 for (const auto &col : parsedExpr.fUsedCols) {
821 varyInvocation << "\"" << col << "\", ";
822 }
823 if (!parsedExpr.fUsedCols.empty())
824 varyInvocation.seekp(-2, varyInvocation.cur); // remove the last ", "
825 varyInvocation << "}, " << parsedExpr.fUsedCols.size();
826 varyInvocation << ", new const char*[" << colNames.size() << "]{";
827 for (const auto &col : colNames) {
828 varyInvocation << "\"" << col << "\", ";
829 }
830 varyInvocation.seekp(-2, varyInvocation.cur); // remove the last ", "
831 varyInvocation << "}, " << colNames.size() << ", new const char*[" << variationTags.size() << "]{";
832 for (const auto &tag : variationTags) {
833 varyInvocation << "\"" << tag << "\", ";
834 }
835 varyInvocation.seekp(-2, varyInvocation.cur); // remove the last ", "
836 varyInvocation << "}, " << variationTags.size() << ", \"" << variationName
837 << "\", reinterpret_cast<ROOT::Detail::RDF::RLoopManager*>(" << PrettyPrintAddr(&lm)
838 << "), reinterpret_cast<std::weak_ptr<ROOT::Internal::RDF::RJittedVariation>*>("
840 << "), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" << colRegisterAddr
841 << "), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
842 << PrettyPrintAddr(upcastNodeOnHeap) << "));\n";
843
844 lm.ToJitExec(varyInvocation.str());
845 return jittedVariation;
846}
847
848// Jit and call something equivalent to "this->BuildAndBook<ColTypes...>(params...)"
849// (see comments in the body for actual jitted code)
850std::string JitBuildAction(const ColumnNames_t &cols, std::shared_ptr<RDFDetail::RNodeBase> *prevNode,
851 const std::type_info &helperArgType, const std::type_info &at, void *helperArgOnHeap,
852 TTree *tree, const unsigned int nSlots, const RColumnRegister &colRegister, RDataSource *ds,
853 std::weak_ptr<RJittedAction> *jittedActionOnHeap, const bool vector2RVec)
854{
855 // retrieve type of action as a string
857 if (!actionTypeClass) {
858 std::string exceptionText = "An error occurred while inferring the action type of the operation.";
859 throw std::runtime_error(exceptionText);
860 }
861 const std::string actionTypeName = actionTypeClass->GetName();
862 const std::string actionTypeNameBase = actionTypeName.substr(actionTypeName.rfind(':') + 1);
863
864 // retrieve type of result of the action as a string
866 if (helperArgTypeName.empty()) {
868 }
869
870 auto definesCopy = new RColumnRegister(colRegister); // deleted in jitted CallBuildAction
872
873 // Build a call to CallBuildAction with the appropriate argument. When run through the interpreter, this code will
874 // just-in-time create an RAction object and it will assign it to its corresponding RJittedAction.
875 std::stringstream createAction_str;
876 createAction_str << "ROOT::Internal::RDF::CallBuildAction<" << actionTypeName;
878 for (auto &colType : columnTypeNames)
879 createAction_str << ", " << colType;
880 // on Windows, to prefix the hexadecimal value of a pointer with '0x',
881 // one need to write: std::hex << std::showbase << (size_t)pointer
882 createAction_str << ">(reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>("
883 << PrettyPrintAddr(prevNode) << "), new const char*[" << cols.size() << "]{";
884 for (auto i = 0u; i < cols.size(); ++i) {
885 if (i != 0u)
886 createAction_str << ", ";
887 createAction_str << '"' << cols[i] << '"';
888 }
889 createAction_str << "}, " << cols.size() << ", " << nSlots << ", reinterpret_cast<shared_ptr<" << helperArgTypeName
890 << ">*>(" << PrettyPrintAddr(helperArgOnHeap)
891 << "), reinterpret_cast<std::weak_ptr<ROOT::Internal::RDF::RJittedAction>*>("
893 << "), reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(" << definesAddr << "));";
894 return createAction_str.str();
895}
896
897bool AtLeastOneEmptyString(const std::vector<std::string_view> strings)
898{
899 for (const auto &s : strings) {
900 if (s.empty())
901 return true;
902 }
903 return false;
904}
905
906std::shared_ptr<RNodeBase> UpcastNode(std::shared_ptr<RNodeBase> ptr)
907{
908 return ptr;
909}
910
911/// Given the desired number of columns and the user-provided list of columns:
912/// * fallback to using the first nColumns default columns if needed (or throw if nColumns > nDefaultColumns)
913/// * check that selected column names refer to valid branches, custom columns or datasource columns (throw if not)
914/// * replace column names from aliases by the actual column name
915/// Return the list of selected column names.
918{
919 auto selectedColumns = SelectColumns(nColumns, columns, lm.GetDefaultColumnNames());
920
921 for (auto &col : selectedColumns) {
922 col = colRegister.ResolveAlias(col);
923 }
924
925 // Complain if there are still unknown columns at this point
927 ds ? ds->GetColumnNames() : ColumnNames_t{});
928
929 if (!unknownColumns.empty()) {
930 // Some columns are still unknown, we need to understand if the error
931 // should be printed or if the user requested to explicitly disable it.
932 // Look for a possible overlap between the unknown columns and the
933 // columns we should ignore for the purpose of the following exception
934 std::set<std::string> intersection;
935 const auto &colsToIgnore = lm.GetSuppressErrorsForMissingBranches();
936 std::sort(unknownColumns.begin(), unknownColumns.end());
937 std::set_intersection(unknownColumns.cbegin(), unknownColumns.cend(), colsToIgnore.cbegin(), colsToIgnore.cend(),
938 std::inserter(intersection, intersection.begin()));
939 if (intersection.empty()) {
940 std::string errMsg = std::string("Unknown column") + (unknownColumns.size() > 1 ? "s: " : ": ");
941 for (auto &unknownColumn : unknownColumns)
942 errMsg += '"' + unknownColumn + "\", ";
943 errMsg.resize(errMsg.size() - 2); // remove last ", "
944 throw std::runtime_error(errMsg);
945 }
946 }
947
948 return selectedColumns;
949}
950
952 TTree *tree, RDataSource *ds, const std::string &context,
953 bool vector2RVec)
954{
955 auto toCheckedArgType = [&](const std::string &c) {
956 RDFDetail::RDefineBase *define = colRegister.GetDefine(c);
957 const auto colType = ColumnName2ColumnTypeName(c, tree, ds, define, vector2RVec);
958 if (colType.rfind("CLING_UNKNOWN_TYPE", 0) == 0) { // the interpreter does not know this type
959 const auto msg =
960 "The type of custom column \"" + c + "\" (" + colType.substr(19) +
961 ") is not known to the interpreter, but a just-in-time-compiled " + context +
962 " call requires this column. Make sure to create and load ROOT dictionaries for this column's class.";
963 throw std::runtime_error(msg);
964 }
965 return colType;
966 };
967 std::vector<std::string> colTypes;
968 colTypes.reserve(colNames.size());
969 std::transform(colNames.begin(), colNames.end(), std::back_inserter(colTypes), toCheckedArgType);
970 return colTypes;
971}
972
973/// Return a bitset each element of which indicates whether the corresponding element in `selectedColumns` is the
974/// name of a column that must be defined via datasource. All elements of the returned vector are false if no
975/// data-source is present.
977{
978 const auto nColumns = requestedCols.size();
979 std::vector<bool> mustBeDefined(nColumns, false);
980 for (auto i = 0u; i < nColumns; ++i)
982 return mustBeDefined;
983}
984
986{
987 std::unordered_set<std::string> uniqueCols;
988 for (auto &col : cols) {
989 if (!uniqueCols.insert(col).second) {
990 const auto msg = "Error: column \"" + col +
991 "\" was passed to Snapshot twice. This is not supported: only one of the columns would be "
992 "readable with RDataFrame.";
993 throw std::logic_error(msg);
994 }
995 }
996}
997
998/// Return copies of colsWithoutAliases and colsWithAliases with size branches for variable-sized array branches added
999/// in the right positions (i.e. before the array branches that need them).
1000std::pair<std::vector<std::string>, std::vector<std::string>>
1001AddSizeBranches(const std::vector<std::string> &branches, ROOT::RDF::RDataSource *ds,
1002 std::vector<std::string> &&colsWithoutAliases, std::vector<std::string> &&colsWithAliases)
1003{
1004 TTree *tree{};
1005 if (auto treeDS = dynamic_cast<ROOT::Internal::RDF::RTTreeDS *>(ds))
1006 tree = treeDS->GetTree();
1007 if (!tree) // nothing to do
1008 return {std::move(colsWithoutAliases), std::move(colsWithAliases)};
1009
1010 assert(colsWithoutAliases.size() == colsWithAliases.size());
1011
1012 auto nCols = colsWithoutAliases.size();
1013 // Use index-iteration as we modify the vector during the iteration.
1014 for (std::size_t i = 0u; i < nCols; ++i) {
1015 const auto &colName = colsWithoutAliases[i];
1016 if (!IsStrInVec(colName, branches))
1017 continue; // this column is not a TTree branch, nothing to do
1018
1019 auto *b = tree->GetBranch(colName.c_str());
1020 if (!b) // try harder
1021 b = tree->FindBranch(colName.c_str());
1022 assert(b != nullptr);
1023 auto *leaves = b->GetListOfLeaves();
1024 if (b->IsA() != TBranch::Class() || leaves->GetEntries() != 1)
1025 continue; // this branch is not a variable-sized array, nothing to do
1026
1027 TLeaf *countLeaf = static_cast<TLeaf *>(leaves->At(0))->GetLeafCount();
1028 if (!countLeaf || IsStrInVec(countLeaf->GetName(), colsWithoutAliases))
1029 continue; // not a variable-sized array or the size branch is already there, nothing to do
1030
1031 // otherwise we must insert the size in colsWithoutAliases _and_ colsWithAliases
1032 colsWithoutAliases.insert(colsWithoutAliases.begin() + i, countLeaf->GetName());
1033 colsWithAliases.insert(colsWithAliases.begin() + i, countLeaf->GetName());
1034 ++nCols;
1035 ++i; // as we inserted an element in the vector we iterate over, we need to move the index forward one extra time
1036 }
1037
1038 return {std::move(colsWithoutAliases), std::move(colsWithAliases)};
1039}
1040
1042{
1043 std::set<std::string> uniqueCols;
1044 columnNames.erase(
1045 std::remove_if(columnNames.begin(), columnNames.end(),
1046 [&uniqueCols](const std::string &colName) { return !uniqueCols.insert(colName).second; }),
1047 columnNames.end());
1048}
1049
1050#ifdef R__HAS_ROOT7
1051void RemoveRNTupleSubFields(ColumnNames_t &columnNames)
1052{
1053 ColumnNames_t parentFields;
1054
1055 std::copy_if(columnNames.cbegin(), columnNames.cend(), std::back_inserter(parentFields),
1056 [](const std::string &colName) { return colName.find('.') == std::string::npos; });
1057
1058 columnNames.erase(std::remove_if(columnNames.begin(), columnNames.end(),
1059 [&parentFields](const std::string &colName) {
1060 if (colName.find('.') == std::string::npos)
1061 return false;
1062 const auto parentFieldName = colName.substr(0, colName.find_first_of('.'));
1063 return std::find(parentFields.cbegin(), parentFields.cend(), parentFieldName) !=
1064 parentFields.end();
1065 }),
1066 columnNames.end());
1067}
1068#endif
1069} // namespace RDF
1070} // namespace Internal
1071} // namespace ROOT
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
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.
Definition TError.h:125
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
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:406
#define R__LOCKGUARD(mutex)
#define free
Definition civetweb.c:1539
The head node of a RDF computation graph.
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 * Class()
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.
Definition TClass.cxx:3069
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Definition TPRegexp.h:78
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
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.
void CheckForNoVariations(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister)
Throw if the column has systematic variations attached.
ParsedTreePath ParseTreePath(std::string_view fullTreeName)
void CheckForRedefinition(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister, const ColumnNames_t &treeColumns, const ColumnNames_t &dataSourceColumns)
Throw if column definedColView is already there.
void CheckForDefinition(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister, const ColumnNames_t &treeColumns, const ColumnNames_t &dataSourceColumns)
Throw if column definedColView is not already there.
std::shared_ptr< RJittedDefine > BookDefineJit(std::string_view name, std::string_view expression, RLoopManager &lm, RDataSource *ds, const RColumnRegister &colRegister, const ColumnNames_t &branches, std::shared_ptr< RNodeBase > *upcastNodeOnHeap)
Book the jitting of a Define call.
void CheckValidCppVarName(std::string_view var, const std::string &where)
void RemoveDuplicates(ColumnNames_t &columnNames)
ColumnNames_t GetValidatedColumnNames(RLoopManager &lm, const unsigned int nColumns, const ColumnNames_t &columns, const RColumnRegister &colRegister, RDataSource *ds)
Given the desired number of columns and the user-provided list of columns:
std::shared_ptr< RNodeBase > UpcastNode(std::shared_ptr< RNodeBase > ptr)
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...
Definition RDFUtils.cxx:123
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)
Definition RDFUtils.cxx:444
std::string ResolveAlias(const std::string &col, const std::map< std::string, std::string > &aliasMap)
std::vector< std::string > GetFilterNames(const std::shared_ptr< RLoopManager > &loopManager)
std::string PrettyPrintAddr(const void *const addr)
void CheckTypesAndPars(unsigned int nTemplateParams, unsigned int nColumnNames)
bool AtLeastOneEmptyString(const std::vector< std::string_view > strings)
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *, RDataSource *, RDefineBase *, bool vector2RVec=true)
Return a string containing the type of the given branch.
Definition RDFUtils.cxx:233
std::pair< std::vector< std::string >, std::vector< std::string > > AddSizeBranches(const std::vector< std::string > &branches, ROOT::RDF::RDataSource *ds, std::vector< std::string > &&colsWithoutAliases, std::vector< std::string > &&colsWithAliases)
Return copies of colsWithoutAliases and colsWithAliases with size branches for variable-sized array b...
std::shared_ptr< RDFDetail::RJittedFilter > BookFilterJit(std::shared_ptr< RDFDetail::RNodeBase > *prevNodeOnHeap, std::string_view name, std::string_view expression, const ColumnNames_t &branches, const RColumnRegister &colRegister, TTree *tree, RDataSource *ds)
Book the jitting of a Filter call.
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.
Definition Utils.hxx:270
bool IsInternalColumn(std::string_view colName)
Whether custom column with name colName is an "internal" column such as rdfentry_ or rdfslot_.
Definition RDFUtils.cxx:386
ColumnNames_t FilterArraySizeColNames(const ColumnNames_t &columnNames, const std::string &action)
Take a list of column names, return that list with entries starting by '#' filtered out.
void InterpreterDeclare(const std::string &code)
Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors.
Definition RDFUtils.cxx:337
std::shared_ptr< RJittedVariation > BookVariationJit(const std::vector< std::string > &colNames, std::string_view variationName, const std::vector< std::string > &variationTags, std::string_view expression, RLoopManager &lm, RDataSource *ds, const RColumnRegister &colRegister, const ColumnNames_t &branches, std::shared_ptr< RNodeBase > *upcastNodeOnHeap, bool isSingleColumn)
Book the jitting of a Vary call.
std::vector< std::string > GetValidatedArgTypes(const ColumnNames_t &colNames, const RColumnRegister &colRegister, TTree *tree, RDataSource *ds, const std::string &context, bool vector2RVec)
void CheckForDuplicateSnapshotColumns(const ColumnNames_t &cols)
ColumnNames_t ConvertRegexToColumns(const ColumnNames_t &colNames, std::string_view columnNameRegexp, std::string_view callerName)
std::vector< bool > FindUndefinedDSColumns(const ColumnNames_t &requestedCols, const ColumnNames_t &definedCols)
Return a bitset each element of which indicates whether the corresponding element in selectedColumns ...
std::shared_ptr< RJittedDefine > BookDefinePerSampleJit(std::string_view name, std::string_view expression, RLoopManager &lm, const RColumnRegister &colRegister, std::shared_ptr< RNodeBase > *upcastNodeOnHeap)
Book the jitting of a DefinePerSample call.
std::string JitBuildAction(const ColumnNames_t &cols, std::shared_ptr< RDFDetail::RNodeBase > *prevNode, const std::type_info &helperArgType, const std::type_info &at, void *helperArgOnHeap, TTree *tree, const unsigned int nSlots, const RColumnRegister &colRegister, RDataSource *ds, std::weak_ptr< RJittedAction > *jittedActionOnHeap, const bool vector2RVec)
ColumnNames_t FindUnknownColumns(const ColumnNames_t &requiredCols, const ColumnNames_t &datasetColumns, const RColumnRegister &definedCols, const ColumnNames_t &dataSourceColumns)
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)
Definition vec.h:98