Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDFCustomLoaderHelpers.cxx
Go to the documentation of this file.
2#include <ROOT/RDF/Utils.hxx> // TypeID2TypeName
3
4#include <algorithm>
5#include <stdexcept>
6#include <typeinfo>
7
8namespace {
9
11
12template <typename T>
13void AppendAs(ROOT::RVecF &dest, void *value, std::size_t /*maxSize*/, float /*padding*/)
14{
15 dest.push_back(static_cast<float>(*static_cast<T *>(value)));
16}
17
18template <typename T>
19void AppendVectorAs(ROOT::RVecF &dest, void *value, std::size_t maxSize, float padding)
20{
21 const auto &vec = *static_cast<ROOT::RVec<T> *>(value);
22 const auto size = std::min(vec.size(), maxSize);
23 dest.insert(dest.end(), vec.begin(), vec.begin() + size);
24 dest.insert(dest.end(), maxSize - size, padding);
25}
26
27/// Pick the handler for a column of type T or RVec<T>, flagging vector columns
28template <typename T>
29bool MatchColHandler(const std::type_info &colType, CustomLoaderHelper::ColHandler_t &handler, bool &isVector)
30{
31 if (colType == typeid(T)) {
32 handler = &AppendAs<T>;
33 } else if (colType == typeid(ROOT::RVec<T>)) {
34 handler = &AppendVectorAs<T>;
35 isVector = true;
36 }
37 return handler != nullptr;
38}
39
40/// Pick the handler matching the type of a column among the supported types and their RVecs
41template <typename... Types>
42CustomLoaderHelper::ColHandler_t ResolveColHandler(const std::type_info &colType, bool &isVector)
43{
44 CustomLoaderHelper::ColHandler_t handler = nullptr;
45 if ((MatchColHandler<Types>(colType, handler, isVector) || ...))
46 return handler;
47
48 throw std::invalid_argument("CustomLoaderHelper: column type '" + ROOT::Internal::RDF::TypeID2TypeName(colType) +
49 "' cannot be converted to float.");
50}
51
52} // namespace
53
54ROOT::Internal::RDF::CustomLoaderHelper::CustomLoaderHelper(const std::shared_ptr<ROOT::RVecF> &location,
55 const std::vector<const std::type_info *> &colTypeIDs,
56 const std::vector<std::size_t> &vecSizes, float vecPadding)
57 : fLocation(location), fVecPadding(vecPadding)
58{
59 fColHandlers.reserve(colTypeIDs.size());
60 fMaxSizes.reserve(colTypeIDs.size());
61 std::size_t vecIdx = 0;
62 for (const auto *colType : colTypeIDs) {
63 bool isVector = false;
64 fColHandlers.push_back(
65 ResolveColHandler<float, double, bool, char, signed char, unsigned char, short, unsigned short, int,
66 unsigned int, long, unsigned long, long long, unsigned long long>(*colType, isVector));
67 // Vector columns take the next maximum size, in column order
68 fMaxSizes.push_back(isVector ? vecSizes[vecIdx++] : 1);
69 }
70}
71
72void ROOT::Internal::RDF::CustomLoaderHelper::Exec(unsigned int /*slot*/, const std::vector<void *> &values)
73{
74 // The readers deliver the values in column order, the same order the handlers were resolved in
75 auto nValues{values.size()};
76 for (decltype(nValues) i{}; i < nValues; i++)
77 fColHandlers[i](*fLocation, values[i], fMaxSizes[i], fVecPadding);
78}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
CustomLoaderHelper(const std::shared_ptr< ROOT::RVecF > &location, const std::vector< const std::type_info * > &colTypeIDs, const std::vector< std::size_t > &vecSizes, float vecPadding)
void Exec(unsigned int slot, const std::vector< void * > &values)
std::vector< ColHandler_t > fColHandlers
One handler per input column, resolved once from the column types.
std::vector< std::size_t > fMaxSizes
Maximum size of each input column, resolved once from the vector sizes, only used for vector columns.
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:200