Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RTrivialDS.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include <ROOT/RDF/Utils.hxx>
10#include <ROOT/TSeq.hxx>
11#include <ROOT/RTrivialDS.hxx>
12
13#include <limits>
14#include <memory>
15
16namespace ROOT {
17
18namespace RDF {
19
20std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &)
21{
22 return {};
23}
24
25RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
26{
27}
28
29RTrivialDS::RTrivialDS() : fSize(std::numeric_limits<ULong64_t>::max()), fSkipEvenEntries(false)
30{
31}
32
33const std::vector<std::string> &RTrivialDS::GetColumnNames() const
34{
35 return fColNames;
36}
37
38bool RTrivialDS::HasColumn(std::string_view colName) const
39{
40 return colName == fColNames[0];
41}
42
43std::string RTrivialDS::GetTypeName(std::string_view) const
44{
45 return "ULong64_t";
46}
47
48std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
49{
50 if (fSize == std::numeric_limits<ULong64_t>::max()) {
51 auto currentEntry = *std::max_element(fCounter.begin(), fCounter.end());
52 // infinite source, just make some ranges up
53 std::vector<std::pair<ULong64_t, ULong64_t>> ranges(fNSlots);
54 for (auto &range : ranges) {
55 range = std::make_pair(currentEntry, currentEntry + 10);
56 currentEntry += 10;
57 }
58 return ranges;
59 }
60
61 // empty fEntryRanges so we'll return an empty vector on subsequent calls
62 auto ranges = std::move(fEntryRanges);
63 return ranges;
64}
65
66bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
67{
68 if (fSkipEvenEntries && 0 == entry % 2) {
69 return false;
70 }
71 fCounter[slot] = entry;
72 return true;
73}
74
75void RTrivialDS::SetNSlots(unsigned int nSlots)
76{
77 assert(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
78
79 fNSlots = nSlots;
80 fCounter.resize(fNSlots);
81 fCounterAddr.resize(fNSlots);
82}
83
85{
86 if (fSize == std::numeric_limits<ULong64_t>::max()) {
87 // infinite source, nothing to do here
88 return;
89 }
90
91 // initialize fEntryRanges
92 const auto chunkSize = fSize / fNSlots;
93 auto start = 0UL;
94 auto end = 0UL;
95 for (auto i : ROOT::TSeqUL(fNSlots)) {
96 start = end;
97 end += chunkSize;
98 fEntryRanges.emplace_back(start, end);
99 (void)i;
100 }
101 // TODO: redistribute reminder to all slots
102 fEntryRanges.back().second += fSize % fNSlots;
103}
104
106{
107 return "TrivialDS";
108}
109
111{
112 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
114 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
115}
116
118{
119 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(), RDFInternal::ColumnNames_t{});
120 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
121}
122
123} // ns RDF
124
125} // ns ROOT
126
127std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase>
128ROOT::RDF::RTrivialDS::GetColumnReaders(unsigned int slot, std::string_view /*colName*/, const std::type_info &tid)
129{
130 // We know we have only one column and that it's holding ULong64_t's
131 if (tid != typeid(ULong64_t)) {
132 throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
133 }
134
135 fCounterAddr[slot] = &fCounter[slot];
136
137 return std::make_unique<ROOT::Internal::RDF::RTrivialDSColumnReader>(fCounterAddr[slot]);
138}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
start
Definition Rotated.cxx:223
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:84
The public interface to the RDataFrame federation of classes.
std::string GetTypeName(std::string_view) const final
Type of a column as a string, e.g.
bool HasColumn(std::string_view colName) const final
Checks if the dataset has a certain column.
void SetNSlots(unsigned int nSlots) final
Inform RDataSource of the number of processing slots (i.e.
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
std::string GetLabel() final
Return a string representation of the datasource type.
std::vector< ULong64_t * > fCounterAddr
std::vector< void * > GetColumnReadersImpl(std::string_view name, const std::type_info &) final
type-erased vector of pointers to pointers to column values - one per slot
std::vector< ULong64_t > fCounter
std::vector< std::string > fColNames
bool SetEntry(unsigned int slot, ULong64_t entry) final
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
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.
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges() final
Return ranges of entries to distribute to tasks.
RTrivialDS(ULong64_t size, bool skipEvenEntries=false)
const std::vector< std::string > & GetColumnNames() const final
Returns a reference to the collection of the dataset's column names.
void Initialize() final
Convenience method called before starting an event-loop.
RInterface< RDFDetail::RLoopManager > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Make a RDF wrapping a RTrivialDS with the specified amount of entries.
std::vector< std::string > ColumnNames_t
TSeq< unsigned long > TSeqUL
Definition TSeq.hxx:206