Skip to content

Commit

Permalink
[df] Fix Vary sanity check for typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
vepadulano committed Jan 22, 2025
1 parent 8ded485 commit 783252b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tree/dataframe/inc/ROOT/RDF/RInterfaceBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,33 @@ protected:
"does not return an RVec of RVecs.");

auto colTypes = GetColumnTypeNamesList(colNames);
auto allColTypesEqual =
std::all_of(colTypes.begin() + 1, colTypes.end(), [&](const std::string &t) { return t == colTypes[0]; });
if (!allColTypesEqual)
throw std::runtime_error("Cannot simultaneously vary multiple columns of different types.");
auto &&nColTypes = colTypes.size();
// Cache for column types when requested
std::vector<const std::type_info *> colTypeIDs(nColTypes);
for (decltype(nColTypes) i{1}; i < nColTypes; ++i) {
if (colTypes[i] != colTypes[0]) {
if (!colTypeIDs[0])
colTypeIDs[0] = &RDFInternal::TypeName2TypeID(colTypes[0]);
if (!colTypeIDs[i])
colTypeIDs[i] = &RDFInternal::TypeName2TypeID(colTypes[i]);
if (*colTypeIDs[i] != *colTypeIDs[0]) {
throw std::runtime_error("Cannot simultaneously vary multiple columns of different types.");
}
}
}

const auto &innerTypeID = typeid(RDFInternal::InnerValueType_t<RetType>);

for (auto i = 0u; i < colTypes.size(); ++i) {
for (decltype(nColTypes) i{}; i < nColTypes; ++i) {
const auto *define = fColRegister.GetDefine(colNames[i]);
const auto *expectedTypeID = define ? &define->GetTypeId() : &RDFInternal::TypeName2TypeID(colTypes[i]);
const std::type_info *expectedTypeID{nullptr};
if (define)
expectedTypeID = &define->GetTypeId();
if (!expectedTypeID) {
if (!colTypeIDs[i])
colTypeIDs[i] = &RDFInternal::TypeName2TypeID(colTypes[i]);
expectedTypeID = colTypeIDs[i];
}
if (innerTypeID != *expectedTypeID)
throw std::runtime_error("Varied values for column \"" + colNames[i] + "\" have a different type (" +
RDFInternal::TypeID2TypeName(innerTypeID) + ") than the nominal value (" +
Expand Down

0 comments on commit 783252b

Please sign in to comment.