11#ifndef ROOT_RDF_TINTERFACE
12#define ROOT_RDF_TINTERFACE
48#include "RConfigure.h"
57#include <initializer_list>
67#include <unordered_set>
82std::string printValue(ROOT::RDataFrame *tdf);
89namespace TTraits = ROOT::TypeTraits;
91template <
typename Proxied>
99class GraphCreatorHelper;
123template <
typename Proxied>
131 template <
typename T>
138 friend std::vector<std::pair<std::uint64_t, std::uint64_t>>
164 template <typename T = Proxied, typename = std::enable_if_t<std::is_same<T, RLoopManager>::value,
int>>
234 template <typename F, std::enable_if_t<!std::is_convertible<F, std::string>::value,
int> = 0>
237 RDFInternal::CheckFilter(
f);
238 using ColTypes_t =
typename TTraits::CallableTraits<F>::arg_types;
239 constexpr auto nColumns = ColTypes_t::list_size;
243 using F_t = RDFDetail::RFilter<F, Proxied>;
257 template <typename F, std::enable_if_t<!std::is_convertible<F, std::string>::value,
int> = 0>
273 template <
typename F>
354 throw std::runtime_error(
"Unknown column: \"" + std::string(column) +
"\"");
355 using F_t = RDFDetail::RFilterWithMissingValues<Proxied>;
405 throw std::runtime_error(
"Unknown column: \"" + std::string(column) +
"\"");
406 using F_t = RDFDetail::RFilterWithMissingValues<Proxied>;
452 template <typename F, typename std::enable_if_t<!std::is_convertible<F, std::string>::value,
int> = 0>
482 template <
typename F>
513 template <
typename F>
544 constexpr auto where =
"Define";
553 newCols.
AddDefine(std::move(jittedDefine));
571 template <typename F, std::enable_if_t<!std::is_convertible<F, std::string>::value,
int> = 0>
590 template <
typename F>
609 template <
typename F>
613 "RedefineSlotEntry");
632 constexpr auto where =
"Redefine";
641 newCols.
AddDefine(std::move(jittedDefine));
681 template <
typename T>
684 constexpr auto where{
"DefaultValueFor"};
694 if (retTypeName.empty()) {
698 retTypeName =
"CLING_UNKNOWN_TYPE_" + demangledType;
702 auto newColumn = std::make_shared<ROOT::Internal::RDF::RDefaultValueFor<T>>(
707 newCols.AddDefine(std::move(newColumn));
744 template <typename F, typename RetType_t = typename TTraits::CallableTraits<F>::ret_type>
752 if (retTypeName.empty()) {
756 retTypeName =
"CLING_UNKNOWN_TYPE_" + demangledType;
760 std::make_shared<RDFDetail::RDefinePerSample<F>>(
name, retTypeName, std::move(expression), *
fLoopManager);
763 newCols.AddDefine(std::move(newColumn));
816 newCols.
AddDefine(std::move(jittedDefine));
869 template <
typename F>
871 const std::vector<std::string> &variationTags, std::string_view variationName =
"")
873 std::vector<std::string> colNames{{std::string(colName)}};
874 const std::string theVariationName{variationName.empty() ? colName : variationName};
876 return VaryImpl<true>(std::move(colNames), std::forward<F>(expression), inputColumns, variationTags,
908 template <
typename F>
910 std::size_t nVariations, std::string_view variationName =
"")
912 R__ASSERT(nVariations > 0 &&
"Must have at least one variation.");
914 std::vector<std::string> variationTags;
915 variationTags.reserve(nVariations);
916 for (std::size_t i = 0u; i < nVariations; ++i)
917 variationTags.emplace_back(std::to_string(i));
919 const std::string theVariationName{variationName.empty() ? colName : variationName};
921 return Vary(colName, std::forward<F>(expression), inputColumns, std::move(variationTags), theVariationName);
956 template <
typename F>
958 const std::vector<std::string> &variationTags, std::string_view variationName)
960 return VaryImpl<false>(colNames, std::forward<F>(expression), inputColumns, variationTags, variationName);
977 template <
typename F>
980 const std::vector<std::string> &variationTags, std::string_view variationName)
982 return Vary(std::vector<std::string>(colNames), std::forward<F>(expression), inputColumns, variationTags, variationName);
1017 template <
typename F>
1019 std::size_t nVariations, std::string_view variationName)
1021 R__ASSERT(nVariations > 0 &&
"Must have at least one variation.");
1023 std::vector<std::string> variationTags;
1024 variationTags.reserve(nVariations);
1025 for (std::size_t i = 0u; i < nVariations; ++i)
1026 variationTags.emplace_back(std::to_string(i));
1028 return Vary(colNames, std::forward<F>(expression), inputColumns, std::move(variationTags), variationName);
1047 template <
typename F>
1049 const ColumnNames_t &inputColumns, std::size_t nVariations, std::string_view variationName)
1051 return Vary(std::vector<std::string>(colNames), std::forward<F>(expression), inputColumns, nVariations, variationName);
1092 const std::vector<std::string> &variationTags, std::string_view variationName =
"")
1094 std::vector<std::string> colNames{{std::string(colName)}};
1095 const std::string theVariationName{variationName.empty() ? colName : variationName};
1097 return JittedVaryImpl(colNames, expression, variationTags, theVariationName,
true);
1137 std::string_view variationName =
"")
1139 std::vector<std::string> variationTags;
1140 variationTags.reserve(nVariations);
1141 for (std::size_t i = 0u; i < nVariations; ++i)
1142 variationTags.emplace_back(std::to_string(i));
1144 return Vary(colName, expression, std::move(variationTags), variationName);
1199 std::size_t nVariations, std::string_view variationName)
1201 std::vector<std::string> variationTags;
1202 variationTags.reserve(nVariations);
1203 for (std::size_t i = 0u; i < nVariations; ++i)
1204 variationTags.emplace_back(std::to_string(i));
1206 return Vary(colNames, expression, std::move(variationTags), variationName);
1223 std::size_t nVariations, std::string_view variationName)
1225 return Vary(std::vector<std::string>(colNames), expression, nVariations, variationName);
1276 const std::vector<std::string> &variationTags, std::string_view variationName)
1278 return JittedVaryImpl(colNames, expression, variationTags, variationName,
false);
1302 constexpr auto where =
"Alias";
1310 newCols.AddAlias(alias, validColumnName);
1314 return newInterface;
1317 template <
typename... ColumnTypes>
1318 [[deprecated(
"Snapshot is not any more a template. You can safely remove the template parameters.")]]
1323 return Snapshot(treename, filename, columnList, options);
1411 const auto pairOfColumnLists =
1413 const auto &colListNoAliasesWithSizeBranches = pairOfColumnLists.first;
1414 const auto &colListWithAliasesAndSizeBranches = pairOfColumnLists.second;
1416 const auto fullTreeName = treename;
1418 treename = parsedTreePath.fTreeName;
1419 const auto &dirname = parsedTreePath.fDirName;
1425 auto retrieveTypeID = [](
const std::string &colName,
const std::string &colTypeName,
1426 bool isRNTuple =
false) ->
const std::type_info * {
1429 }
catch (
const std::runtime_error &
err) {
1433 if (std::string(
err.what()).find(
"Cannot extract type_info of type") != std::string::npos) {
1435 std::string trueTypeName{colTypeName};
1436 if (colTypeName.rfind(
"CLING_UNKNOWN_TYPE", 0) == 0)
1437 trueTypeName = colTypeName.substr(19);
1438 std::string msg{
"No runtime type information is available for column \"" + colName +
1439 "\" with type name \"" + trueTypeName +
1440 "\". Thus, it cannot be written to disk with Snapshot. Make sure to generate and load "
1441 "ROOT dictionaries for the type of this column."};
1443 throw std::runtime_error(msg);
1456 auto newRDF = std::make_shared<RInterface<RLoopManager>>(std::make_shared<RLoopManager>(colListNoPoundSizes));
1458 auto snapHelperArgs = std::make_shared<RDFInternal::SnapshotHelperArgs>(RDFInternal::SnapshotHelperArgs{
1459 std::string(filename), std::string(dirname), std::string(treename), colListWithAliasesAndSizeBranches,
1460 options, newRDF->GetLoopManager(),
GetLoopManager(),
true ,
false});
1462 auto &&nColumns = colListNoAliasesWithSizeBranches.size();
1466 std::vector<const std::type_info *> colTypeIDs;
1467 colTypeIDs.reserve(nColumns);
1468 for (
decltype(nColumns) i{}; i < nColumns; i++) {
1469 const auto &colName = validColumnNames[i];
1472 const std::type_info *colTypeID = retrieveTypeID(colName, colTypeName,
true);
1473 colTypeIDs.push_back(colTypeID);
1481 resPtr = MakeResultPtr(newRDF, *
GetLoopManager(), std::move(action));
1486 "The default Snapshot output data format is TTree, but the input data format is RNTuple. If you "
1487 "want to Snapshot to RNTuple or suppress this warning, set the appropriate fOutputFormat option in "
1488 "RSnapshotOptions. Note that this current default behaviour might change in the future.");
1493 auto newRDF = std::make_shared<RInterface<RLoopManager>>(
1494 std::make_shared<RLoopManager>(colListNoAliasesWithSizeBranches));
1496 auto snapHelperArgs = std::make_shared<RDFInternal::SnapshotHelperArgs>(RDFInternal::SnapshotHelperArgs{
1497 std::string(filename), std::string(dirname), std::string(treename), colListWithAliasesAndSizeBranches,
1498 options, newRDF->GetLoopManager(),
GetLoopManager(),
false , options.fIncludeVariations});
1500 auto &&nColumns = colListNoAliasesWithSizeBranches.size();
1504 std::vector<const std::type_info *> colTypeIDs;
1505 colTypeIDs.reserve(nColumns);
1506 for (
decltype(nColumns) i{}; i < nColumns; i++) {
1507 const auto &colName = validColumnNames[i];
1510 const std::type_info *colTypeID = retrieveTypeID(colName, colTypeName);
1511 colTypeIDs.push_back(colTypeID);
1519 resPtr = MakeResultPtr(newRDF, *
GetLoopManager(), std::move(action));
1541 std::string_view columnNameRegexp =
"",
1544 const auto definedColumns =
fColRegister.GenerateColumnNames();
1549 std::copy_if(dsColumns.begin(), dsColumns.end(), std::back_inserter(dsColumnsWithoutSizeColumns),
1550 [](
const std::string &
name) { return name.size() < 13 || name.substr(0, 13) !=
"R_rdf_sizeof_"; });
1552 columnNames.reserve(definedColumns.size() + dsColumnsWithoutSizeColumns.size());
1553 columnNames.insert(columnNames.end(), definedColumns.begin(), definedColumns.end());
1554 columnNames.insert(columnNames.end(), dsColumnsWithoutSizeColumns.begin(), dsColumnsWithoutSizeColumns.end());
1560 std::vector<std::string> selectedColumns;
1564 catch (
const std::runtime_error &
e){
1576 return Snapshot(treename, filename, selectedColumns, options);
1594 std::initializer_list<std::string> columnList,
1598 return Snapshot(treename, filename, selectedColumns, options);
1636 template <
typename... ColumnTypes>
1639 auto staticSeq = std::make_index_sequence<
sizeof...(ColumnTypes)>();
1640 return CacheImpl<ColumnTypes...>(columnList, staticSeq);
1653 if (columnList.empty()) {
1654 auto nEntries = *this->
Count();
1659 std::stringstream cacheCall;
1666 cacheCall <<
"*reinterpret_cast<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>*>("
1668 <<
") = reinterpret_cast<ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase>*>("
1673 const auto validColumnNames =
1675 const auto colTypes =
1677 for (
const auto &colType : colTypes)
1678 cacheCall << colType <<
", ";
1679 if (!columnListWithoutSizeColumns.empty())
1680 cacheCall.seekp(-2, cacheCall.cur);
1681 cacheCall <<
">(*reinterpret_cast<std::vector<std::string>*>("
1700 const auto definedColumns =
fColRegister.GenerateColumnNames();
1704 std::copy_if(dsColumns.begin(), dsColumns.end(), std::back_inserter(dsColumnsWithoutSizeColumns),
1705 [](
const std::string &
name) { return name.size() < 13 || name.substr(0, 13) !=
"R_rdf_sizeof_"; });
1707 columnNames.reserve(definedColumns.size() + dsColumns.size());
1708 columnNames.insert(columnNames.end(), definedColumns.begin(), definedColumns.end());
1709 columnNames.insert(columnNames.end(), dsColumns.begin(), dsColumns.end());
1711 return Cache(selectedColumns);
1723 return Cache(selectedColumns);
1747 if (stride == 0 || (end != 0 && end < begin))
1748 throw std::runtime_error(
"Range: stride must be strictly greater than 0 and end must be greater than begin.");
1751 using Range_t = RDFDetail::RRange<Proxied>;
1752 auto rangePtr = std::make_shared<Range_t>(begin, end, stride,
fProxiedPtr);
1754 return newInterface;
1784 template <
typename F>
1787 using arg_types =
typename TTraits::CallableTraits<
decltype(
f)>::arg_types_nodecay;
1788 using ret_type =
typename TTraits::CallableTraits<
decltype(
f)>::ret_type;
1789 ForeachSlot(RDFInternal::AddSlotParameter<ret_type>(
f, arg_types()), columns);
1814 template <
typename F>
1818 constexpr auto nColumns = ColTypes_t::list_size;
1823 using Helper_t = RDFInternal::ForeachSlotHelper<F>;
1861 template <typename F, typename T = typename TTraits::CallableTraits<F>::ret_type>
1865 std::is_default_constructible<T>::value,
1866 "reduce object cannot be default-constructed. Please provide an initialisation value (redIdentity)");
1867 return Reduce(std::move(
f), columnName, T());
1884 template <typename F, typename T = typename TTraits::CallableTraits<F>::ret_type>
1906 auto cSPtr = std::make_shared<ULong64_t>(0);
1907 using Helper_t = RDFInternal::CountHelper;
1911 return MakeResultPtr(cSPtr, *
fLoopManager, std::move(action));
1934 template <
typename T,
typename COLL = std::vector<T>>
1942 using Helper_t = RDFInternal::TakeHelper<T, T, COLL>;
1944 auto valuesPtr = std::make_shared<COLL>();
1949 return MakeResultPtr(valuesPtr, *
fLoopManager, std::move(action));
1977 template <
typename V = RDFDetail::RInferredType>
1984 std::shared_ptr<::TH1D>
h(
nullptr);
1986 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
1987 h = model.GetHistogram();
1990 if (
h->GetXaxis()->GetXmax() ==
h->GetXaxis()->GetXmin())
2012 template <
typename V = RDFDetail::RInferredType>
2015 const auto h_name = std::string(vName);
2016 const auto h_title = h_name +
";" + h_name +
";count";
2017 return Histo1D<V>({h_name.c_str(), h_title.c_str(), 128u, 0., 0.}, vName);
2038 template <
typename V = RDFDetail::RInferredType,
typename W = RDFDetail::RInferredType>
2041 const std::vector<std::string_view> columnViews = {vName, wName};
2045 std::shared_ptr<::TH1D>
h(
nullptr);
2047 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2048 h = model.GetHistogram();
2051 if (
h->GetXaxis()->GetXmax() ==
h->GetXaxis()->GetXmin())
2075 template <
typename V = RDFDetail::RInferredType,
typename W = RDFDetail::RInferredType>
2079 std::string str_vName{vName};
2080 std::string str_wName{wName};
2081 const auto h_name = str_vName +
"_weighted_" + str_wName;
2082 const auto h_title = str_vName +
", weights: " + str_wName +
";" + str_vName +
";count * " + str_wName;
2083 return Histo1D<V, W>({h_name.c_str(), h_title.c_str(), 128u, 0., 0.}, vName, wName);
2095 template <
typename V,
typename W>
2129 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType>
2132 std::shared_ptr<::TH2D>
h(
nullptr);
2134 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2135 h = model.GetHistogram();
2137 if (!RDFInternal::HistoUtils<::TH2D>::HasAxisLimits(*
h)) {
2138 throw std::runtime_error(
"2D histograms with no axes limits are not supported yet.");
2140 const std::vector<std::string_view> columnViews = {v1Name, v2Name};
2170 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType,
2171 typename W = RDFDetail::RInferredType>
2173 Histo2D(
const TH2DModel &model, std::string_view v1Name, std::string_view v2Name, std::string_view wName)
2175 std::shared_ptr<::TH2D>
h(
nullptr);
2177 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2178 h = model.GetHistogram();
2180 if (!RDFInternal::HistoUtils<::TH2D>::HasAxisLimits(*
h)) {
2181 throw std::runtime_error(
"2D histograms with no axes limits are not supported yet.");
2183 const std::vector<std::string_view> columnViews = {v1Name, v2Name, wName};
2190 template <
typename V1,
typename V2,
typename W>
2225 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType,
2226 typename V3 = RDFDetail::RInferredType>
2228 std::string_view v3Name =
"")
2230 std::shared_ptr<::TH3D>
h(
nullptr);
2232 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2233 h = model.GetHistogram();
2235 if (!RDFInternal::HistoUtils<::TH3D>::HasAxisLimits(*
h)) {
2236 throw std::runtime_error(
"3D histograms with no axes limits are not supported yet.");
2238 const std::vector<std::string_view> columnViews = {v1Name, v2Name, v3Name};
2274 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType,
2275 typename V3 = RDFDetail::RInferredType,
typename W = RDFDetail::RInferredType>
2277 std::string_view v3Name, std::string_view wName)
2279 std::shared_ptr<::TH3D>
h(
nullptr);
2281 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2282 h = model.GetHistogram();
2284 if (!RDFInternal::HistoUtils<::TH3D>::HasAxisLimits(*
h)) {
2285 throw std::runtime_error(
"3D histograms with no axes limits are not supported yet.");
2287 const std::vector<std::string_view> columnViews = {v1Name, v2Name, v3Name, wName};
2294 template <
typename V1,
typename V2,
typename V3,
typename W>
2325 template <
typename FirstColumn,
typename... OtherColumns>
2328 std::shared_ptr<::THnD>
h(
nullptr);
2330 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2331 h = model.GetHistogram();
2332 const auto hDims =
h->GetNdimensions();
2333 decltype(hDims) nCols = columnList.size();
2335 if (!wName.empty() && nCols == hDims + 1)
2336 throw std::invalid_argument(
"The weight column was passed as an argument and at the same time the list of "
2337 "input columns contains one column more than the number of dimensions of the "
2338 "histogram. Call as 'HistoND(model, cols, weightCol)'.");
2340 if (nCols == hDims + 1)
2341 Warning(
"HistoND",
"Passing the column with the weights as the last column in the list is deprecated. "
2342 "Instead, pass it as a separate argument, e.g. 'HistoND(model, cols, weightCol)'.");
2344 if (!wName.empty() || nCols == hDims + 1)
2347 if (nCols != hDims + 1 && nCols != hDims)
2348 throw std::invalid_argument(
"Wrong number of columns for the specified number of histogram axes.");
2351 if (!wName.empty()) {
2355 userColumns.push_back(std::string{wName});
2356 return CreateAction<RDFInternal::ActionTags::HistoND, FirstColumn, OtherColumns...>(userColumns,
h,
h,
2359 return CreateAction<RDFInternal::ActionTags::HistoND, FirstColumn, OtherColumns...>(columnList,
h,
h,
2385 std::shared_ptr<::THnD>
h(
nullptr);
2387 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2388 h = model.GetHistogram();
2389 const auto hDims =
h->GetNdimensions();
2390 decltype(hDims) nCols = columnList.size();
2392 if (!wName.empty() && nCols == hDims + 1)
2393 throw std::invalid_argument(
"The weight column was passed as an argument and at the same time the list of "
2394 "input columns contains one column more than the number of dimensions of the "
2395 "histogram. Call as 'HistoND(model, cols, weightCol)'.");
2397 if (nCols == hDims + 1)
2398 Warning(
"HistoND",
"Passing the column with the weights as the last column in the list is deprecated. "
2399 "Instead, pass it as a separate argument, e.g. 'HistoND(model, cols, weightCol)'.");
2401 if (!wName.empty() || nCols == hDims + 1)
2404 if (nCols != hDims + 1 && nCols != hDims)
2405 throw std::invalid_argument(
"Wrong number of columns for the specified number of histogram axes.");
2408 if (!wName.empty()) {
2412 userColumns.push_back(std::string{wName});
2414 userColumns.size());
2445 template <
typename FirstColumn,
typename... OtherColumns>
2449 std::shared_ptr<::THnSparseD>
h(
nullptr);
2451 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2452 h = model.GetHistogram();
2453 const auto hDims =
h->GetNdimensions();
2454 decltype(hDims) nCols = columnList.size();
2456 if (!wName.empty() && nCols == hDims + 1)
2457 throw std::invalid_argument(
"The weight column was passed as an argument and at the same time the list of "
2458 "input columns contains one column more than the number of dimensions of the "
2459 "histogram. Call as 'HistoNSparseD(model, cols, weightCol)'.");
2461 if (nCols == hDims + 1)
2463 "Passing the column with the weights as the last column in the list is deprecated. "
2464 "Instead, pass it as a separate argument, e.g. 'HistoNSparseD(model, cols, weightCol)'.");
2466 if (!wName.empty() || nCols == hDims + 1)
2469 if (nCols != hDims + 1 && nCols != hDims)
2470 throw std::invalid_argument(
"Wrong number of columns for the specified number of histogram axes.");
2473 if (!wName.empty()) {
2477 userColumns.push_back(std::string{wName});
2478 return CreateAction<RDFInternal::ActionTags::HistoNSparseD, FirstColumn, OtherColumns...>(userColumns,
h,
h,
2481 return CreateAction<RDFInternal::ActionTags::HistoNSparseD, FirstColumn, OtherColumns...>(columnList,
h,
h,
2508 std::shared_ptr<::THnSparseD>
h(
nullptr);
2510 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2511 h = model.GetHistogram();
2512 const auto hDims =
h->GetNdimensions();
2513 decltype(hDims) nCols = columnList.size();
2515 if (!wName.empty() && nCols == hDims + 1)
2516 throw std::invalid_argument(
"The weight column was passed as an argument and at the same time the list of "
2517 "input columns contains one column more than the number of dimensions of the "
2518 "histogram. Call as 'HistoNSparseD(model, cols, weightCol)'.");
2520 if (nCols == hDims + 1)
2522 "Passing the column with the weights as the last column in the list is deprecated. "
2523 "Instead, pass it as a separate argument, e.g. 'HistoNSparseD(model, cols, weightCol)'.");
2525 if (!wName.empty() || nCols == hDims + 1)
2528 if (nCols != hDims + 1 && nCols != hDims)
2529 throw std::invalid_argument(
"Wrong number of columns for the specified number of histogram axes.");
2532 if (!wName.empty()) {
2536 userColumns.push_back(std::string{wName});
2560 template <
typename BinContentType =
double,
typename V = RDFDetail::RInferredType>
2562 Hist(std::uint64_t nNormalBins, std::pair<double, double> interval, std::string_view vName)
2564 std::shared_ptr
h = std::make_shared<ROOT::Experimental::RHist<BinContentType>>(nNormalBins, interval);
2586 template <
typename BinContentType =
double,
typename ColumnType = RDFDetail::RInferredType,
typename... ColumnTypes>
2590 if (axes.size() != columnList.size()) {
2591 std::string msg =
"Wrong number of columns for the specified number of histogram axes: ";
2592 msg +=
"expected " + std::to_string(axes.size()) +
", got " + std::to_string(columnList.size());
2593 throw std::invalid_argument(msg);
2596 std::shared_ptr
h = std::make_shared<ROOT::Experimental::RHist<BinContentType>>(std::move(axes));
2598 return Hist<ColumnType, ColumnTypes...>(
h, columnList);
2618 template <
typename ColumnType = RDFDetail::RInferredType,
typename... ColumnTypes,
typename BinContentType>
2624 if (
h->GetNDimensions() != columnList.size()) {
2625 std::string msg =
"Wrong number of columns for the passed histogram: ";
2626 msg +=
"expected " + std::to_string(
h->GetNDimensions()) +
", got " + std::to_string(columnList.size());
2627 throw std::invalid_argument(msg);
2651 typename W = RDFDetail::RInferredType>
2653 Hist(std::uint64_t nNormalBins, std::pair<double, double> interval, std::string_view vName, std::string_view wName)
2655 std::shared_ptr
h = std::make_shared<ROOT::Experimental::RHist<BinContentType>>(nNormalBins, interval);
2681 typename ColumnType = RDFDetail::RInferredType,
typename... ColumnTypes>
2683 Hist(std::vector<ROOT::Experimental::RAxisVariant> axes,
const ColumnNames_t &columnList, std::string_view wName)
2686 "weighted filling is not supported for integral bin content types");
2688 if (axes.size() != columnList.size()) {
2689 std::string msg =
"Wrong number of columns for the specified number of histogram axes: ";
2690 msg +=
"expected " + std::to_string(axes.size()) +
", got " + std::to_string(columnList.size());
2691 throw std::invalid_argument(msg);
2694 std::shared_ptr
h = std::make_shared<ROOT::Experimental::RHist<BinContentType>>(std::move(axes));
2696 return Hist<ColumnType, ColumnTypes...>(
h, columnList, wName);
2719 template <
typename ColumnType = RDFDetail::RInferredType,
typename... ColumnTypes,
typename BinContentType>
2722 std::string_view wName)
2725 "weighted filling is not supported for integral bin content types");
2729 if (
h->GetNDimensions() != columnList.size()) {
2730 std::string msg =
"Wrong number of columns for the passed histogram: ";
2731 msg +=
"expected " + std::to_string(
h->GetNDimensions()) +
", got " + std::to_string(columnList.size());
2732 throw std::invalid_argument(msg);
2737 columnListWithWeights.push_back(std::string(wName));
2739 return CreateAction<RDFInternal::ActionTags::HistWithWeight, ColumnType, ColumnTypes...>(
2740 columnListWithWeights,
h,
h,
fProxiedPtr, columnListWithWeights.size());
2760 template <
typename ColumnType = RDFDetail::RInferredType,
typename... ColumnTypes,
typename BinContentType>
2766 if (
h->GetNDimensions() != columnList.size()) {
2767 std::string msg =
"Wrong number of columns for the passed histogram: ";
2768 msg +=
"expected " + std::to_string(
h->GetNDimensions()) +
", got " + std::to_string(columnList.size());
2769 throw std::invalid_argument(msg);
2796 template <
typename ColumnType = RDFDetail::RInferredType,
typename... ColumnTypes,
typename BinContentType>
2799 std::string_view wName)
2802 "weighted filling is not supported for integral bin content types");
2806 if (
h->GetNDimensions() != columnList.size()) {
2807 std::string msg =
"Wrong number of columns for the passed histogram: ";
2808 msg +=
"expected " + std::to_string(
h->GetNDimensions()) +
", got " + std::to_string(columnList.size());
2809 throw std::invalid_argument(msg);
2814 columnListWithWeights.push_back(std::string(wName));
2816 return CreateAction<RDFInternal::ActionTags::HistWithWeight, ColumnType, ColumnTypes...>(
2817 columnListWithWeights,
h,
h,
fProxiedPtr, columnListWithWeights.size());
2849 template <
typename X = RDFDetail::RInferredType,
typename Y = RDFDetail::RInferredType>
2852 auto graph = std::make_shared<::TGraph>();
2853 const std::vector<std::string_view> columnViews = {
x,
y};
2861 const auto g_name = validatedColumns[1] +
"_vs_" + validatedColumns[0];
2862 const auto g_title = validatedColumns[1] +
" vs " + validatedColumns[0];
2863 graph->SetNameTitle(g_name.c_str(), g_title.c_str());
2864 graph->GetXaxis()->SetTitle(validatedColumns[0].c_str());
2865 graph->GetYaxis()->SetTitle(validatedColumns[1].c_str());
2911 template <
typename X = RDFDetail::RInferredType,
typename Y = RDFDetail::RInferredType,
2912 typename EXL = RDFDetail::RInferredType,
typename EXH = RDFDetail::RInferredType,
2913 typename EYL = RDFDetail::RInferredType,
typename EYH = RDFDetail::RInferredType>
2916 std::string_view exh =
"", std::string_view eyl =
"", std::string_view eyh =
"")
2918 auto graph = std::make_shared<::TGraphAsymmErrors>();
2919 const std::vector<std::string_view> columnViews = {
x,
y, exl, exh, eyl, eyh};
2927 const auto g_name = validatedColumns[1] +
"_vs_" + validatedColumns[0];
2928 const auto g_title = validatedColumns[1] +
" vs " + validatedColumns[0];
2929 graph->SetNameTitle(g_name.c_str(), g_title.c_str());
2930 graph->GetXaxis()->SetTitle(validatedColumns[0].c_str());
2931 graph->GetYaxis()->SetTitle(validatedColumns[1].c_str());
2960 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType>
2964 std::shared_ptr<::TProfile>
h(
nullptr);
2966 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
2967 h = model.GetProfile();
2970 if (!RDFInternal::HistoUtils<::TProfile>::HasAxisLimits(*
h)) {
2971 throw std::runtime_error(
"Profiles with no axes limits are not supported yet.");
2973 const std::vector<std::string_view> columnViews = {v1Name, v2Name};
3004 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType,
3005 typename W = RDFDetail::RInferredType>
3009 std::shared_ptr<::TProfile>
h(
nullptr);
3011 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
3012 h = model.GetProfile();
3015 if (!RDFInternal::HistoUtils<::TProfile>::HasAxisLimits(*
h)) {
3016 throw std::runtime_error(
"Profile histograms with no axes limits are not supported yet.");
3018 const std::vector<std::string_view> columnViews = {v1Name, v2Name, wName};
3028 template <
typename V1,
typename V2,
typename W>
3061 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType,
3062 typename V3 = RDFDetail::RInferredType>
3064 std::string_view v2Name =
"", std::string_view v3Name =
"")
3066 std::shared_ptr<::TProfile2D>
h(
nullptr);
3068 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
3069 h = model.GetProfile();
3072 if (!RDFInternal::HistoUtils<::TProfile2D>::HasAxisLimits(*
h)) {
3073 throw std::runtime_error(
"2D profiles with no axes limits are not supported yet.");
3075 const std::vector<std::string_view> columnViews = {v1Name, v2Name, v3Name};
3109 template <
typename V1 = RDFDetail::RInferredType,
typename V2 = RDFDetail::RInferredType,
3110 typename V3 = RDFDetail::RInferredType,
typename W = RDFDetail::RInferredType>
3112 std::string_view v3Name, std::string_view wName)
3114 std::shared_ptr<::TProfile2D>
h(
nullptr);
3116 ROOT::Internal::RDF::RIgnoreErrorLevelRAII iel(
kError);
3117 h = model.GetProfile();
3120 if (!RDFInternal::HistoUtils<::TProfile2D>::HasAxisLimits(*
h)) {
3121 throw std::runtime_error(
"2D profiles with no axes limits are not supported yet.");
3123 const std::vector<std::string_view> columnViews = {v1Name, v2Name, v3Name, wName};
3132 template <
typename V1,
typename V2,
typename V3,
typename W>
3172 template <
typename FirstColumn = RDFDetail::RInferredType,
typename... OtherColumns,
typename T>
3175 auto h = std::make_shared<std::decay_t<T>>(std::forward<T>(model));
3176 if (!RDFInternal::HistoUtils<T>::HasAxisLimits(*
h)) {
3177 throw std::runtime_error(
"The absence of axes limits is not supported yet.");
3198 template <
typename V = RDFDetail::RInferredType>
3202 if (!value.empty()) {
3203 columns.emplace_back(std::string(value));
3206 if (std::is_same<V, RDFDetail::RInferredType>::value) {
3230 template <
typename V = RDFDetail::RInferredType,
typename W = RDFDetail::RInferredType>
3233 ColumnNames_t columns{std::string(value), std::string(weight)};
3234 constexpr auto vIsInferred = std::is_same<V, RDFDetail::RInferredType>::value;
3235 constexpr auto wIsInferred = std::is_same<W, RDFDetail::RInferredType>::value;
3241 if (vIsInferred && wIsInferred) {
3243 }
else if (vIsInferred != wIsInferred) {
3244 std::string error(
"The ");
3245 error += vIsInferred ?
"value " :
"weight ";
3246 error +=
"column type is explicit, while the ";
3247 error += vIsInferred ?
"weight " :
"value ";
3248 error +=
" is specified to be inferred. This case is not supported: please specify both types or none.";
3249 throw std::runtime_error(error);
3276 template <
typename T = RDFDetail::RInferredType>
3280 using RetType_t = RDFDetail::MinReturnType_t<T>;
3281 auto minV = std::make_shared<RetType_t>(std::numeric_limits<RetType_t>::max());
3306 template <
typename T = RDFDetail::RInferredType>
3310 using RetType_t = RDFDetail::MaxReturnType_t<T>;
3311 auto maxV = std::make_shared<RetType_t>(std::numeric_limits<RetType_t>::lowest());
3337 template <
typename T = RDFDetail::RInferredType>
3341 auto meanV = std::make_shared<double>(0);
3365 template <
typename T = RDFDetail::RInferredType>
3369 auto stdDeviationV = std::make_shared<double>(0);
3396 template <
typename T = RDFDetail::RInferredType>
3398 Sum(std::string_view columnName =
"",
3399 const RDFDetail::SumReturnType_t<T> &initValue = RDFDetail::SumReturnType_t<T>{})
3402 auto sumV = std::make_shared<RDFDetail::SumReturnType_t<T>>(initValue);
3433 bool returnEmptyReport =
false;
3439 if (std::is_same<Proxied, RLoopManager>::value &&
fColRegister.GenerateColumnNames().size() > 4)
3440 returnEmptyReport =
true;
3442 auto rep = std::make_shared<RCutFlowReport>();
3449 return MakeResultPtr(rep, *
fLoopManager, std::move(action));
3513 template <typename AccFun, typename MergeFun, typename R = typename TTraits::CallableTraits<AccFun>::ret_type,
3514 typename ArgTypes =
typename TTraits::CallableTraits<AccFun>::arg_types,
3515 typename ArgTypesNoDecay =
typename TTraits::CallableTraits<AccFun>::arg_types_nodecay,
3516 typename U = TTraits::TakeFirstParameter_t<ArgTypes>,
3517 typename T = TTraits::TakeFirstParameter_t<TTraits::RemoveFirstParameter_t<ArgTypes>>>
3520 RDFInternal::CheckAggregate<R, MergeFun>(ArgTypesNoDecay());
3526 auto accObjPtr = std::make_shared<U>(aggIdentity);
3527 using Helper_t = RDFInternal::AggregateHelper<AccFun, MergeFun, R, T, U>;
3529 auto action = std::make_unique<Action_t>(
3530 Helper_t(std::move(aggregator), std::move(merger), accObjPtr,
fLoopManager->GetNSlots()), validColumnNames,
3532 return MakeResultPtr(accObjPtr, *
fLoopManager, std::move(action));
3548 template <typename AccFun, typename MergeFun, typename R = typename TTraits::CallableTraits<AccFun>::ret_type,
3549 typename ArgTypes =
typename TTraits::CallableTraits<AccFun>::arg_types,
3550 typename U = TTraits::TakeFirstParameter_t<ArgTypes>,
3551 typename T = TTraits::TakeFirstParameter_t<TTraits::RemoveFirstParameter_t<ArgTypes>>>
3555 std::is_default_constructible<U>::value,
3556 "aggregated object cannot be default-constructed. Please provide an initialisation value (aggIdentity)");
3557 return Aggregate(std::move(aggregator), std::move(merger), columnName, U());
3623 template <
typename FirstColumn = RDFDetail::RInferredType,
typename... OtherColumns,
typename Helper>
3626 using HelperT = std::decay_t<Helper>;
3628 using AH = RDFDetail::RActionImpl<HelperT>;
3629 static_assert(std::is_base_of<AH, HelperT>::value && std::is_convertible<HelperT *, AH *>::value,
3630 "Action helper of type T must publicly inherit from ROOT::Detail::RDF::RActionImpl<T>");
3632 auto hPtr = std::make_shared<HelperT>(std::forward<Helper>(helper));
3633 auto resPtr = hPtr->GetResultPtr();
3635 if (std::is_same<FirstColumn, RDFDetail::RInferredType>::value && columns.empty()) {
3638 return CreateAction<RDFInternal::ActionTags::Book, FirstColumn, OtherColumns...>(columns, resPtr, hPtr,
3668 template <
typename... ColumnTypes>
3672 auto newCols = columnList;
3673 newCols.insert(newCols.begin(),
"rdfentry_");
3674 auto displayer = std::make_shared<RDisplay>(newCols,
GetColumnTypeNamesList(newCols), nMaxCollectionElements);
3675 using displayHelperArgs_t = std::pair<size_t, std::shared_ptr<RDisplay>>;
3678 std::move(newCols), displayer, std::make_shared<displayHelperArgs_t>(nRows, displayer),
fProxiedPtr);
3695 auto newCols = columnList;
3696 newCols.insert(newCols.begin(),
"rdfentry_");
3697 auto displayer = std::make_shared<RDisplay>(newCols,
GetColumnTypeNamesList(newCols), nMaxCollectionElements);
3698 using displayHelperArgs_t = std::pair<size_t, std::shared_ptr<RDisplay>>;
3700 std::move(newCols), displayer, std::make_shared<displayHelperArgs_t>(nRows, displayer),
fProxiedPtr,
3701 columnList.size() + 1);
3715 Display(std::string_view columnNameRegexp =
"",
size_t nRows = 5,
size_t nMaxCollectionElements = 10)
3719 return Display(selectedColumns, nRows, nMaxCollectionElements);
3731 Display(std::initializer_list<std::string> columnList,
size_t nRows = 5,
size_t nMaxCollectionElements = 10)
3734 return Display(selectedColumns, nRows, nMaxCollectionElements);
3740 template <typename F, typename DefineType, typename RetType = typename TTraits::CallableTraits<F>::ret_type>
3744 if (where.compare(0, 8,
"Redefine") != 0) {
3754 using ArgTypes_t =
typename TTraits::CallableTraits<F>::arg_types;
3756 std::is_same<DefineType, RDFDetail::ExtraArgsForDefine::Slot>::value, ArgTypes_t>
::type;
3758 std::is_same<DefineType, RDFDetail::ExtraArgsForDefine::SlotAndEntry>::value, ColTypesTmp_t>
::type;
3760 constexpr auto nColumns = ColTypes_t::list_size;
3767 if (retTypeName.empty()) {
3771 retTypeName =
"CLING_UNKNOWN_TYPE_" + demangledType;
3774 using NewCol_t = RDFDetail::RDefine<F, DefineType>;
3775 auto newColumn = std::make_shared<NewCol_t>(
name, retTypeName, std::forward<F>(expression), validColumnNames,
3779 newCols.
AddDefine(std::move(newColumn));
3783 return newInterface;
3789 template <typename F, typename DefineType, typename RetType = typename TTraits::CallableTraits<F>::ret_type,
3790 bool IsFStringConv = std::is_convertible<F, std::string>::value,
3791 bool IsRetTypeDefConstr = std::is_default_constructible<RetType>::value>
3792 std::enable_if_t<!IsFStringConv && !IsRetTypeDefConstr, RInterface<Proxied>>
3795 static_assert(std::is_default_constructible<typename TTraits::CallableTraits<F>::ret_type>::value,
3796 "Error in `Define`: type returned by expression is not default-constructible");
3802 template <
typename... ColTypes, std::size_t... S>
3808 constexpr bool areCopyConstructible =
3809 RDFInternal::TEvalAnd<std::is_copy_constructible<ColTypes>::value...>::value;
3810 static_assert(areCopyConstructible,
"Columns of a type which is not copy constructible cannot be cached yet.");
3814 auto colHolders = std::make_tuple(
Take<ColTypes>(columnListWithoutSizeColumns[S])...);
3815 auto ds = std::make_unique<
RLazyDS<ColTypes...>>(
3816 std::make_pair(columnListWithoutSizeColumns[S], std::get<S>(colHolders))...);
3823 template <
bool IsSingleColumn,
typename F>
3826 const std::vector<std::string> &variationTags, std::string_view variationName)
3828 using F_t = std::decay_t<F>;
3829 using ColTypes_t =
typename TTraits::CallableTraits<F_t>::arg_types;
3830 using RetType =
typename TTraits::CallableTraits<F_t>::ret_type;
3831 constexpr auto nColumns = ColTypes_t::list_size;
3839 if (retTypeName.empty()) {
3843 retTypeName =
"CLING_UNKNOWN_TYPE_" + demangledType;
3846 auto variation = std::make_shared<RDFInternal::RVariation<F_t, IsSingleColumn>>(
3851 newCols.AddVariation(std::move(variation));
3855 return newInterface;
3859 const std::vector<std::string> &variationTags, std::string_view variationName,
3860 bool isSingleColumn)
3862 R__ASSERT(!variationTags.empty() &&
"Must have at least one variation.");
3863 R__ASSERT(!colNames.empty() &&
"Must have at least one varied column.");
3864 R__ASSERT(!variationName.empty() &&
"Must provide a variation name.");
3866 for (
auto &colName : colNames) {
3874 if (colNames.size() > 1) {
3875 std::set<std::string> uniqueCols(colNames.begin(), colNames.end());
3876 if (uniqueCols.size() != colNames.size())
3877 throw std::logic_error(
"A column name was passed to the same Vary invocation multiple times.");
3882 auto jittedVariation =
3887 newColRegister.
AddVariation(std::move(jittedVariation));
3891 return newInterface;
3894 template <
typename Helper,
typename ActionResultType>
3896 const std::shared_ptr<Helper> &hPtr,
3897 TTraits::TypeList<RDFDetail::RInferredType>)
3903 template <
typename Helper,
typename ActionResultType,
typename... Others>
3904 RResultPtr<ActionResultType>
3906 const std::shared_ptr<Helper>& ,
3909 throw std::logic_error(std::string(
"An action was booked with no input columns, but the action requires "
3910 "columns! The action helper type was ") +
3911 typeid(Helper).
name());
Basic types used by ROOT and required by TInterpreter.
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
long long Long64_t
Portable signed long integer 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
A histogram data structure to bin data along multiple dimensions.
static constexpr bool SupportsWeightedFilling
Whether this histogram engine type supports weighted filling.
A histogram for aggregation of data along multiple dimensions.
A RDataFrame node that produces a result.
A binder for user-defined columns, variations and aliases.
void AddVariation(std::shared_ptr< RVariationBase > variation)
Register a new systematic variation.
void AddDefine(std::shared_ptr< RDFDetail::RDefineBase > column)
Add a new defined column.
The dataset specification for RDataFrame.
virtual const std::vector< std::string > & GetColumnNames() const =0
Returns a reference to the collection of the dataset's column names.
std::string GetColumnType(std::string_view column)
Return the type of a given column as a string.
ColumnNames_t GetValidatedColumnNames(const unsigned int nColumns, const ColumnNames_t &columns)
ColumnNames_t GetColumnTypeNamesList(const ColumnNames_t &columnList)
std::shared_ptr< ROOT::Detail::RDF::RLoopManager > fLoopManager
RResultPtr< ActionResultType > CreateAction(const ColumnNames_t &columns, const std::shared_ptr< ActionResultType > &r, const std::shared_ptr< HelperArgType > &helperArg, const std::shared_ptr< RDFNode > &proxiedPtr, const int=-1)
Create RAction object, return RResultPtr for the action Overload for the case in which all column typ...
void SanityChecksForVary(const std::vector< std::string > &colNames, const std::vector< std::string > &variationTags, std::string_view variationName)
RDataSource * GetDataSource() const
void CheckAndFillDSColumns(ColumnNames_t validCols, TTraits::TypeList< ColumnTypes... > typeList)
void CheckIMTDisabled(std::string_view callerName)
RInterfaceBase(std::shared_ptr< RDFDetail::RLoopManager > lm)
ColumnNames_t GetColumnNames()
Returns the names of the available columns.
RDFDetail::RLoopManager * GetLoopManager() const
RDFInternal::RColumnRegister fColRegister
The public interface to the RDataFrame federation of classes.
RResultPtr< RDisplay > Display(const ColumnNames_t &columnList, size_t nRows=5, size_t nMaxCollectionElements=10)
Provides a representation of the columns in the dataset.
RResultPtr<::TProfile > Profile1D(const TProfile1DModel &model, std::string_view v1Name, std::string_view v2Name, std::string_view wName)
Fill and return a one-dimensional profile (lazy action).
RResultPtr<::THnD > HistoND(const THnDModel &model, const ColumnNames_t &columnList, std::string_view wName="")
Fill and return an N-dimensional histogram (lazy action).
RResultPtr<::TGraph > Graph(std::string_view x="", std::string_view y="")
Fill and return a TGraph object (lazy action).
RInterface< Proxied > Vary(std::string_view colName, F &&expression, const ColumnNames_t &inputColumns, const std::vector< std::string > &variationTags, std::string_view variationName="")
Register systematic variations for a single existing column using custom variation tags.
RInterface< Proxied > Vary(const std::vector< std::string > &colNames, std::string_view expression, std::size_t nVariations, std::string_view variationName)
Register systematic variations for multiple existing columns using auto-generated variation tags.
RDFDetail::RFilterBase RFilterBase
RResultPtr< ROOT::Experimental::RHist< BinContentType > > Hist(std::uint64_t nNormalBins, std::pair< double, double > interval, std::string_view vName, std::string_view wName)
Fill and return a one-dimensional RHist with weights (lazy action).
RInterface(const RInterface &)=default
Copy-ctor for RInterface.
RResultPtr< RDFDetail::MaxReturnType_t< T > > Max(std::string_view columnName="")
Return the maximum of processed column values (lazy action).
auto CallCreateActionWithoutColsIfPossible(const std::shared_ptr< ActionResultType > &resPtr, const std::shared_ptr< Helper > &hPtr, TTraits::TypeList< RDFDetail::RInferredType >) -> decltype(hPtr->Exec(0u), RResultPtr< ActionResultType >{})
RInterface(RInterface &&)=default
Move-ctor for RInterface.
RInterface< Proxied > Vary(std::string_view colName, std::string_view expression, const std::vector< std::string > &variationTags, std::string_view variationName="")
Register systematic variations for a single existing column using custom variation tags.
RInterface< RDFDetail::RFilter< F, Proxied > > Filter(F f, const std::initializer_list< std::string > &columns)
Append a filter to the call graph.
RInterface< RLoopManager > Cache(std::initializer_list< std::string > columnList)
Save selected columns in memory.
RInterface< Proxied > Vary(std::string_view colName, F &&expression, const ColumnNames_t &inputColumns, std::size_t nVariations, std::string_view variationName="")
Register systematic variations for a single existing column using auto-generated variation tags.
RInterface< Proxied > Vary(std::initializer_list< std::string > colNames, std::string_view expression, std::size_t nVariations, std::string_view variationName)
Register systematic variations for multiple existing columns using auto-generated variation tags.
RResultPtr< RInterface< RLoopManager > > Snapshot(std::string_view treename, std::string_view filename, const ColumnNames_t &columnList, const RSnapshotOptions &options=RSnapshotOptions())
RResultPtr<::TProfile2D > Profile2D(const TProfile2DModel &model, std::string_view v1Name, std::string_view v2Name, std::string_view v3Name, std::string_view wName)
Fill and return a two-dimensional profile (lazy action).
RResultPtr< RInterface< RLoopManager > > Snapshot(std::string_view treename, std::string_view filename, std::string_view columnNameRegexp="", const RSnapshotOptions &options=RSnapshotOptions())
Save selected columns to disk, in a new TTree or RNTuple treename in file filename.
RResultPtr< RDisplay > Display(const ColumnNames_t &columnList, size_t nRows=5, size_t nMaxCollectionElements=10)
Provides a representation of the columns in the dataset.
RResultPtr< RDisplay > Display(std::initializer_list< std::string > columnList, size_t nRows=5, size_t nMaxCollectionElements=10)
Provides a representation of the columns in the dataset.
RInterface(const std::shared_ptr< RLoopManager > &proxied)
Build a RInterface from a RLoopManager.
RResultPtr<::THnSparseD > HistoNSparseD(const THnSparseDModel &model, const ColumnNames_t &columnList, std::string_view wName="")
Fill and return a sparse N-dimensional histogram (lazy action).
RInterface< Proxied > Redefine(std::string_view name, F expression, const ColumnNames_t &columns={})
Overwrite the value and/or type of an existing column.
std::shared_ptr< ::ROOT::Detail::RDF::RNodeBase > fProxiedPtr
RInterface< Proxied > Vary(const std::vector< std::string > &colNames, std::string_view expression, const std::vector< std::string > &variationTags, std::string_view variationName)
Register systematic variations for multiple existing columns using custom variation tags.
RInterface< Proxied > Vary(std::string_view colName, std::string_view expression, std::size_t nVariations, std::string_view variationName="")
Register systematic variations for a single existing column using auto-generated variation tags.
RResultPtr<::TH1D > Histo1D(std::string_view vName)
Fill and return a one-dimensional histogram with the values of a column (lazy action).
RInterface< RDFDetail::RRange< Proxied > > Range(unsigned int begin, unsigned int end, unsigned int stride=1)
Creates a node that filters entries based on range: [begin, end).
RResultPtr< typename std::decay_t< Helper >::Result_t > Book(Helper &&helper, const ColumnNames_t &columns={})
Book execution of a custom action using a user-defined helper object.
RResultPtr< ROOT::Experimental::RHist< BinContentType > > Hist(std::vector< ROOT::Experimental::RAxisVariant > axes, const ColumnNames_t &columnList)
Fill and return an RHist (lazy action).
RResultPtr<::TProfile > Profile1D(const TProfile1DModel &model, std::string_view v1Name="", std::string_view v2Name="")
Fill and return a one-dimensional profile (lazy action).
const std::shared_ptr< Proxied > & GetProxiedPtr() const
RResultPtr<::TH1D > Histo1D(const TH1DModel &model={"", "", 128u, 0., 0.})
Fill and return a one-dimensional histogram with the weighted values of a column (lazy action).
RResultPtr< T > Reduce(F f, std::string_view columnName="")
Execute a user-defined reduce operation on the values of a column.
RResultPtr< T > Reduce(F f, std::string_view columnName, const T &redIdentity)
Execute a user-defined reduce operation on the values of a column.
RInterface< Proxied > Vary(const std::vector< std::string > &colNames, F &&expression, const ColumnNames_t &inputColumns, const std::vector< std::string > &variationTags, std::string_view variationName)
Register systematic variations for multiple existing columns using custom variation tags.
RInterface< RLoopManager > Cache(const ColumnNames_t &columnList)
Save selected columns in memory.
RResultPtr<::TH1D > Histo1D(const TH1DModel &model, std::string_view vName, std::string_view wName)
Fill and return a one-dimensional histogram with the weighted values of a column (lazy action).
RDFDetail::RRangeBase RRangeBase
RResultPtr< RDisplay > Display(std::string_view columnNameRegexp="", size_t nRows=5, size_t nMaxCollectionElements=10)
Provides a representation of the columns in the dataset.
RInterface & operator=(const RInterface &)=default
Copy-assignment operator for RInterface.
RInterface< Proxied > VaryImpl(const std::vector< std::string > &colNames, F &&expression, const ColumnNames_t &inputColumns, const std::vector< std::string > &variationTags, std::string_view variationName)
RResultPtr<::THnSparseD > HistoNSparseD(const THnSparseDModel &model, const ColumnNames_t &columnList, std::string_view wName="")
Fill and return a sparse N-dimensional histogram (lazy action).
RInterface< Proxied > Define(std::string_view name, std::string_view expression)
Define a new column.
RInterface< RDFDetail::RFilterWithMissingValues< Proxied > > FilterAvailable(std::string_view column)
Discard entries with missing values.
std::enable_if_t<!IsFStringConv &&!IsRetTypeDefConstr, RInterface< Proxied > > DefineImpl(std::string_view, F, const ColumnNames_t &, const std::string &)
RInterface< Proxied > Redefine(std::string_view name, std::string_view expression)
Overwrite the value and/or type of an existing column.
std::vector< std::string > GetFilterNames()
Returns the names of the filters created.
RInterface< RLoopManager > Cache(std::string_view columnNameRegexp="")
Save selected columns in memory.
RResultPtr<::TH1D > Histo1D(const TH1DModel &model={"", "", 128u, 0., 0.}, std::string_view vName="")
Fill and return a one-dimensional histogram with the values of a column (lazy action).
RInterface< Proxied > Vary(std::initializer_list< std::string > colNames, F &&expression, const ColumnNames_t &inputColumns, const std::vector< std::string > &variationTags, std::string_view variationName)
Register systematic variations for multiple existing columns using custom variation tags.
RResultPtr<::TH3D > Histo3D(const TH3DModel &model, std::string_view v1Name, std::string_view v2Name, std::string_view v3Name, std::string_view wName)
Fill and return a three-dimensional histogram (lazy action).
RResultPtr< ROOT::Experimental::RHistEngine< BinContentType > > Hist(std::shared_ptr< ROOT::Experimental::RHistEngine< BinContentType > > h, const ColumnNames_t &columnList)
Fill the provided RHistEngine (lazy action).
RInterface< RLoopManager > CacheImpl(const ColumnNames_t &columnList, std::index_sequence< S... >)
RResultPtr<::TProfile2D > Profile2D(const TProfile2DModel &model, std::string_view v1Name="", std::string_view v2Name="", std::string_view v3Name="")
Fill and return a two-dimensional profile (lazy action).
RInterface< RDFDetail::RFilter< F, Proxied > > Filter(F f, std::string_view name)
Append a filter to the call graph.
RResultPtr< U > Aggregate(AccFun aggregator, MergeFun merger, std::string_view columnName="")
Execute a user-defined accumulation operation on the processed column values in each processing slot.
std::enable_if_t< std::is_default_constructible< RetType >::value, RInterface< Proxied > > DefineImpl(std::string_view name, F &&expression, const ColumnNames_t &columns, const std::string &where)
RResultPtr< ROOT::Experimental::RHist< BinContentType > > Hist(std::shared_ptr< ROOT::Experimental::RHist< BinContentType > > h, const ColumnNames_t &columnList)
Fill the provided RHist (lazy action).
RInterface(const std::shared_ptr< Proxied > &proxied, RLoopManager &lm, const RDFInternal::RColumnRegister &colRegister)
RResultPtr< COLL > Take(std::string_view column="")
Return a collection of values of a column (lazy action, returns a std::vector by default).
RInterface< Proxied > Alias(std::string_view alias, std::string_view columnName)
Allow to refer to a column with a different name.
RResultPtr< RDFDetail::MinReturnType_t< T > > Min(std::string_view columnName="")
Return the minimum of processed column values (lazy action).
RResultPtr< RInterface< RLoopManager > > Snapshot(std::string_view treename, std::string_view filename, const ColumnNames_t &columnList, const RSnapshotOptions &options=RSnapshotOptions())
Save selected columns to disk, in a new TTree or RNTuple treename in file filename.
RResultPtr< ROOT::Experimental::RHistEngine< BinContentType > > Hist(std::shared_ptr< ROOT::Experimental::RHistEngine< BinContentType > > h, const ColumnNames_t &columnList, std::string_view wName)
Fill the provided RHistEngine with weights (lazy action).
RResultPtr< RCutFlowReport > Report()
Gather filtering statistics.
RResultPtr<::TH3D > Histo3D(const TH3DModel &model)
RResultPtr<::TH3D > Histo3D(const TH3DModel &model, std::string_view v1Name="", std::string_view v2Name="", std::string_view v3Name="")
Fill and return a three-dimensional histogram (lazy action).
RResultPtr<::TH1D > Histo1D(std::string_view vName, std::string_view wName)
Fill and return a one-dimensional histogram with the weighted values of a column (lazy action).
RInterface< Proxied > DefinePerSample(std::string_view name, std::string_view expression)
Define a new column that is updated when the input sample changes.
RInterface< Proxied > DefineSlotEntry(std::string_view name, F expression, const ColumnNames_t &columns={})
Define a new column with a value dependent on the processing slot and the current entry.
RResultPtr< std::decay_t< T > > Fill(T &&model, const ColumnNames_t &columnList)
Return an object of type T on which T::Fill will be called once per event (lazy action).
RInterface< Proxied > DefineSlot(std::string_view name, F expression, const ColumnNames_t &columns={})
Define a new column with a value dependent on the processing slot.
RInterface< RDFDetail::RFilterWithMissingValues< Proxied > > FilterMissing(std::string_view column)
Keep only the entries that have missing values.
RResultPtr< TStatistic > Stats(std::string_view value="")
Return a TStatistic object, filled once per event (lazy action).
RInterface< Proxied > JittedVaryImpl(const std::vector< std::string > &colNames, std::string_view expression, const std::vector< std::string > &variationTags, std::string_view variationName, bool isSingleColumn)
RInterface< Proxied > DefaultValueFor(std::string_view column, const T &defaultValue)
In case the value in the given column is missing, provide a default value.
RResultPtr< TStatistic > Stats(std::string_view value, std::string_view weight)
Return a TStatistic object, filled once per event (lazy action).
RResultPtr<::TProfile2D > Profile2D(const TProfile2DModel &model)
Fill and return a two-dimensional profile (lazy action).
RInterface< Proxied > RedefineSlot(std::string_view name, F expression, const ColumnNames_t &columns={})
Overwrite the value and/or type of an existing column.
void Foreach(F f, const ColumnNames_t &columns={})
Execute a user-defined function on each entry (instant action).
RResultPtr<::TH2D > Histo2D(const TH2DModel &model, std::string_view v1Name="", std::string_view v2Name="")
Fill and return a two-dimensional histogram (lazy action).
RResultPtr< ActionResultType > CallCreateActionWithoutColsIfPossible(const std::shared_ptr< ActionResultType > &, const std::shared_ptr< Helper > &, Others...)
RInterface< Proxied > Define(std::string_view name, F expression, const ColumnNames_t &columns={})
Define a new column.
void ForeachSlot(F f, const ColumnNames_t &columns={})
Execute a user-defined function requiring a processing slot index on each entry (instant action).
RResultPtr<::TGraphAsymmErrors > GraphAsymmErrors(std::string_view x="", std::string_view y="", std::string_view exl="", std::string_view exh="", std::string_view eyl="", std::string_view eyh="")
Fill and return a TGraphAsymmErrors object (lazy action).
RResultPtr< U > Aggregate(AccFun aggregator, MergeFun merger, std::string_view columnName, const U &aggIdentity)
Execute a user-defined accumulation operation on the processed column values in each processing slot.
RResultPtr< ROOT::Experimental::RHist< BinContentType > > Hist(std::shared_ptr< ROOT::Experimental::RHist< BinContentType > > h, const ColumnNames_t &columnList, std::string_view wName)
Fill the provided RHist with weights (lazy action).
RResultPtr<::TProfile > Profile1D(const TProfile1DModel &model)
Fill and return a one-dimensional profile (lazy action).
RResultPtr< RInterface< RLoopManager > > Snapshot(std::string_view treename, std::string_view filename, std::initializer_list< std::string > columnList, const RSnapshotOptions &options=RSnapshotOptions())
Save selected columns to disk, in a new TTree or RNTuple treename in file filename.
RInterface & operator=(RInterface &&)=default
Move-assignment operator for RInterface.
RDFDetail::RLoopManager RLoopManager
RResultPtr<::TH2D > Histo2D(const TH2DModel &model)
RResultPtr< double > Mean(std::string_view columnName="")
Return the mean of processed column values (lazy action).
RInterface< RDFDetail::RFilter< F, Proxied > > Filter(F f, const ColumnNames_t &columns={}, std::string_view name="")
Append a filter to the call graph.
RInterface< RLoopManager > Cache(const ColumnNames_t &columnList)
Save selected columns in memory.
RInterface< Proxied > DefinePerSample(std::string_view name, F expression)
Define a new column that is updated when the input sample changes.
RInterface< Proxied > Vary(std::initializer_list< std::string > colNames, F &&expression, const ColumnNames_t &inputColumns, std::size_t nVariations, std::string_view variationName)
Register systematic variations for for multiple existing columns using custom variation tags.
RInterface< RDFDetail::RRange< Proxied > > Range(unsigned int end)
Creates a node that filters entries based on range.
RInterface< Proxied > RedefineSlotEntry(std::string_view name, F expression, const ColumnNames_t &columns={})
Overwrite the value and/or type of an existing column.
RInterface< RDFDetail::RJittedFilter > Filter(std::string_view expression, std::string_view name="")
Append a filter to the call graph.
RResultPtr< ROOT::Experimental::RHist< BinContentType > > Hist(std::uint64_t nNormalBins, std::pair< double, double > interval, std::string_view vName)
Fill and return a one-dimensional RHist (lazy action).
RResultPtr< ROOT::Experimental::RHist< BinContentType > > Hist(std::vector< ROOT::Experimental::RAxisVariant > axes, const ColumnNames_t &columnList, std::string_view wName)
Fill and return an RHist with weights (lazy action).
RResultPtr< ULong64_t > Count()
Return the number of entries processed (lazy action).
RResultPtr<::TH2D > Histo2D(const TH2DModel &model, std::string_view v1Name, std::string_view v2Name, std::string_view wName)
Fill and return a weighted two-dimensional histogram (lazy action).
RInterface< Proxied > Vary(const std::vector< std::string > &colNames, F &&expression, const ColumnNames_t &inputColumns, std::size_t nVariations, std::string_view variationName)
Register systematic variations for multiple existing columns using auto-generated tags.
RResultPtr<::THnD > HistoND(const THnDModel &model, const ColumnNames_t &columnList, std::string_view wName="")
Fill and return an N-dimensional histogram (lazy action).
RResultPtr< double > StdDev(std::string_view columnName="")
Return the unbiased standard deviation of processed column values (lazy action).
RResultPtr< RDFDetail::SumReturnType_t< T > > Sum(std::string_view columnName="", const RDFDetail::SumReturnType_t< T > &initValue=RDFDetail::SumReturnType_t< T >{})
Return the sum of processed column values (lazy action).
A RDataSource implementation which is built on top of result proxies.
Smart pointer for the return type of actions.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
typename RemoveFirstParameter< T >::type RemoveFirstParameter_t
TDirectory::TContext keeps track and restore the current directory.
Statistical variable, defined by its mean and variance (RMS).
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)
const std::type_info & TypeName2TypeID(const std::string &name)
Return the type_info associated to a name.
void ChangeEmptyEntryRange(const ROOT::RDF::RNode &node, std::pair< ULong64_t, ULong64_t > &&newRange)
std::shared_ptr< RJittedDefine > BookDefinePerSampleJit(std::string_view name, std::string_view expression, RLoopManager &lm, const RColumnRegister &colRegister)
Book the jitting of a DefinePerSample call.
void CheckValidCppVarName(std::string_view var, const std::string &where)
void ChangeSpec(const ROOT::RDF::RNode &node, ROOT::RDF::Experimental::RDatasetSpec &&spec)
Changes the input dataset specification of an RDataFrame.
const std::vector< std::string > & GetTopLevelFieldNames(const ROOT::RDF::RDataSource &ds)
void RemoveDuplicates(ColumnNames_t &columnNames)
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...
void CheckSnapshotOptionsFormatCompatibility(const ROOT::RDF::RSnapshotOptions &opts)
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 GetDataSourceLabel(const ROOT::RDF::RNode &node)
std::string PrettyPrintAddr(const void *const addr)
std::shared_ptr< RDFDetail::RJittedFilter > BookFilterJit(std::shared_ptr< RDFDetail::RNodeBase > prevNode, std::string_view name, std::string_view expression, const RColumnRegister &colRegister, TTree *tree, RDataSource *ds)
Book the jitting of a Filter call.
void TriggerRun(ROOT::RDF::RNode node)
Trigger the execution of an RDataFrame computation graph.
void CheckTypesAndPars(unsigned int nTemplateParams, unsigned int nColumnNames)
std::string DemangleTypeIdName(const std::type_info &typeInfo)
bool AtLeastOneEmptyString(const std::vector< std::string_view > strings)
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.
void SetTTreeLifeline(ROOT::RDF::RNode &node, std::any lifeline)
void RemoveRNTupleSubfields(ColumnNames_t &columnNames)
std::vector< std::pair< std::uint64_t, std::uint64_t > > GetDatasetGlobalClusterBoundaries(const RNode &node)
Retrieve the cluster boundaries for each cluster in the dataset, across files, with a global offset.
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 WarnHist()
Warn once about experimental filling of RHist.
void CheckForDuplicateSnapshotColumns(const ColumnNames_t &cols)
ColumnNames_t ConvertRegexToColumns(const ColumnNames_t &colNames, std::string_view columnNameRegexp, std::string_view callerName)
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::shared_ptr< RJittedDefine > BookDefineJit(std::string_view name, std::string_view expression, RLoopManager &lm, RDataSource *ds, const RColumnRegister &colRegister)
Book the jitting of a Define call.
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, bool isSingleColumn, const std::string &varyColType)
Book the jitting of a Vary call.
void ChangeBeginAndEndEntries(const RNode &node, Long64_t begin, Long64_t end)
RInterface<::ROOT::Detail::RDF::RNodeBase > RNode
std::vector< std::string > ColumnNames_t
ROOT type_traits extensions.
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
void DisableImplicitMT()
Disables the implicit multi-threading in ROOT (see EnableImplicitMT).
A special bin content type to compute the bin error in weighted filling.
type is TypeList if MustRemove is false, otherwise it is a TypeList with the first type removed
Tag to let data sources use the native data type when creating a column reader.
A collection of options to steer the creation of the dataset on disk through Snapshot().
A struct which stores some basic parameters of a TH1D.
A struct which stores some basic parameters of a TH2D.
A struct which stores some basic parameters of a TH3D.
A struct which stores some basic parameters of a THnD.
A struct which stores some basic parameters of a THnSparseD.
A struct which stores some basic parameters of a TProfile.
A struct which stores some basic parameters of a TProfile2D.