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