11#ifndef ROOT_RLAZYDSIMPL
12#define ROOT_RLAZYDSIMPL
50template <
typename... ColumnTypes>
54 std::tuple<RResultPtr<std::vector<ColumnTypes>>...>
fColumns;
63 std::vector<std::pair<ULong64_t, ULong64_t>> fEntryRanges{};
72 template <std::size_t... S>
75 std::initializer_list<int> expander{
76 (*
static_cast<ColumnTypes *
>(fPointerHolders[S][slot]->GetPointer()) = (*std::get<S>(fColumns))[entry], 0)...};
80 template <std::size_t... S>
86 const std::vector<size_t> colLengths{std::get<S>(fColumns)->size()...};
87 const auto expectedLen = colLengths[0];
89 for (
auto i :
TSeqI(1, colLengths.size())) {
90 if (expectedLen != colLengths[i]) {
91 err +=
"Column \"" + fColNames[i] +
"\" and column \"" + fColNames[0] +
92 "\" have different lengths: " + std::to_string(expectedLen) +
" and " +
93 std::to_string(colLengths[i]);
97 throw std::runtime_error(err);
102 std::string
AsString() final {
return "lazy data source"; };
106 : fColumns(std::tuple<
RResultPtr<std::vector<ColumnTypes>>...>(colsNameVals.second...)),
107 fColNames({colsNameVals.first...}),
120 for (
auto &&ptrHolderv : fPointerHolders) {
121 for (
auto &&ptrHolder : ptrHolderv) {
127 const std::vector<std::string> &
GetColumnNames() const final {
return fColNames; }
131 auto entryRanges(std::move(fEntryRanges));
137 const auto key = std::string(colName);
138 return fColTypesMap.at(key);
143 const auto key = std::string(colName);
144 const auto endIt = fColTypesMap.end();
145 return endIt != fColTypesMap.find(key);
150 SetEntryHelper(slot, entry, std::index_sequence_for<ColumnTypes...>());
157 const auto nCols = fColNames.size();
158 fPointerHolders.resize(nCols);
160 for (
auto &&ptrHolderv : fPointerHolders) {
162 auto ptrHolder = fPointerHoldersModels[colIndex]->GetDeepCopy();
163 ptrHolderv.emplace_back(ptrHolder);
168 for (
auto &&ptrHolder : fPointerHoldersModels)
174 ColLengthChecker(std::index_sequence_for<ColumnTypes...>());
175 const auto nEntries = GetEntriesNumber();
176 const auto nEntriesInRange = nEntries / fNSlots;
177 auto reminder = 1U == fNSlots ? 0 : nEntries % fNSlots;
178 fEntryRanges.resize(fNSlots);
181 for (
auto &&range : fEntryRanges) {
182 end = init + nEntriesInRange;
195 std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
196 GetColumnReaders(
unsigned int slot, std::string_view colName,
const std::type_info &tid)
final
198 auto colTypeIt = fColTypesMap.find(std::string(colName));
199 if (colTypeIt == fColTypesMap.end()) {
200 throw std::runtime_error(
"The specified column name, \"" + std::string(colName) +
201 "\" is not known to the data source.");
205 if (colTypeIt->second != typeName) {
206 throw std::runtime_error(
"Column " + std::string(colName) +
" has type " + colTypeIt->second +
207 " while the id specified is associated to type " + typeName);
210 if (
auto colNameIt = std::find(fColNames.begin(), fColNames.end(), colName); colNameIt != fColNames.end()) {
211 const auto index = std::distance(fColNames.begin(), colNameIt);
212 return std::make_unique<ROOT::Internal::RDF::RLazyDSColumnReader>(fPointerHolders[
index][slot]);
215 throw std::runtime_error(
"Could not find column name \"" + std::string(colName) +
216 "\" in available column names.");
long long Long64_t
Portable signed long integer 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
void * GetImpl(Long64_t) final
RLazyDSColumnReader(ROOT::Internal::RDF::TPointerHolder *ptr)
ROOT::Internal::RDF::TPointerHolder * fPtr
Mother class of TTypedPointerHolder.
Class to wrap a pointer and delete the memory associated to it correctly.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
std::vector< void * > Record_t
A RDataSource implementation which is built on top of result proxies.
RLazyDS(RLazyDS &&)=delete
const std::vector< std::string > fColNames
std::vector< PointerHolderPtrs_t > fPointerHolders
RLazyDS(const RLazyDS &)=delete
std::vector< ROOT::Internal::RDF::TPointerHolder * > PointerHolderPtrs_t
void SetNSlots(unsigned int nSlots) final
Inform RDataSource of the number of processing slots (i.e.
std::string GetLabel() final
Return a string representation of the datasource type.
const std::vector< std::string > & GetColumnNames() const final
Returns a reference to the collection of the dataset's column names.
RLazyDS & operator=(RLazyDS &&)=delete
std::string GetTypeName(std::string_view colName) const final
Type of a column as a string, e.g.
void SetEntryHelper(unsigned int slot, ULong64_t entry, std::index_sequence< S... >)
const PointerHolderPtrs_t fPointerHoldersModels
const std::map< std::string, std::string > fColTypesMap
void ColLengthChecker(std::index_sequence< S... >)
bool HasColumn(std::string_view colName) const final
Checks if the dataset has a certain column.
std::string AsString() final
void Initialize() final
Convenience method called before starting an event-loop.
RLazyDS & operator=(const RLazyDS &)=delete
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges() final
Return ranges of entries to distribute to tasks.
Record_t GetColumnReadersImpl(std::string_view, const std::type_info &) final
type-erased vector of pointers to pointers to column values - one per slot
size_t GetEntriesNumber()
RLazyDS(std::pair< std::string, RResultPtr< std::vector< ColumnTypes > > >... colsNameVals)
bool SetEntry(unsigned int slot, ULong64_t entry) final
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
std::tuple< RResultPtr< std::vector< ColumnTypes > >... > fColumns
std::unique_ptr< ROOT::Detail::RDF::RColumnReaderBase > GetColumnReaders(unsigned int slot, std::string_view colName, const std::type_info &tid) final
If the other GetColumnReaders overload returns an empty vector, this overload will be called instead.
Smart pointer for the return type of actions.
A pseudo container class which is a generator of indices.
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...