Skip to content

Commit c970f84

Browse files
eguirauddpiparo
authored andcommitted
[TDF] Validate columns in Foreach[Slot], Reduce, Take
1 parent 541edd8 commit c970f84

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

tree/treeplayer/inc/ROOT/TDFInterface.hxx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public:
459459
/// \brief Execute a user-defined function requiring a processing slot index on each entry (*instant action*)
460460
/// \param[in] f Function, lambda expression, functor class or any other callable object performing user defined
461461
/// calculations.
462-
/// \param[in] bl Names of the branches in input to the user function.
462+
/// \param[in] columns Names of the branches in input to the user function.
463463
///
464464
/// Same as `Foreach`, but the user-defined function takes an extra
465465
/// `unsigned int` as its first parameter, the *processing slot index*.
@@ -472,16 +472,15 @@ public:
472472
/// `ForeachSlot` works just as well with single-thread execution: in that
473473
/// case `slot` will always be `0`.
474474
template <typename F>
475-
void ForeachSlot(F f, const ColumnNames_t &bl = {})
475+
void ForeachSlot(F f, const ColumnNames_t &columns = {})
476476
{
477-
auto df = GetDataFrameChecked();
478-
const ColumnNames_t &defBl = df->GetDefaultColumnNames();
479-
auto nArgs = TTraits::CallableTraits<F>::arg_types::list_size;
480-
const auto actualBl = TDFInternal::SelectColumns(nArgs - 1, bl, defBl);
477+
auto loopManager = GetDataFrameChecked();
478+
auto nColumns = TTraits::CallableTraits<F>::arg_types::list_size - 1;
479+
const auto validColumnNames = GetValidatedColumnNames(*loopManager, nColumns, columns);
481480
using Helper_t = TDFInternal::ForeachSlotHelper<F>;
482481
using Action_t = TDFInternal::TAction<Helper_t, Proxied>;
483-
df->Book(std::make_shared<Action_t>(Helper_t(std::move(f)), actualBl, *fProxiedPtr));
484-
df->Run();
482+
loopManager->Book(std::make_shared<Action_t>(Helper_t(std::move(f)), validColumnNames, *fProxiedPtr));
483+
loopManager->Run();
485484
}
486485

487486
////////////////////////////////////////////////////////////////////////////
@@ -522,15 +521,15 @@ public:
522521
{
523522
using arg_types = typename TTraits::CallableTraits<F>::arg_types;
524523
TDFInternal::CheckReduce(f, arg_types());
525-
auto df = GetDataFrameChecked();
526-
const auto &defBl = df->GetDefaultColumnNames();
527-
const ColumnNames_t userColumns = columnName.empty() ? ColumnNames_t() : ColumnNames_t({std::string(columnName)});
528-
const auto actualBl = TDFInternal::SelectColumns(1, userColumns, defBl);
524+
auto loopManager = GetDataFrameChecked();
525+
const auto columns = columnName.empty() ? ColumnNames_t() : ColumnNames_t({std::string(columnName)});
526+
const auto validColumnNames = GetValidatedColumnNames(*loopManager, 1, columns);
529527
auto redObjPtr = std::make_shared<T>(initValue);
530528
using Helper_t = TDFInternal::ReduceHelper<F, T>;
531529
using Action_t = typename TDFInternal::TAction<Helper_t, Proxied>;
532-
df->Book(std::make_shared<Action_t>(Helper_t(std::move(f), redObjPtr, df->GetNSlots()), actualBl, *fProxiedPtr));
533-
return MakeResultProxy(redObjPtr, df);
530+
loopManager->Book(std::make_shared<Action_t>(Helper_t(std::move(f), redObjPtr, loopManager->GetNSlots()),
531+
validColumnNames, *fProxiedPtr));
532+
return MakeResultProxy(redObjPtr, loopManager);
534533
}
535534

536535
////////////////////////////////////////////////////////////////////////////
@@ -567,23 +566,22 @@ public:
567566
/// \brief Return a collection of values of a branch (*lazy action*)
568567
/// \tparam T The type of the branch.
569568
/// \tparam COLL The type of collection used to store the values.
570-
/// \param[in] branchName The name of the branch of which the values are to be collected
569+
/// \param[in] column The name of the branch of which the values are to be collected
571570
///
572571
/// This action is *lazy*: upon invocation of this method the calculation is
573572
/// booked but not executed. See TResultProxy documentation.
574573
template <typename T, typename COLL = std::vector<T>>
575-
TResultProxy<COLL> Take(std::string_view branchName = "")
574+
TResultProxy<COLL> Take(std::string_view column = "")
576575
{
577-
auto df = GetDataFrameChecked();
578-
unsigned int nSlots = df->GetNSlots();
579-
const ColumnNames_t &defBl = df->GetDefaultColumnNames();
580-
const ColumnNames_t userColumns = branchName.empty() ? ColumnNames_t() : ColumnNames_t({std::string(branchName)});
581-
const auto bl = TDFInternal::SelectColumns(1, userColumns, defBl);
582-
auto valuesPtr = std::make_shared<COLL>();
576+
auto loopManager = GetDataFrameChecked();
577+
const auto columns = column.empty() ? ColumnNames_t() : ColumnNames_t({std::string(column)});
578+
const auto validColumnNames = GetValidatedColumnNames(*loopManager, 1, columns);
583579
using Helper_t = TDFInternal::TakeHelper<T, COLL>;
584580
using Action_t = TDFInternal::TAction<Helper_t, Proxied>;
585-
df->Book(std::make_shared<Action_t>(Helper_t(valuesPtr, nSlots), bl, *fProxiedPtr));
586-
return MakeResultProxy(valuesPtr, df);
581+
auto valuesPtr = std::make_shared<COLL>();
582+
const auto nSlots = loopManager->GetNSlots();
583+
loopManager->Book(std::make_shared<Action_t>(Helper_t(valuesPtr, nSlots), validColumnNames, *fProxiedPtr));
584+
return MakeResultProxy(valuesPtr, loopManager);
587585
}
588586

589587
////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)